[Argil-svn] SF.net SVN: argil: [520] branches/experimental/src/Argil
Status: Alpha
Brought to you by:
tswicegood
|
From: <tsw...@us...> - 2007-05-13 05:53:10
|
Revision: 520
http://argil.svn.sourceforge.net/argil/?rev=520&view=rev
Author: tswicegood
Date: 2007-05-12 22:53:10 -0700 (Sat, 12 May 2007)
Log Message:
-----------
Move src/ code over to PEAR formatting standards. Done via php_beautifier.
Modified Paths:
--------------
branches/experimental/src/Argil/Model/Container.php
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/src/Argil/Reflection/Property.php
branches/experimental/src/Argil/Reflection/PropertyList.php
branches/experimental/src/Argil/Route.php
branches/experimental/src/Argil/Specification/Length.php
Modified: branches/experimental/src/Argil/Model/Container.php
===================================================================
--- branches/experimental/src/Argil/Model/Container.php 2007-05-13 05:52:03 UTC (rev 519)
+++ branches/experimental/src/Argil/Model/Container.php 2007-05-13 05:53:10 UTC (rev 520)
@@ -1,51 +1,47 @@
<?php
-
require_once 'Argil/Reflection/Object.php';
-
class Argil_Model_Container
{
- private $_contained = array();
- private $_reflections = array();
-
- public function __construct() {
- if (func_num_args() > 0) {
- foreach (func_get_args() as $object) {
- $this->_contained[get_class($object)] = $object;
- $this->_reflections[get_class($object)] = new Argil_Reflection_Object($object);
- }
- }
- }
-
- public function is($name) {
- return isset($this->_contained[$name]);
- }
-
- public function __set($key, $value) {
- foreach ($this->_contained as $objectName => $object) {
- $vars = get_object_vars($object);
- if (!isset($vars[$key])) {
- continue;
- }
-
- $property = $this->_reflections[$objectName]->getProperty($key);
- $oldValue = $object->$key;
- $object->$key = $value;
- if (!$property->isValid($object)) {
- $object->$key = $oldValue;
- throw new Exception();
- }
- return;
- }
-
- throw new Exception();
- }
-
- public function __get($key) {
- foreach ($this->_contained as $object) {
- $vars = get_object_vars($object);
- if (isset($vars[$key])) {
- return $object->$key;
- }
- }
- }
+ private $_contained = array();
+ private $_reflections = array();
+ public function __construct()
+ {
+ if (func_num_args() > 0) {
+ foreach(func_get_args() as $object) {
+ $this->_contained[get_class($object) ] = $object;
+ $this->_reflections[get_class($object) ] = new Argil_Reflection_Object($object);
+ }
+ }
+ }
+ public function is($name)
+ {
+ return isset($this->_contained[$name]);
+ }
+ public function __set($key, $value)
+ {
+ foreach($this->_contained as $objectName => $object) {
+ $vars = get_object_vars($object);
+ if (!isset($vars[$key])) {
+ continue;
+ }
+ $property = $this->_reflections[$objectName]->getProperty($key);
+ $oldValue = $object->$key;
+ $object->$key = $value;
+ if (!$property->isValid($object)) {
+ $object->$key = $oldValue;
+ throw new Exception();
+ }
+ return;
+ }
+ throw new Exception();
+ }
+ public function __get($key)
+ {
+ foreach($this->_contained as $object) {
+ $vars = get_object_vars($object);
+ if (isset($vars[$key])) {
+ return $object->$key;
+ }
+ }
+ }
}
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-05-13 05:52:03 UTC (rev 519)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-05-13 05:53:10 UTC (rev 520)
@@ -1,33 +1,27 @@
<?php
-
require_once 'Argil/Reflection/Property.php';
require_once 'Argil/Reflection/PropertyList.php';
-
class Argil_Reflection_Object
{
- private $_decorated = null;
-
- public function __construct($object) {
- assert('is_object($object)');
- $this->_decorated = new ReflectionObject($object);
- }
-
- public function __call($method, $arguments) {
- return call_user_func_array(
- array($this->_decorated, $method),
- $arguments
- );
- }
-
- public function getProperties() {
- return new Argil_Reflection_PropertyList(
- $this->_decorated->getProperties()
- );
- }
-
- public function getProperty($name) {
- return new Argil_Reflection_Property(
- $this->_decorated->getProperty($name)
- );
- }
-}
\ No newline at end of file
+ private $_decorated = null;
+ public function __construct($object)
+ {
+ assert('is_object($object)');
+ $this->_decorated = new ReflectionObject($object);
+ }
+ public function __call($method, $arguments)
+ {
+ return call_user_func_array(array(
+ $this->_decorated,
+ $method
+ ) , $arguments);
+ }
+ public function getProperties()
+ {
+ return new Argil_Reflection_PropertyList($this->_decorated->getProperties());
+ }
+ public function getProperty($name)
+ {
+ return new Argil_Reflection_Property($this->_decorated->getProperty($name));
+ }
+}
Modified: branches/experimental/src/Argil/Reflection/Property.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Property.php 2007-05-13 05:52:03 UTC (rev 519)
+++ branches/experimental/src/Argil/Reflection/Property.php 2007-05-13 05:53:10 UTC (rev 520)
@@ -1,50 +1,47 @@
<?php
-
require_once 'Argil/Specification/Length.php';
-
-class Argil_Reflection_Property
+class Argil_Reflection_Property
{
- private $_decorated = null;
-
- public function __construct(ReflectionProperty $property) {
- $this->_decorated = $property;
- }
-
- public function __call($method, $arguments) {
- return call_user_func_array(
- array($this->_decorated, $method),
- $arguments
- );
- }
-
- public function isValid($object) {
- $doc = $this->getDocComment();
- $name = $this->getName();
- $value = $object->$name;
- if (preg_match_all('/@(is|isNot) ([a-z]+) (.*)/', $doc, $matches)) {
- foreach ($matches[2] as $key => $spec) {
- $spec = ucfirst($spec);
- $reflection = new ReflectionClass('Argil_Specification_' . $spec);
- $args = array_merge(
- array($value),
- explode(' ', $matches[3][$key])
- );
- $specObj = $reflection->newInstanceArgs($args);
- switch ($matches[1][$key]) {
- case 'is' :
- if (!$specObj->valid()) {
- return false;
- }
- break;
- case 'isNot' :
- if ($specObj->valid()) {
- return false;
- }
- break;
- }
- }
- }
-
- return true;
- }
+ private $_decorated = null;
+ public function __construct(ReflectionProperty $property)
+ {
+ $this->_decorated = $property;
+ }
+ public function __call($method, $arguments)
+ {
+ return call_user_func_array(array(
+ $this->_decorated,
+ $method
+ ) , $arguments);
+ }
+ public function isValid($object)
+ {
+ $doc = $this->getDocComment();
+ $name = $this->getName();
+ $value = $object->$name;
+ if (preg_match_all('/@(is|isNot) ([a-z]+) (.*)/', $doc, $matches)) {
+ foreach($matches[2] as $key => $spec) {
+ $spec = ucfirst($spec);
+ $reflection = new ReflectionClass('Argil_Specification_' . $spec);
+ $args = array_merge(array(
+ $value
+ ) , explode(' ', $matches[3][$key]));
+ $specObj = $reflection->newInstanceArgs($args);
+ switch ($matches[1][$key]) {
+ case 'is':
+ if (!$specObj->valid()) {
+ return false;
+ }
+ break;
+
+ case 'isNot':
+ if ($specObj->valid()) {
+ return false;
+ }
+ break;
+ }
+ }
+ }
+ return true;
+ }
}
Modified: branches/experimental/src/Argil/Reflection/PropertyList.php
===================================================================
--- branches/experimental/src/Argil/Reflection/PropertyList.php 2007-05-13 05:52:03 UTC (rev 519)
+++ branches/experimental/src/Argil/Reflection/PropertyList.php 2007-05-13 05:53:10 UTC (rev 520)
@@ -1,40 +1,48 @@
<?php
-
require_once 'Argil/Reflection/Property.php';
-
-class Argil_Reflection_PropertyList
- implements ArrayAccess, Countable, SeekableIterator
+class Argil_Reflection_PropertyList implements ArrayAccess, Countable, SeekableIterator
{
- private $_data = array();
-
- public function __construct(array $propertyList) {
- $this->_data = $propertyList;
- }
-
- public function offsetExists($offset) {
- return isset($this->_data[$offset]);
- }
-
- public function offsetGet($offset) {
- return new Argil_Reflection_Property($this->_data[$offset]);
- }
-
- public function offsetSet($offset, $value) {
- throw new Exception();
- }
-
- public function offsetUnset($offset) {
- throw new Exception();
- }
-
- public function count() {
- return count($this->_data);
- }
-
- public function seek($index) { }
- public function current() { }
- public function key() { }
- public function next() { }
- public function rewind() { }
- public function valid() { }
-}
\ No newline at end of file
+ private $_data = array();
+ public function __construct(array$propertyList)
+ {
+ $this->_data = $propertyList;
+ }
+ public function offsetExists($offset)
+ {
+ return isset($this->_data[$offset]);
+ }
+ public function offsetGet($offset)
+ {
+ return new Argil_Reflection_Property($this->_data[$offset]);
+ }
+ public function offsetSet($offset, $value)
+ {
+ throw new Exception();
+ }
+ public function offsetUnset($offset)
+ {
+ throw new Exception();
+ }
+ public function count()
+ {
+ return count($this->_data);
+ }
+ public function seek($index)
+ {
+ }
+ public function current()
+ {
+ }
+ public function key()
+ {
+ }
+ public function next()
+ {
+ }
+ public function rewind()
+ {
+ }
+ public function valid()
+ {
+ }
+}
Modified: branches/experimental/src/Argil/Route.php
===================================================================
--- branches/experimental/src/Argil/Route.php 2007-05-13 05:52:03 UTC (rev 519)
+++ branches/experimental/src/Argil/Route.php 2007-05-13 05:53:10 UTC (rev 520)
@@ -1,14 +1,13 @@
<?php
-
class Argil_Route
{
- private $_callback = null;
-
- public function __construct($callback) {
- $this->_callback = $callback;
- }
-
- public function execute() {
- call_user_func($this->_callback);
- }
+ private $_callback = null;
+ public function __construct($callback)
+ {
+ $this->_callback = $callback;
+ }
+ public function execute()
+ {
+ call_user_func($this->_callback);
+ }
}
Modified: branches/experimental/src/Argil/Specification/Length.php
===================================================================
--- branches/experimental/src/Argil/Specification/Length.php 2007-05-13 05:52:03 UTC (rev 519)
+++ branches/experimental/src/Argil/Specification/Length.php 2007-05-13 05:53:10 UTC (rev 520)
@@ -1,36 +1,31 @@
<?php
-
class Argil_Specification_Length
{
- private
- $_comparison,
- $_length,
- $_value;
-
- public function __construct($value, $length, $comparison = '==') {
- $this->_value = $value;
- $this->_length = $length;
- $this->_comparison = $comparison;
- }
-
- public function valid() {
- $actualLength = strlen($this->_value);
- switch ($this->_comparison) {
- case '==' :
- return $actualLength == $this->_length;
- case '<=' :
- return $actualLength <= $this->_length;
- case '>=' :
- return $actualLength >= $this->_length;
- case '>' :
- return $actualLength > $this->_length;
- case '<' :
- return $actualLength < $this->_length;
- case '<>' :
- case '!=' :
- return $actualLength != $this->_length;
- }
-
- throw new Exception();
- }
-}
\ No newline at end of file
+ private $_comparison, $_length, $_value;
+ public function __construct($value, $length, $comparison = '==')
+ {
+ $this->_value = $value;
+ $this->_length = $length;
+ $this->_comparison = $comparison;
+ }
+ public function valid()
+ {
+ $actualLength = strlen($this->_value);
+ switch ($this->_comparison) {
+ case '==':
+ return $actualLength == $this->_length;
+ case '<=':
+ return $actualLength <= $this->_length;
+ case '>=':
+ return $actualLength >= $this->_length;
+ case '>':
+ return $actualLength > $this->_length;
+ case '<':
+ return $actualLength < $this->_length;
+ case '<>':
+ case '!=':
+ return $actualLength != $this->_length;
+ }
+ throw new Exception();
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|