[Argil-svn] SF.net SVN: argil: [514] branches/experimental
Status: Alpha
Brought to you by:
tswicegood
|
From: <tsw...@us...> - 2007-04-01 04:51:44
|
Revision: 514
http://argil.svn.sourceforge.net/argil/?rev=514&view=rev
Author: tswicegood
Date: 2007-03-31 21:51:45 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
Start using specification.
This still needs some work. A Specification Locator needs to be implemented so
multiple specs can be used and allow a flex point for scanning multiple places for
Specs, but this starts the code in the right direction.
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Property.php
branches/experimental/tests/Argil/Reflection/PropertyTest.php
Modified: branches/experimental/src/Argil/Reflection/Property.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Property.php 2007-04-01 04:38:34 UTC (rev 513)
+++ branches/experimental/src/Argil/Reflection/Property.php 2007-04-01 04:51:45 UTC (rev 514)
@@ -1,5 +1,7 @@
<?php
+require_once 'Argil/Specification/Length.php';
+
class Argil_Reflection_Property
{
private $_decorated = null;
@@ -16,8 +18,24 @@
}
public function isValid($object) {
+ $doc = $this->getDocComment();
$name = $this->getName();
- $len = strlen($object->$name);
- return $len <= 10 && $len >= 5;
+ $value = $object->$name;
+ if (preg_match_all('/@is ([a-z]+) (.*)/', $doc, $matches)) {
+ foreach ($matches[1] as $key => $spec) {
+ $spec = ucfirst($spec);
+ $reflection = new ReflectionClass('Argil_Specification_' . $spec);
+ $args = array_merge(
+ array($value),
+ explode(' ', $matches[2][$key])
+ );
+ $specObj = $reflection->newInstanceArgs($args);
+ if (!$specObj->valid()) {
+ return false;
+ }
+ }
+ }
+
+ return true;
}
}
Modified: branches/experimental/tests/Argil/Reflection/PropertyTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-04-01 04:38:34 UTC (rev 513)
+++ branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-04-01 04:51:45 UTC (rev 514)
@@ -5,8 +5,8 @@
class ArgilSamplePropertyObjectForReflection {
/**
- * @is length <= 10
- * @is length >= 5
+ * @is length 10 <=
+ * @is length 5 >=
*/
public $publicProperty;
protected $protectedProperty;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|