[Argil-svn] SF.net SVN: argil: [531] branches/experimental
Status: Alpha
Brought to you by:
tswicegood
|
From: <tsw...@us...> - 2007-05-25 23:07:47
|
Revision: 531
http://argil.svn.sourceforge.net/argil/?rev=531&view=rev
Author: tswicegood
Date: 2007-05-25 16:07:49 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add getTable() to the reflection object
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/Argil/Reflection/ObjectTest.php
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-05-25 23:00:37 UTC (rev 530)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-05-25 23:07:49 UTC (rev 531)
@@ -1,6 +1,8 @@
<?php
require_once 'Argil/Reflection/Property.php';
require_once 'Argil/Reflection/PropertyList.php';
+require_once 'Argil/Util/Annotation/Parser.php';
+
class Argil_Reflection_Object
{
private $_decorated = null;
@@ -24,4 +26,16 @@
{
return new Argil_Reflection_Property($this->_decorated->getProperty($name));
}
+
+ public function getTable()
+ {
+ $parser = new Argil_Util_Annotation_Parser();
+ $collection = $parser->parse($this->_decorated->getDocComment());
+
+ if (!$collection->has('table')) {
+ return '';
+ }
+
+ return array_shift($collection->filter('table')->current()->params);
+ }
}
Modified: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-25 23:00:37 UTC (rev 530)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-25 23:07:49 UTC (rev 531)
@@ -7,6 +7,12 @@
protected $protectedProperty = '';
private $privateProperty = '';
}
+
+/**
+ * @table a_custom_table
+ */
+class ArgilSampleReflectionObjectWithTable { }
+
class Argil_Reflection_ObjectTest extends UnitTestCase
{
public function testReturnsArrayOfProperties()
@@ -23,4 +29,19 @@
$property = $reflection->getProperty('publicProperty');
$this->assertIsA($property, 'Argil_Reflection_Property');
}
+
+ public function testReturnsTableNameIfTableAnnotationSet()
+ {
+ $reflection = new Argil_Reflection_Object(
+ new ArgilSampleReflectionObjectWithTable()
+ );
+
+ $this->assertEqual('a_custom_table', $reflection->getTable());
+ }
+
+ public function testReturnsEmptyStringIfTableAnnotationIsNotSet()
+ {
+ $reflection = new Argil_Reflection_Object($this);
+ $this->assertEqual('', $reflection->getTable());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|