From 380d4cf489bcbcbd77668838b26ec66a2478013b Mon Sep 17 00:00:00 2001 From: Jonathan Moss Date: Tue, 19 Apr 2011 14:49:03 +1000 Subject: [PATCH] converted the whole project to namespaced PHP --- build.xml | 4 +- integration-tests/TestComposeMany.php | 8 +- integration-tests/TestComposeOne.php | 8 +- integration-tests/TestFileProperty.php | 12 +-- integration-tests/TestHasMany.php | 8 +- integration-tests/TestHasOne.php | 8 +- integration-tests/TestQuery.php | 22 ++--- integration-tests/TestSingleObject.php | 8 +- .../{MongoUnit => mongoUnit}/JsonLoader.php | 16 ++-- .../{MongoUnit => mongoUnit}/TestCase.php | 34 +++---- .../constraint}/CollectionDoesNotExist.php | 9 +- .../constraint}/CollectionExists.php | 11 ++- .../constraint}/DocumentExists.php | 10 +- .../constraint}/DocumentPropertyEquals.php | 11 ++- integration-tests/test-objects/Child.php | 8 +- .../test-objects/ComposeManyParent.php | 6 +- .../test-objects/ComposeOneParent.php | 6 +- .../test-objects/HasManyParent.php | 6 +- .../test-objects/HasOneParent.php | 6 +- integration-tests/test-objects/User.php | 6 +- src/bootstrap.php | 52 +++++----- src/{Morph => morph}/Collection.php | 32 +++---- src/{Morph => morph}/Enum.php | 8 +- src/{Morph => morph}/ICompare.php | 6 +- src/{Morph => morph}/IQuery.php | 4 +- src/{Morph => morph}/Iterator.php | 14 +-- src/{Morph => morph}/Object.php | 94 +++++++++--------- src/{Morph => morph}/PropertySet.php | 18 ++-- src/{Morph => morph}/Query.php | 6 +- src/{Morph => morph}/Storage.php | 96 +++++++++---------- src/{Morph => morph}/Utils.php | 16 ++-- .../compare}/NumericProperty.php | 8 +- .../Compare => morph/compare}/Property.php | 6 +- .../exception}/ObjectNotFound.php | 4 +- .../Property => morph/property}/Boolean.php | 19 +--- .../property}/ComposeMany.php | 34 +++---- .../property}/ComposeOne.php | 26 ++--- .../Property => morph/property}/Date.php | 36 +++---- .../Property => morph/property}/Enum.php | 20 ++-- .../Property => morph/property}/File.php | 44 ++++----- .../Property => morph/property}/Float.php | 22 ++--- .../Property => morph/property}/Generic.php | 18 ++-- .../Property => morph/property}/HasMany.php | 54 +++++------ .../Property => morph/property}/HasOne.php | 52 +++++----- .../Property => morph/property}/Integer.php | 22 ++--- .../Property => morph/property}/String.php | 16 ++-- src/{Morph/Query => morph/query}/Property.php | 26 ++--- unit-tests/ForTesting.php | 9 +- unit-tests/TestObject.php | 54 +++++------ unit-tests/TestPropertySet.php | 40 ++++---- unit-tests/TestQuery.php | 33 ++++--- unit-tests/TestUtils.php | 32 +++---- unit-tests/UnitTests.php | 16 ++-- unit-tests/namespaced_stub.php | 2 +- .../{Property => property}/TestProperties.php | 37 +++---- unit-tests/{Query => query}/TestProperty.php | 44 ++++----- 56 files changed, 598 insertions(+), 629 deletions(-) rename integration-tests/{MongoUnit => mongoUnit}/JsonLoader.php (67%) rename integration-tests/{MongoUnit => mongoUnit}/TestCase.php (79%) rename integration-tests/{MongoUnit/Constraint => mongoUnit/constraint}/CollectionDoesNotExist.php (89%) rename integration-tests/{MongoUnit/Constraint => mongoUnit/constraint}/CollectionExists.php (87%) rename integration-tests/{MongoUnit/Constraint => mongoUnit/constraint}/DocumentExists.php (89%) rename integration-tests/{MongoUnit/Constraint => mongoUnit/constraint}/DocumentPropertyEquals.php (89%) rename src/{Morph => morph}/Collection.php (84%) rename src/{Morph => morph}/Enum.php (81%) rename src/{Morph => morph}/ICompare.php (84%) rename src/{Morph => morph}/IQuery.php (93%) rename src/{Morph => morph}/Iterator.php (88%) rename src/{Morph => morph}/Object.php (71%) rename src/{Morph => morph}/PropertySet.php (79%) rename src/{Morph => morph}/Query.php (97%) rename src/{Morph => morph}/Storage.php (63%) rename src/{Morph => morph}/Utils.php (58%) rename src/{Morph/Compare => morph/compare}/NumericProperty.php (84%) rename src/{Morph/Compare => morph/compare}/Property.php (87%) rename src/{Morph/Exception => morph/exception}/ObjectNotFound.php (77%) rename src/{Morph/Property => morph/property}/Boolean.php (74%) rename src/{Morph/Property => morph/property}/ComposeMany.php (73%) rename src/{Morph/Property => morph/property}/ComposeOne.php (75%) rename src/{Morph/Property => morph/property}/Date.php (61%) rename src/{Morph/Property => morph/property}/Enum.php (74%) rename src/{Morph/Property => morph/property}/File.php (63%) rename src/{Morph/Property => morph/property}/Float.php (68%) rename src/{Morph/Property => morph/property}/Generic.php (88%) rename src/{Morph/Property => morph/property}/HasMany.php (62%) rename src/{Morph/Property => morph/property}/HasOne.php (61%) rename src/{Morph/Property => morph/property}/Integer.php (68%) rename src/{Morph/Property => morph/property}/String.php (69%) rename src/{Morph/Query => morph/query}/Property.php (90%) rename unit-tests/{Property => property}/TestProperties.php (67%) rename unit-tests/{Query => query}/TestProperty.php (65%) diff --git a/build.xml b/build.xml index 1e1b37f..681dc99 100644 --- a/build.xml +++ b/build.xml @@ -7,11 +7,11 @@ - + - + diff --git a/integration-tests/TestComposeMany.php b/integration-tests/TestComposeMany.php index 1a0c053..f5b931b 100644 --- a/integration-tests/TestComposeMany.php +++ b/integration-tests/TestComposeMany.php @@ -6,26 +6,26 @@ */ require_once dirname(__FILE__).'/../Morph.phar'; -require_once dirname(__FILE__).'/MongoUnit/TestCase.php'; +require_once dirname(__FILE__).'/mongoUnit/TestCase.php'; require_once dirname(__FILE__).'/test-objects/ComposeManyParent.php'; require_once dirname(__FILE__).'/test-objects/Child.php'; /** * @package Morph */ -class TestComposeMany extends MongoUnit_TestCase +class TestComposeMany extends \mongoUnit\TestCase { public function setup() { parent::setUp(); - Morph_Storage::init($this->getDatabase()); + \morph\Storage::init($this->getDatabase()); } public function tearDown() { parent::tearDown(); - Morph_Storage::deInit(); + \morph\Storage::deInit(); } public function testStoresParentAndChild() diff --git a/integration-tests/TestComposeOne.php b/integration-tests/TestComposeOne.php index 3228c35..a76be14 100644 --- a/integration-tests/TestComposeOne.php +++ b/integration-tests/TestComposeOne.php @@ -6,26 +6,26 @@ */ require_once dirname(__FILE__).'/../Morph.phar'; -require_once dirname(__FILE__).'/MongoUnit/TestCase.php'; +require_once dirname(__FILE__).'/mongoUnit/TestCase.php'; require_once dirname(__FILE__).'/test-objects/ComposeOneParent.php'; require_once dirname(__FILE__).'/test-objects/Child.php'; /** * @package Morph */ -class TestComposeOne extends MongoUnit_TestCase +class TestComposeOne extends \mongoUnit\TestCase { public function setup() { parent::setup(); - Morph_Storage::init($this->getDatabase()); + \morph\Storage::init($this->getDatabase()); } public function tearDown() { parent::tearDown(); - Morph_Storage::deInit(); + \morph\Storage::deInit(); } public function testStoresParentAndChild() diff --git a/integration-tests/TestFileProperty.php b/integration-tests/TestFileProperty.php index b81254d..30667a3 100644 --- a/integration-tests/TestFileProperty.php +++ b/integration-tests/TestFileProperty.php @@ -6,25 +6,25 @@ */ require_once dirname(__FILE__).'/../Morph.phar'; -require_once dirname(__FILE__).'/MongoUnit/TestCase.php'; +require_once dirname(__FILE__).'/mongoUnit/TestCase.php'; require_once dirname(__FILE__).'/test-objects/User.php'; /** * @package Morph */ -class TestFileProperty extends MongoUnit_TestCase +class TestFileProperty extends \mongoUnit\TestCase { public function setup() { parent::setup(); - Morph_Storage::init($this->getDatabase()); + \morph\Storage::init($this->getDatabase()); } public function tearDown() { parent::tearDown(); - Morph_Storage::deInit(); + \morph\Storage::deInit(); unlink('test.png'); } @@ -38,8 +38,8 @@ public function testStoresUserAndFile() $this->assertDocumentExists('User', $user->id()); $user->Avatar->write("test.png"); $this->assertFileExists('test.png'); - $originalFileHash = md5_file(dirname(__FILE__).'/fixtures/flask.png'); - $retrievedFileHash = md5_file('test.png'); + $originalFileHash = \md5_file(dirname(__FILE__).'/fixtures/flask.png'); + $retrievedFileHash = \md5_file('test.png'); $this->assertEquals($originalFileHash, $retrievedFileHash); } diff --git a/integration-tests/TestHasMany.php b/integration-tests/TestHasMany.php index 6647ed5..7941eeb 100644 --- a/integration-tests/TestHasMany.php +++ b/integration-tests/TestHasMany.php @@ -6,26 +6,26 @@ */ require_once dirname(__FILE__).'/../Morph.phar'; -require_once dirname(__FILE__).'/MongoUnit/TestCase.php'; +require_once dirname(__FILE__).'/mongoUnit/TestCase.php'; require_once dirname(__FILE__).'/test-objects/HasManyParent.php'; require_once dirname(__FILE__).'/test-objects/Child.php'; /** * @package Morph */ -class TestHasMany extends MongoUnit_TestCase +class TestHasMany extends \mongoUnit\TestCase { public function setup() { parent::setup(); - Morph_Storage::init($this->getDatabase()); + \morph\Storage::init($this->getDatabase()); } public function tearDown() { parent::tearDown(); - Morph_Storage::deInit(); + \morph\Storage::deInit(); } public function testStoresParentAndChildren() diff --git a/integration-tests/TestHasOne.php b/integration-tests/TestHasOne.php index 67f3c64..77fb3c2 100644 --- a/integration-tests/TestHasOne.php +++ b/integration-tests/TestHasOne.php @@ -6,26 +6,26 @@ */ require_once dirname(__FILE__).'/../Morph.phar'; -require_once dirname(__FILE__).'/MongoUnit/TestCase.php'; +require_once dirname(__FILE__).'/mongoUnit/TestCase.php'; require_once dirname(__FILE__).'/test-objects/HasOneParent.php'; require_once dirname(__FILE__).'/test-objects/Child.php'; /** * @package Morph */ -class TestHasOne extends MongoUnit_TestCase +class TestHasOne extends \mongoUnit\TestCase { public function setup() { parent::setup(); - Morph_Storage::init($this->getDatabase()); + \morph\Storage::init($this->getDatabase()); } public function tearDown() { parent::tearDown(); - Morph_Storage::deInit(); + \morph\Storage::deInit(); } public function testStoresParentAndChild() diff --git a/integration-tests/TestQuery.php b/integration-tests/TestQuery.php index 5e8401a..be33d11 100644 --- a/integration-tests/TestQuery.php +++ b/integration-tests/TestQuery.php @@ -6,19 +6,19 @@ */ require_once dirname(__FILE__).'/../Morph.phar'; -require_once dirname(__FILE__).'/MongoUnit/TestCase.php'; +require_once dirname(__FILE__).'/mongoUnit/TestCase.php'; require_once dirname(__FILE__).'/test-objects/Child.php'; /** * @package Morph */ -class TestQuery extends MongoUnit_TestCase +class TestQuery extends \mongoUnit\TestCase { public function setup() { parent::setup(); - Morph_Storage::init($this->getDatabase()); + \morph\Storage::init($this->getDatabase()); //load data from file to query against $this->loadJsonFileDatasetIntoCollection('Child', dirname(__FILE__). '/fixtures/children.json'); } @@ -26,13 +26,13 @@ public function setup() public function tearDown() { parent::tearDown(); - Morph_Storage::deInit(); + \morph\Storage::deInit(); } public function testCanFindByValue() { $child = new Child(); - $query = new Morph_Query(); + $query = new \morph\Query(); $query->property('Name')->equals('a_musing_moose'); $results = $child->findByQuery($query); $this->assertEquals(1, $results->totalCount()); @@ -41,7 +41,7 @@ public function testCanFindByValue() public function testCanFindByRegex() { $child = new Child(); - $query = new Morph_Query(); + $query = new \morph\Query(); $query->property('Name')->regex('/.*moose.*/i'); $results = $child->findByQuery($query); $this->assertEquals(4, $results->totalCount()); @@ -50,7 +50,7 @@ public function testCanFindByRegex() public function testCanFindByLike() { $child = new Child(); - $query = new Morph_Query(); + $query = new \morph\Query(); $query->property('Name')->like('moose'); $results = $child->findByQuery($query); $this->assertEquals(4, $results->totalCount()); @@ -59,7 +59,7 @@ public function testCanFindByLike() public function testCanFindByGreaterThan() { $child = new Child(); - $query = new Morph_Query(); + $query = new \morph\Query(); $query->property('Age')->greaterThan(22); $results = $child->findByQuery($query); $this->assertEquals(2, $results->totalCount()); @@ -68,7 +68,7 @@ public function testCanFindByGreaterThan() public function testCanFindByLessThan() { $child = new Child(); - $query = new Morph_Query(); + $query = new \morph\Query(); $query->property('Age')->lessThan(22); $results = $child->findByQuery($query); $this->assertEquals(2, $results->totalCount()); @@ -77,7 +77,7 @@ public function testCanFindByLessThan() public function testCanFindBetween() { $child = new Child(); - $query = new Morph_Query(); + $query = new \morph\Query(); $query->property('Age')->greaterThan(22)->lessThan(40); $results = $child->findByQuery($query); $this->assertEquals(1, $results->totalCount()); @@ -86,7 +86,7 @@ public function testCanFindBetween() public function testCanFindByNotValue() { $child = new Child(); - $query = new Morph_Query(); + $query = new \morph\Query(); $query->property('Name')->notEqualTo('a_musing_moose'); $results = $child->findByQuery($query); $this->assertEquals(3, $results->totalCount()); diff --git a/integration-tests/TestSingleObject.php b/integration-tests/TestSingleObject.php index a061bba..b2c249f 100644 --- a/integration-tests/TestSingleObject.php +++ b/integration-tests/TestSingleObject.php @@ -6,25 +6,25 @@ */ require_once dirname(__FILE__).'/../Morph.phar'; -require_once dirname(__FILE__).'/MongoUnit/TestCase.php'; +require_once dirname(__FILE__).'/mongoUnit/TestCase.php'; require_once dirname(__FILE__).'/test-objects/Child.php'; /** * @package Morph */ -class TestSingleObject extends MongoUnit_TestCase +class TestSingleObject extends \mongoUnit\TestCase { public function setup() { parent::setup(); - Morph_Storage::init($this->getDatabase()); + \morph\Storage::init($this->getDatabase()); } public function tearDown() { parent::tearDown(); - Morph_Storage::deInit(); + \morph\Storage::deInit(); } public function testStoresObject() diff --git a/integration-tests/MongoUnit/JsonLoader.php b/integration-tests/mongoUnit/JsonLoader.php similarity index 67% rename from integration-tests/MongoUnit/JsonLoader.php rename to integration-tests/mongoUnit/JsonLoader.php index e0278a7..38671cb 100644 --- a/integration-tests/MongoUnit/JsonLoader.php +++ b/integration-tests/mongoUnit/JsonLoader.php @@ -5,43 +5,43 @@ * @copyright 2010 Tangent Labs * @version SVN: $Id$ */ - +namespace mongoUnit; /** * Loads data into a collection * * @package MongoUnit */ -class MongoUnit_JsonLoader +class JsonLoader { private $collection; - public function __construct(MongoCollection $collection) + public function __construct(\MongoCollection $collection) { $this->collection = $collection; } public function loadFromJsonFile($filePath) { - if (!file_exists($filePath)) { + if (!\file_exists($filePath)) { throw new InvalidArgumentException("Could not locate $filePath"); } - $json = file_get_contents($filePath); + $json = \file_get_contents($filePath); return $this->loadJsonFromString($json); } public function loadJsonFromString($json) { if (!$this->isValidJson($json)) { - throw new InvalidArgumentException("Invalid Json"); + throw new \InvalidArgumentException("Invalid Json"); } - $data = json_decode($json, true); + $data = \json_decode($json, true); $this->collection->drop(); return $this->collection->batchInsert($data); } private function isValidJson($json) { - return (json_decode($json) !== null) ? true : false; + return (\json_decode($json) !== null) ? true : false; } } \ No newline at end of file diff --git a/integration-tests/MongoUnit/TestCase.php b/integration-tests/mongoUnit/TestCase.php similarity index 79% rename from integration-tests/MongoUnit/TestCase.php rename to integration-tests/mongoUnit/TestCase.php index a5f5222..3857b08 100644 --- a/integration-tests/MongoUnit/TestCase.php +++ b/integration-tests/mongoUnit/TestCase.php @@ -4,13 +4,13 @@ * @copyright 2010 Jonathan Moss * @package MongoUnit */ - +namespace mongoUnit; require_once 'PHPUnit/Framework/TestCase.php'; require_once dirname(__FILE__).'/JsonLoader.php'; -require_once dirname(__FILE__).'/Constraint/CollectionExists.php'; -require_once dirname(__FILE__).'/Constraint/CollectionDoesNotExist.php'; -require_once dirname(__FILE__).'/Constraint/DocumentExists.php'; -require_once dirname(__FILE__).'/Constraint/DocumentPropertyEquals.php'; +require_once dirname(__FILE__).'/constraint/CollectionExists.php'; +require_once dirname(__FILE__).'/constraint/CollectionDoesNotExist.php'; +require_once dirname(__FILE__).'/constraint/DocumentExists.php'; +require_once dirname(__FILE__).'/constraint/DocumentPropertyEquals.php'; /** * MongoUnit Test Case @@ -19,7 +19,7 @@ * It provides new assertion types specific to MongoDB * @package MongoUnit */ -class MongoUnit_TestCase extends PHPUnit_Framework_TestCase +class TestCase extends \PHPUnit_Framework_TestCase { const TEST_DB_NAME = 'MongoTestDB'; @@ -48,7 +48,7 @@ class MongoUnit_TestCase extends PHPUnit_Framework_TestCase public function setup() { - if (!extension_loaded('mongo')) { + if (!\extension_loaded('mongo')) { $this->markSkipped('Mongo extension not installed'); } } @@ -95,7 +95,7 @@ protected function getDsn() protected function getConnection() { if (!isset($this->connection)) { - $this->connection = new Mongo($this->getDsn()); + $this->connection = new \Mongo($this->getDsn()); } return $this->connection; } @@ -150,10 +150,10 @@ protected function getDatabase() public function assertCollectionExists($collection, $message = '') { if (!is_string($collection)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); + throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); } - self::assertThat($collection, new MongoUnit_Constraint_CollectionExists($this->getDatabase()), $message); + self::assertThat($collection, new \mongoUnit\constraint\CollectionExists($this->getDatabase()), $message); } /** @@ -165,10 +165,10 @@ public function assertCollectionExists($collection, $message = '') public function assertCollectionDoesNotExist($collection, $message = '') { if (!is_string($collection)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); + throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); } - self::assertThat($collection, new MongoUnit_Constraint_CollectionDoesNotExist($this->getDatabase()), $message); + self::assertThat($collection, new \mongoUnit\constraint\CollectionDoesNotExist($this->getDatabase()), $message); } /** @@ -181,14 +181,14 @@ public function assertCollectionDoesNotExist($collection, $message = '') public function assertDocumentExists($collection, $id, $message = '') { if (!is_string($collection)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); + throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); } - self::assertThat($id, new MongoUnit_Constraint_DocumentExists($this->getDatabase(), $collection), $message); + self::assertThat($id, new \mongoUnit\constraint\DocumentExists($this->getDatabase(), $collection), $message); } public function assertDocumentPropertyEquals($expected, $collection, $property, $id, $message = '') { - $constraint = new MongoUnit_Constraint_DocumentPropertyEquals($this->getDatabase(), $collection, $property, $expected); + $constraint = new \mongoUnit\constraint\DocumentPropertyEquals($this->getDatabase(), $collection, $property, $expected); self::assertThat($id, $constraint, $message); } @@ -208,7 +208,7 @@ public function assertDocumentPropertyEquals($expected, $collection, $property, public function loadJsonFileDatasetIntoCollection($collectionName, $filePath) { $collection = $this->getDatabase()->selectCollection($collectionName); - $loader = new MongoUnit_JsonLoader($collection); + $loader = new JsonLoader($collection); return $loader->loadFromJsonFile($filePath); } @@ -224,7 +224,7 @@ public function loadJsonFileDatasetIntoCollection($collectionName, $filePath) public function loadJsonStringDatasetIntoCollection($collectionName, $json) { $collection = $this->getDatabase()->selectCollection($collectionName); - $loader = new MongoUnit_JsonLoader($collection); + $loader = new JsonLoader($collection); return $loader->loadJsonFromString($json); } diff --git a/integration-tests/MongoUnit/Constraint/CollectionDoesNotExist.php b/integration-tests/mongoUnit/constraint/CollectionDoesNotExist.php similarity index 89% rename from integration-tests/MongoUnit/Constraint/CollectionDoesNotExist.php rename to integration-tests/mongoUnit/constraint/CollectionDoesNotExist.php index 7797072..b8e9c1d 100644 --- a/integration-tests/MongoUnit/Constraint/CollectionDoesNotExist.php +++ b/integration-tests/mongoUnit/constraint/CollectionDoesNotExist.php @@ -5,6 +5,8 @@ * @package MongoUnit * @subpackage Constraint */ +namespace mongoUnit\constraint; + require_once 'PHPUnit/Util/Type.php'; /** * A PHP Unit constraint that checks a collection does not exist @@ -12,7 +14,7 @@ * @package MongoUnit * @subpackage Constraint */ -class MongoUnit_Constraint_CollectionDoesNotExist extends PHPUnit_Framework_Constraint +class CollectionDoesNotExist extends \PHPUnit_Framework_Constraint { /** * @var MongoDB @@ -42,7 +44,7 @@ public function evaluate($other) foreach ($collections as $collection) { $collectionNames[] = $collection->getName(); } - return !in_array($other, $collectionNames); + return !\in_array($other, $collectionNames); } /** @@ -62,11 +64,10 @@ public function toString() */ protected function customFailureDescription($other, $description, $not) { - return sprintf( + return \sprintf( 'Failed asserting that the %s %s', $other, $this->toString() ); } } -?> diff --git a/integration-tests/MongoUnit/Constraint/CollectionExists.php b/integration-tests/mongoUnit/constraint/CollectionExists.php similarity index 87% rename from integration-tests/MongoUnit/Constraint/CollectionExists.php rename to integration-tests/mongoUnit/constraint/CollectionExists.php index 9bf4bc6..8c583d9 100644 --- a/integration-tests/MongoUnit/Constraint/CollectionExists.php +++ b/integration-tests/mongoUnit/constraint/CollectionExists.php @@ -5,6 +5,8 @@ * @package MongoUnit * @subpackage Constraint */ +namespace mongoUnit\constraint; + require_once 'PHPUnit/Util/Type.php'; /** * A PHP Unit constraint that checks if a collection exists @@ -12,7 +14,7 @@ * @package MongoUnit * @subpackage Constraint */ -class MongoUnit_Constraint_CollectionExists extends PHPUnit_Framework_Constraint +class CollectionExists extends \PHPUnit_Framework_Constraint { /** * @var MongoDB @@ -20,7 +22,7 @@ class MongoUnit_Constraint_CollectionExists extends PHPUnit_Framework_Constraint private $db; /** - * @param integer|string $key + * @param \MongoDB */ public function __construct($db) { @@ -42,7 +44,7 @@ public function evaluate($other) foreach ($collections as $collection) { $collectionNames[] = $collection->getName(); } - return in_array($other, $collectionNames); + return \in_array($other, $collectionNames); } /** @@ -62,11 +64,10 @@ public function toString() */ protected function customFailureDescription($other, $description, $not) { - return sprintf( + return \sprintf( 'Failed asserting that the %s %s', $other, $this->toString() ); } } -?> diff --git a/integration-tests/MongoUnit/Constraint/DocumentExists.php b/integration-tests/mongoUnit/constraint/DocumentExists.php similarity index 89% rename from integration-tests/MongoUnit/Constraint/DocumentExists.php rename to integration-tests/mongoUnit/constraint/DocumentExists.php index 6cbe14e..a14598f 100644 --- a/integration-tests/MongoUnit/Constraint/DocumentExists.php +++ b/integration-tests/mongoUnit/constraint/DocumentExists.php @@ -5,6 +5,8 @@ * @package MongoUnit * @subpackage Constraint */ +namespace mongoUnit\constraint; + require_once 'PHPUnit/Util/Type.php'; /** * A PHP Unit constraint that checks to ensure a specific document exists @@ -12,7 +14,7 @@ * @package MongoUnit * @subpackage Constraint */ -class MongoUnit_Constraint_DocumentExists extends PHPUnit_Framework_Constraint +class DocumentExists extends \PHPUnit_Framework_Constraint { /** * @var MongoDB @@ -22,7 +24,8 @@ class MongoUnit_Constraint_DocumentExists extends PHPUnit_Framework_Constraint private $collection; /** - * @param integer|string $key + * @param \MongoDB $db + * @param \MongoCollection $collection */ public function __construct($db, $collection) { @@ -65,11 +68,10 @@ public function toString() */ protected function customFailureDescription($other, $description, $not) { - return sprintf( + return \sprintf( 'Failed asserting that the document %s %s', $other, $this->toString() ); } } -?> diff --git a/integration-tests/MongoUnit/Constraint/DocumentPropertyEquals.php b/integration-tests/mongoUnit/constraint/DocumentPropertyEquals.php similarity index 89% rename from integration-tests/MongoUnit/Constraint/DocumentPropertyEquals.php rename to integration-tests/mongoUnit/constraint/DocumentPropertyEquals.php index 7974979..5469abe 100644 --- a/integration-tests/MongoUnit/Constraint/DocumentPropertyEquals.php +++ b/integration-tests/mongoUnit/constraint/DocumentPropertyEquals.php @@ -5,6 +5,8 @@ * @package MongoUnit * @subpackage Constraint */ +namespace mongoUnit\constraint; + require_once 'PHPUnit/Util/Type.php'; /** * A PHP Unit constraint that checks to ensure a specific document property @@ -13,7 +15,7 @@ * @package MongoUnit * @subpackage Constraint */ -class MongoUnit_Constraint_DocumentPropertyEquals extends PHPUnit_Framework_Constraint +class DocumentPropertyEquals extends \PHPUnit_Framework_Constraint { /** * @var MongoDB @@ -67,7 +69,7 @@ public function evaluate($other) */ public function toString() { - return "expected:\n" . print_r($this->expected, true); + return "expected:\n" . \print_r($this->expected, true); } /** @@ -77,13 +79,12 @@ public function toString() */ protected function customFailureDescription($other, $description, $not) { - return sprintf( + return \sprintf( "Failed asserting that the property %s in document \n%s %s\nactual: ", $this->property, $other, $this->toString(), - print_r($this->found) + \print_r($this->found) ); } } -?> diff --git a/integration-tests/test-objects/Child.php b/integration-tests/test-objects/Child.php index b2a83e2..0b498c9 100644 --- a/integration-tests/test-objects/Child.php +++ b/integration-tests/test-objects/Child.php @@ -1,12 +1,12 @@ addProperty(new Morph_Property_String('Name')); - $this->addProperty(new Morph_Property_Integer('Age')); + $this->addProperty(new \morph\property\String('Name')); + $this->addProperty(new \morph\property\Integer('Age')); } } \ No newline at end of file diff --git a/integration-tests/test-objects/ComposeManyParent.php b/integration-tests/test-objects/ComposeManyParent.php index 9d5b502..3d1e752 100644 --- a/integration-tests/test-objects/ComposeManyParent.php +++ b/integration-tests/test-objects/ComposeManyParent.php @@ -1,12 +1,12 @@ addProperty(new Morph_Property_ComposeMany('Children', 'Child')); - $this->addProperty(new Morph_Property_String('Name')); + $this->addProperty(new \morph\property\ComposeMany('Children', 'Child')); + $this->addProperty(new \morph\property\String('Name')); } } \ No newline at end of file diff --git a/integration-tests/test-objects/ComposeOneParent.php b/integration-tests/test-objects/ComposeOneParent.php index 342ada9..b492091 100644 --- a/integration-tests/test-objects/ComposeOneParent.php +++ b/integration-tests/test-objects/ComposeOneParent.php @@ -1,12 +1,12 @@ addProperty(new Morph_Property_ComposeOne('Child', 'Child')); - $this->addProperty(new Morph_Property_String('Name')); + $this->addProperty(new \morph\property\ComposeOne('Child', 'Child')); + $this->addProperty(new \morph\property\String('Name')); } } \ No newline at end of file diff --git a/integration-tests/test-objects/HasManyParent.php b/integration-tests/test-objects/HasManyParent.php index db73170..876ea21 100644 --- a/integration-tests/test-objects/HasManyParent.php +++ b/integration-tests/test-objects/HasManyParent.php @@ -1,12 +1,12 @@ addProperty(new Morph_Property_HasMany('Children', 'Child')); - $this->addProperty(new Morph_Property_String('Name')); + $this->addProperty(new \morph\property\HasMany('Children', 'Child')); + $this->addProperty(new \morph\property\String('Name')); } } \ No newline at end of file diff --git a/integration-tests/test-objects/HasOneParent.php b/integration-tests/test-objects/HasOneParent.php index ad35289..b37c078 100644 --- a/integration-tests/test-objects/HasOneParent.php +++ b/integration-tests/test-objects/HasOneParent.php @@ -1,12 +1,12 @@ addProperty(new Morph_Property_HasOne('Child', 'Child')); - $this->addProperty(new Morph_Property_String('Name')); + $this->addProperty(new \morph\property\HasOne('Child', 'Child')); + $this->addProperty(new \morph\property\String('Name')); } } \ No newline at end of file diff --git a/integration-tests/test-objects/User.php b/integration-tests/test-objects/User.php index 8caa5e2..17d9e9c 100644 --- a/integration-tests/test-objects/User.php +++ b/integration-tests/test-objects/User.php @@ -1,12 +1,12 @@ addProperty(new Morph_Property_String('Username')) - ->addProperty(new Morph_Property_File('Avatar')); + $this->addProperty(new \morph\property\String('Username')) + ->addProperty(new \morph\property\File('Avatar')); } } \ No newline at end of file diff --git a/src/bootstrap.php b/src/bootstrap.php index 199fb0e..4786c66 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -18,32 +18,32 @@ class MorphAutoloader * @var array */ private static $classes = array( - 'Morph_Collection' => 'phar://Morph/Collection.php', - 'Morph_Utils' => 'phar://Morph/Utils.php', - 'Morph_Iterator' => 'phar://Morph/Iterator.php', - 'Morph_Compare_NumericProperty' => 'phar://Morph/Compare/NumericProperty.php', - 'Morph_Compare_Property' => 'phar://Morph/Compare/Property.php', - 'Morph_PropertySet' => 'phar://Morph/PropertySet.php', - 'Morph_Query' => 'phar://Morph/Query.php', - 'Morph_IQuery' => 'phar://Morph/IQuery.php', - 'Morph_Object' => 'phar://Morph/Object.php', - 'Morph_ICompare' => 'phar://Morph/ICompare.php', - 'Morph_Property_HasMany' => 'phar://Morph/Property/HasMany.php', - 'Morph_Property_Date' => 'phar://Morph/Property/Date.php', - 'Morph_Property_ComposeMany' => 'phar://Morph/Property/ComposeMany.php', - 'Morph_Property_HasOne' => 'phar://Morph/Property/HasOne.php', - 'Morph_Property_Enum' => 'phar://Morph/Property/Enum.php', - 'Morph_Property_Integer' => 'phar://Morph/Property/Integer.php', - 'Morph_Property_File' => 'phar://Morph/Property/File.php', - 'Morph_Property_Float' => 'phar://Morph/Property/Float.php', - 'Morph_Property_ComposeOne' => 'phar://Morph/Property/ComposeOne.php', - 'Morph_Property_String' => 'phar://Morph/Property/String.php', - 'Morph_Property_Generic' => 'phar://Morph/Property/Generic.php', - 'Morph_Query_Property' => 'phar://Morph/Query/Property.php', - 'Morph_Storage' => 'phar://Morph/Storage.php', - 'Morph_Format_Collection' => 'phar://Morph/Format/Collection.php', - 'Morph_Enum' => 'phar://Morph/Enum.php', - 'Morph_Exception_ObjectNotFound' => 'phar://Morph/Exception/ObjectNotFound.php', + 'morph\\Collection' => 'phar://Morph/Collection.php', + 'morph\\Enum' => 'phar://Morph/Enum.php', + 'morph\\Utils' => 'phar://Morph/Utils.php', + 'morph\\Iterator' => 'phar://Morph/Iterator.php', + 'morph\\compare\\NumericProperty' => 'phar://Morph/compare/NumericProperty.php', + 'morph\\compare\\Property' => 'phar://Morph/compare/Property.php', + 'morph\\PropertySet' => 'phar://Morph/PropertySet.php', + 'morph\\Query' => 'phar://Morph/Query.php', + 'morph\\IQuery' => 'phar://Morph/IQuery.php', + 'morph\\Object' => 'phar://Morph/Object.php', + 'morph\\ICompare' => 'phar://Morph/ICompare.php', + 'morph\\Storage' => 'phar://Morph/Storage.php', + 'morph\\property\\HasMany' => 'phar://Morph/property/HasMany.php', + 'morph\\property\\Date' => 'phar://Morph/property/Date.php', + 'morph\\property\\ComposeMany' => 'phar://Morph/property/ComposeMany.php', + 'morph\\property\\HasOne' => 'phar://Morph/property/HasOne.php', + 'morph\\property\\Enum' => 'phar://Morph/property/Enum.php', + 'morph\\property\\Integer' => 'phar://Morph/property/Integer.php', + 'morph\\property\\File' => 'phar://Morph/property/File.php', + 'morph\\property\\Float' => 'phar://Morph/property/Float.php', + 'morph\\property\\ComposeOne' => 'phar://Morph/property/ComposeOne.php', + 'morph\\property\\String' => 'phar://Morph/property/String.php', + 'morph\\property\\Generic' => 'phar://Morph/property/Generic.php', + 'morph\\query\\Property' => 'phar://Morph/query/Property.php', + 'morph\\format\\Collection' => 'phar://Morph/format/Collection.php', + 'morph\\exception\\ObjectNotFound' => 'phar://Morph/exception/ObjectNotFound.php', ); /** diff --git a/src/Morph/Collection.php b/src/morph/Collection.php similarity index 84% rename from src/Morph/Collection.php rename to src/morph/Collection.php index c029f75..125c5d6 100644 --- a/src/Morph/Collection.php +++ b/src/morph/Collection.php @@ -4,7 +4,7 @@ * @copyright 2009 Jonathan Moss * @package Morph */ - +namespace morph; /** * Morph collection object * @@ -18,7 +18,7 @@ * * @package Morph */ -class Morph_Collection extends ArrayObject +class Collection extends \ArrayObject { /** @@ -30,7 +30,7 @@ class Morph_Collection extends ArrayObject * The classname of the class this collection should allow * @var String */ - private $PermissableType = 'Morph_Object'; + private $permissableType = 'Morph\\Object'; /** * Sets the classname of the class this collection should allow @@ -39,7 +39,7 @@ class Morph_Collection extends ArrayObject */ public function setPermissableType($type) { - $this->PermissableType = (string) $type; + $this->permissableType = (string) $type; } /** @@ -81,7 +81,7 @@ public function totalCount() */ public function filter($callback = null) { - return new self(array_filter($this->getArrayCopy(), $callback)); + return new self(\array_filter($this->getArrayCopy(), $callback)); } /** @@ -97,7 +97,7 @@ public function filter($callback = null) public function walk($callback, $userdata = null) { $copy = $this->getArrayCopy(); - array_walk($copy, $callback, $userdata); + \array_walk($copy, $callback, $userdata); return new self($copy); } @@ -113,7 +113,7 @@ public function walk($callback, $userdata = null) */ public function reduce($callback, $initial = null) { - return array_reduce($this->getArrayCopy(), $callback, $initial); + return \array_reduce($this->getArrayCopy(), $callback, $initial); } /** @@ -122,10 +122,10 @@ public function reduce($callback, $initial = null) * @param Morph_ICompare $comparator * @return boolean */ - public function comparatorSort(Morph_ICompare $comparator) + public function comparatorSort(ICompare $comparator) { $copy = $this->getArrayCopy(); //ArrayObject - $sorted = usort($copy,array($comparator, 'compare')); + $sorted = \usort($copy,array($comparator, 'compare')); $this->exchangeArray($copy); return $sorted; } @@ -138,7 +138,7 @@ public function comparatorSort(Morph_ICompare $comparator) * @param $comparator * @return boolean */ - public function comparatorASort(Morph_ICompare $comparator) + public function comparatorASort(ICompare $comparator) { return $this->uasort(array($comparator, 'compare')); } @@ -151,7 +151,7 @@ public function comparatorASort(Morph_ICompare $comparator) */ public function propertySort($propertyName, $preserveKeys = false) { - $comparator = new Morph_compare_Property($propertyName); + $comparator = new \morph\compare\Property($propertyName); $sorted = null; if($preserveKeys === true){ $sorted = $this->comparatorASort($comparator); @@ -169,7 +169,7 @@ public function propertySort($propertyName, $preserveKeys = false) */ public function numericPropertySort($propertyName, $preserveKeys = false) { - $comparator = new Morph_compare_NumericProperty($propertyName); + $comparator = new \morph\compare\NumericProperty($propertyName); $sorted = null; if($preserveKeys === true){ $sorted = $this->comparatorASort($comparator); @@ -214,15 +214,15 @@ public function offsetSet($offset, $object) * @param $object */ private function checkType($object){ - if(!($object instanceof $this->PermissableType)){ - throw new RuntimeException('object of type' . get_class($object) . ' does not extend ' . $this->PermissableType); + if(!($object instanceof $this->permissableType)){ + throw new \RuntimeException('object of type' . \get_class($object) . ' does not extend ' . $this->permissableType); } } public function __toString() { - $class = $this->PermissableType; + $class = $this->permissableType; $count = $this->count(); - return "Morph_Collection($class) Count: $count"; + return "\\Morph\\Collection($class) Count: $count"; } } diff --git a/src/Morph/Enum.php b/src/morph/Enum.php similarity index 81% rename from src/Morph/Enum.php rename to src/morph/Enum.php index c327815..606ccf1 100644 --- a/src/Morph/Enum.php +++ b/src/morph/Enum.php @@ -2,15 +2,15 @@ /** * @author Jonathan Moss * @copyright 2009 Jonathan Moss - * @package Morph + * @package morph */ - +namespace morph; /** * Morph Enum object * - * @package Morph + * @package morph */ -class Morph_Enum +class Enum { const STATE_NEW = 'New'; const STATE_CLEAN = 'Clean'; diff --git a/src/Morph/ICompare.php b/src/morph/ICompare.php similarity index 84% rename from src/Morph/ICompare.php rename to src/morph/ICompare.php index 501c6b8..33418b3 100644 --- a/src/Morph/ICompare.php +++ b/src/morph/ICompare.php @@ -4,13 +4,13 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph; /** * Interface for Morph comparators * * @package Morph */ -interface Morph_ICompare +interface ICompare { /** * The actual comparison function @@ -22,6 +22,6 @@ interface Morph_ICompare * @param Morph_Object $objectB * @return int */ - public function compare(Morph_Object $objectA, Morph_Object $objectB); + public function compare(Object $objectA, Object $objectB); } diff --git a/src/Morph/IQuery.php b/src/morph/IQuery.php similarity index 93% rename from src/Morph/IQuery.php rename to src/morph/IQuery.php index 80b677b..839a752 100644 --- a/src/Morph/IQuery.php +++ b/src/morph/IQuery.php @@ -4,13 +4,13 @@ * @author Jonathan Moss * @copyright 2011 Jonathan Moss */ - +namespace morph; /** * An interface for query objects * * @author Jonathan Moss */ -interface Morph_IQuery +interface IQuery { /** diff --git a/src/Morph/Iterator.php b/src/morph/Iterator.php similarity index 88% rename from src/Morph/Iterator.php rename to src/morph/Iterator.php index c16eba0..f998480 100644 --- a/src/Morph/Iterator.php +++ b/src/morph/Iterator.php @@ -5,13 +5,13 @@ * @copyright 2009 Jonathan Moss * @version SVN: $Id$ */ - +namespace morph; /** * An iterator to hold results of a query * * @package Morph */ -class Morph_Iterator implements Iterator +class Iterator implements \Iterator { /** @@ -37,7 +37,7 @@ class Morph_Iterator implements Iterator * @param MongoCursor $cursor * @return Morph_Iterator */ - public function __construct(Morph_Object $object, MongoCursor $cursor) + public function __construct(Object $object, \MongoCursor $cursor) { $this->type = $object; $this->cursor = $cursor; @@ -64,8 +64,8 @@ public function totalCount() public function toCollection() { - $collection = new Morph_Collection(); - $collection->setPermissableType(get_class($this->type)); + $collection = new Collection(); + $collection->setPermissableType(\get_class($this->type)); $collection->setTotalCount($this->totalCount()); $this->rewind(); @@ -84,9 +84,9 @@ public function toCollection() */ private function createObject(array $item) { - $class = get_class($this->type); + $class = \get_class($this->type); $object = new $class; - $object->__setData($item, Morph_Enum::STATE_CLEAN); + $object->__setData($item, Enum::STATE_CLEAN); return $object; } diff --git a/src/Morph/Object.php b/src/morph/Object.php similarity index 71% rename from src/Morph/Object.php rename to src/morph/Object.php index 7e8048b..fd0c0a8 100644 --- a/src/Morph/Object.php +++ b/src/morph/Object.php @@ -4,25 +4,25 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph; /** * A base class for creating model objects for storing in MongoDB. * * @package Morph */ -class Morph_Object +class Object { /** * The name of the collection this object is stored within * @var string */ - protected $Collection; + protected $collection; /** * The unique id for this object * @var string */ - protected $Id; + protected $id; /** * The current state of this object @@ -30,7 +30,7 @@ class Morph_Object * one of Morph_Enum::STATE_* * @var string */ - protected $State; + protected $state; /** * The data associated with this object @@ -42,7 +42,7 @@ class Morph_Object * The collections of validators for propertys * @var array */ - protected $Validators; + protected $validators; /** * @param string $id If supplied this will be the id used to reference this object @@ -50,10 +50,10 @@ class Morph_Object */ public function __construct($id = null) { - $this->State = Morph_Enum::STATE_NEW; - $this->Id = $id; - $this->propertySet = new Morph_PropertySet(); - $this->Validators = array(); + $this->state = Enum::STATE_NEW; + $this->id = $id; + $this->propertySet = new PropertySet(); + $this->validators = array(); } // *********************** // @@ -68,13 +68,13 @@ public function __construct($id = null) */ public function collection($collection = null) { - if (!is_null($collection)) { - $this->Collection = $collection; - }elseif (is_null($this->Collection)) { + if (!\is_null($collection)) { + $this->collection = $collection; + }elseif (\is_null($this->collection)) { //defaults collection name to class name - $this->Collection = Morph_Utils::collectionName($this); + $this->collection = Utils::collectionName($this); } - return $this->Collection; + return $this->collection; } /** @@ -83,7 +83,7 @@ public function collection($collection = null) */ public function id() { - return $this->Id; + return $this->id; } /** @@ -95,7 +95,7 @@ public function id() */ public function state() { - return $this->State; + return $this->state; } /** @@ -104,7 +104,7 @@ public function state() * @param Morph_Property_Generic $property * @return Morph_Object */ - protected function addProperty(Morph_Property_Generic $property) + protected function addProperty(\morph\property\Generic $property) { $this->propertySet[$property->getName()] = $property; return $this; @@ -117,19 +117,19 @@ protected function addProperty(Morph_Property_Generic $property) * @param $state * @return Morph_Object */ - public function __setData(array $data, $state = Morph_Enum::STATE_DIRTY) + public function __setData(array $data, $state = Enum::STATE_DIRTY) { - if (array_key_exists('_id', $data)) { - $this->Id = $data['_id']; + if (\array_key_exists('_id', $data)) { + $this->id = $data['_id']; unset($data['_id']); } - if (array_key_exists('_ns', $data)) { + if (\array_key_exists('_ns', $data)) { unset($data['_ns']); } foreach ($data as $propertyName => $value) { $this->propertySet->__setRawPropertyValue($propertyName, $value); } - $this->State = $state; + $this->state = $state; return $this; } @@ -141,10 +141,10 @@ public function __setData(array $data, $state = Morph_Enum::STATE_DIRTY) public function __getData() { $data = array(); - if (!is_null($this->Id)) { - $data['_id'] = $this->Id; + if (!is_null($this->id)) { + $data['_id'] = $this->id; } - $data['_ns'] = get_class($this); + $data['_ns'] = \get_class($this); foreach($this->propertySet as $property) { $data[$property->getName()] = $property->__getRawValue(); } @@ -163,10 +163,10 @@ public function __getData() public function __get($propertyName) { $value = null; - if (array_key_exists($propertyName, $this->propertySet)) { + if (\array_key_exists($propertyName, $this->propertySet)) { $value = $this->propertySet[$propertyName]->getValue(); }else{ - trigger_error("The property $propertyName was not found in object of class " . get_class($this), E_USER_WARNING); + \trigger_error("The property $propertyName was not found in object of class " . \get_class($this), E_USER_WARNING); } return $value; } @@ -179,14 +179,14 @@ public function __get($propertyName) */ public function __set($propertyName, $propertyValue) { - if (array_key_exists($propertyName, $this->propertySet)) { + if (\array_key_exists($propertyName, $this->propertySet)) { $this->propertySet[$propertyName]->setValue($propertyValue); - if ($this->State == Morph_Enum::STATE_CLEAN) { - $this->State = Morph_Enum::STATE_DIRTY; + if ($this->state == Enum::STATE_CLEAN) { + $this->state = Enum::STATE_DIRTY; } }else{ - $this->addProperty(new Morph_Property_Generic($propertyName, $propertyValue)); - trigger_error("The property $propertyName was not found in object of class " . get_class($this) . ' but I have added it as a generic property type', E_USER_WARNING); + $this->addProperty(new \morph\property_Generic($propertyName, $propertyValue)); + \trigger_error("The property $propertyName was not found in object of class " . \get_class($this) . ' but I have added it as a generic property type', E_USER_WARNING); } return $this; } @@ -202,7 +202,7 @@ public function __set($propertyName, $propertyValue) */ public function save() { - return Morph_Storage::instance()->save($this); + return Storage::instance()->save($this); } /** @@ -213,7 +213,7 @@ public function save() */ public function loadById($id) { - return Morph_Storage::instance()->fetchById($this, $id); + return Storage::instance()->fetchById($this, $id); } /** @@ -224,7 +224,7 @@ public function loadById($id) */ public function findByIds(array $ids) { - return Morph_Storage::instance()->fetchByIds($this, $ids); + return Storage::instance()->fetchByIds($this, $ids); } /** @@ -233,9 +233,9 @@ public function findByIds(array $ids) * @param Morph_IQuery $query * @return Morph_Iterator */ - public function findByQuery(Morph_IQuery $query) + public function findByQuery(IQuery $query) { - return Morph_Storage::instance()->findByQuery($this, $query); + return Storage::instance()->findByQuery($this, $query); } /** @@ -244,9 +244,9 @@ public function findByQuery(Morph_IQuery $query) * @param Morph_Query $query * @return Morph_Object */ - public function findOneByQuery(Morph_IQuery $query) + public function findOneByQuery(IQuery $query) { - return Morph_Storage::instance()->findOneByQuery($this, $query); + return Storage::instance()->findOneByQuery($this, $query); } /** @@ -256,7 +256,7 @@ public function findOneByQuery(Morph_IQuery $query) */ public function delete() { - return Morph_Storage::instance()->delete($this); + return Storage::instance()->delete($this); } // ***************** // @@ -290,30 +290,30 @@ public function __toString() public function __toArray($depth = 1) { $content = array(); - if (!empty($this->Id)) { - $content['_id'] = $this->Id; + if (!empty($this->id)) { + $content['_id'] = $this->id; } --$depth; foreach ($this->propertySet as $property) { $value = $property->getValue(); switch (true) { - case ($property instanceof Morph_Property_ComposeOne): + case ($property instanceof \morph\property\ComposeOne): $content[$value->getName()] = $value->__toArray($depth); break; - case ($property instanceof Morph_Property_ComposeMany): + case ($property instanceof morph\Property\ComposeMany): $valueContents = array(); foreach ($value as $object) { $valueContents[] = $object->__toArray($depth); } $content[$property->getName()] = $valueContents; break; - case ($value instanceof Morph_Object): + case ($value instanceof Object): if ($depth > 0) { $content[$value->getName()] = $value->__toArray($depth); } break; - case ($value instanceof Morph_Collection): + case ($value instanceof Collection): if ($depth > 0) { $valueContents = array(); foreach ($value as $object) { diff --git a/src/Morph/PropertySet.php b/src/morph/PropertySet.php similarity index 79% rename from src/Morph/PropertySet.php rename to src/morph/PropertySet.php index 488a38c..ffb5502 100644 --- a/src/Morph/PropertySet.php +++ b/src/morph/PropertySet.php @@ -4,13 +4,13 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph; /** * Object to represent a set of properties * * @package Morph */ -class Morph_PropertySet extends ArrayObject +class PropertySet extends \ArrayObject { /** @@ -70,7 +70,7 @@ public function __getRawPropertyValue($name) public function __setRawPropertyValue($name, $value) { if(!isset($this[$name])){ - $this[$name] = new Morph_Property_Generic($name); + $this[$name] = new \morph\property\Generic($name); } $this[$name]->__setRawValue($value); } @@ -85,7 +85,7 @@ public function __setRawPropertyValue($name, $value) */ public function append($object) { - throw new RuntimeException("Appending to PropertySet is not supported"); + throw new \RuntimeException("Appending to PropertySet is not supported"); } /** @@ -98,7 +98,7 @@ public function offsetSet($offset, $object) { $this->checkType($object); if (empty($offset)) { - throw new RuntimeException("Unnamed properties are not supported"); + throw new \RuntimeException("Unnamed properties are not supported"); } return parent::offsetSet($offset, $object); } @@ -112,12 +112,12 @@ public function offsetSet($offset, $object) */ private function checkType($object) { - if (!is_object($object)) { - throw new InvalidArgumentException('value if not and object that extends Morph_Property_Generic'); + if (!\is_object($object)) { + throw new \InvalidArgumentException('value if not and object that extends Morph_Property_Generic'); } - if(!($object instanceof Morph_Property_Generic)){ - throw new InvalidArgumentException('object of type' . get_class($object) . ' does not extend Morph_Property_Generic'); + if(!($object instanceof \morph\property\Generic)){ + throw new \InvalidArgumentException('object of type' . \get_class($object) . ' does not extend morph\\property\\Generic'); } } } diff --git a/src/Morph/Query.php b/src/morph/Query.php similarity index 97% rename from src/Morph/Query.php rename to src/morph/Query.php index f422a09..6d13e6d 100644 --- a/src/Morph/Query.php +++ b/src/morph/Query.php @@ -4,7 +4,7 @@ * @author Jonathan Moss * @copyright 2009 Jonathan Moss */ - +namespace morph; /** * A query class to represent queries to the database * @@ -40,7 +40,7 @@ * * @package Morph */ -class Morph_Query implements Morph_IQuery +class Query implements IQuery { /** @@ -143,7 +143,7 @@ public function getSkip() */ public function property($propertyName) { - $property = new Morph_Query_Property($this); + $property = new \morph\query\Property($this); $this->criteria[$propertyName] = $property; return $property; } diff --git a/src/Morph/Storage.php b/src/morph/Storage.php similarity index 63% rename from src/Morph/Storage.php rename to src/morph/Storage.php index e03b079..9d0ca52 100644 --- a/src/Morph/Storage.php +++ b/src/morph/Storage.php @@ -4,14 +4,14 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph; /** * This class provides the Morph_Object <--> MongoDB * storage provider. * * @package Morph */ -class Morph_Storage +class Storage { /** @@ -22,7 +22,7 @@ class Morph_Storage /** * @var MongoDB */ - private $Db; + private $db; /** * Returns the singleton instance of this class @@ -31,7 +31,7 @@ class Morph_Storage public static function instance() { if (!isset(self::$instance)) { - throw new RuntimeException("Morph_Storage has not been initialised"); + throw new \RuntimeException("Morph Storage has not been initialised"); } return self::$instance; } @@ -42,7 +42,7 @@ public static function instance() * @param MongoDB $db * @return Morph_Storage */ - public static function init(MongoDB $db) + public static function init(\MongoDB $db) { self::$instance = new self($db); return self::$instance; @@ -63,9 +63,9 @@ public static function deInit() * @param MongoDB $db * @return Morph_Mapper */ - private function __construct(MongoDB $db) + private function __construct(\MongoDB $db) { - $this->Db = $db; + $this->db = $db; } /** @@ -75,34 +75,34 @@ private function __construct(MongoDB $db) */ public function getDatabase() { - return $this->Db; + return $this->db; } /** * Retrieves the contents of the specified $id * and assigns them into $object * - * @param Morph_Object $object + * @param Morph\\Object $object * @param mixed $id - * @return Morph_Object + * @return Morph\\Object */ - public function fetchById(Morph_Object $object, $id) + public function fetchById(Object $object, $id) { $query = array('_id' => $id); - $data = $this->Db->selectCollection($object->collection())->findOne($query); + $data = $this->db->selectCollection($object->collection())->findOne($query); return $this->setData($object, $data); } /** * Returns all objects with an _id in $ids * - * @param Morph_Object $object + * @param Morph\\Object $object * @param array $Ids - * @return Morph_Iterator + * @return Morph\\Iterator */ - public function fetchByIds(Morph_Object $object, array $ids) + public function fetchByIds(Object $object, array $ids) { - $query = new Morph_Query(); + $query = new Query(); $query->property('_id')->in($ids); return $this->findByQuery($object, $query); } @@ -115,9 +115,9 @@ public function fetchByIds(Morph_Object $object, array $ids) * @param array $dbRef * @return Morph_Object */ - public function fetchByDbRef(Morph_Object $object, array $dbRef) + public function fetchByDbRef(Object $object, array $dbRef) { - $data = $this->Db->getDBRef($dbRef); + $data = $this->db->getDBRef($dbRef); return $this->setData($object, $data); } @@ -127,12 +127,12 @@ public function fetchByDbRef(Morph_Object $object, array $dbRef) * @param $object * @return Morph_Object */ - public function save(Morph_Object $object) + public function save(Object $object) { $response = $object; - if ($object->state() == Morph_Enum::STATE_DIRTY){ + if ($object->state() == Enum::STATE_DIRTY){ $response = $this->update($object); - } elseif ($object->state() == Morph_Enum::STATE_NEW) { + } elseif ($object->state() == Enum::STATE_NEW) { $response = $this->insert($object); } return $response; @@ -144,20 +144,20 @@ public function save(Morph_Object $object) * @param Morph_Object $object * @return Morph_Object */ - private function insert(Morph_Object $object) + private function insert(Object $object) { $data = $object->__getData(); //set an id if we do not have one - if(!array_key_exists('_id', $data)){ + if(!\array_key_exists('_id', $data)){ $id = array( - '_id' => md5(uniqid(rand(), true)) + '_id' => \md5(\uniqid(\rand(), true)) ); - $data = array_merge($id, $data); + $data = \array_merge($id, $data); } - $savedOk = $this->Db->selectCollection($object->collection())->save($data); + $savedOk = $this->db->selectCollection($object->collection())->save($data); if($savedOk){ - $object->__setData($data, Morph_Enum::STATE_CLEAN); + $object->__setData($data, Enum::STATE_CLEAN); } return $object; } @@ -168,7 +168,7 @@ private function insert(Morph_Object $object) * @param Morph_Object $object * @return Morph_Object */ - private function update(Morph_Object $object) + private function update(Object $object) { return $this->insert($object); } @@ -179,10 +179,10 @@ private function update(Morph_Object $object) * @param Morph_Object $object * @return boolean */ - public function delete(Morph_Object $object) + public function delete(Object $object) { $query = array('_id' => $object->id()); - return $this->Db->selectCollection($object->collection())->remove($query, true); + return $this->db->selectCollection($object->collection())->remove($query, true); } /** @@ -194,29 +194,29 @@ public function delete(Morph_Object $object) * @param Morph_IQuery $query * @return Morph_Iterator */ - public function findByQuery(Morph_Object $object, Morph_IQuery $query = null) + public function findByQuery(Object $object, IQuery $query = null) { $class = get_class($object); - $query = (is_null($query)) ? new Morph_Query() : $query; - $cursor = $this->Db->selectCollection($object->collection())->find($query->getRawQuery()); + $query = (is_null($query)) ? new Query() : $query; + $cursor = $this->db->selectCollection($object->collection())->find($query->getRawQuery()); $limit = $query->getLimit(); - if (!is_null($limit)) { + if (!\is_null($limit)) { $cursor->limit($limit); } $skip = $query->getSkip(); - if (!is_null($skip)) { + if (!\is_null($skip)) { $cursor->skip($skip); } $sort = $query->getRawSort(); - if (!is_null($sort)) { + if (!\is_null($sort)) { $cursor->sort($sort); } - $iterator = new Morph_Iterator($object, $cursor); + $iterator = new Iterator($object, $cursor); return $iterator; } @@ -228,13 +228,13 @@ public function findByQuery(Morph_Object $object, Morph_IQuery $query = null) * @param Morph_IQuery $query * @return Morph_Object */ - public function findOneByQuery(Morph_Object $object, Morph_IQuery $query = null) + public function findOneByQuery(Object $object, IQuery $query = null) { $result = null; - $class = get_class($object); + $class = \get_class($object); - $query = (is_null($query)) ? new Morph_Query() : $query; - $data = $this->Db->selectCollection($object->collection())->findOne($query->getRawQuery()); + $query = (is_null($query)) ? new Query() : $query; + $data = $this->db->selectCollection($object->collection())->findOne($query->getRawQuery()); return $this->setData($object, $data); } @@ -247,7 +247,7 @@ public function findOneByQuery(Morph_Object $object, Morph_IQuery $query = null) public function fetchFile($id) { $query = array('_id' => $id); - return $this->Db->getGridFS()->findOne($query); + return $this->db->getGridFS()->findOne($query); } /** @@ -262,11 +262,11 @@ public function saveFile($filePath, $oldReference = null) $id = null; if (file_exists($filePath)) { if (!empty($oldReference)) { - $this->Db->getGridFS()->remove(array('_id'=>$oldReference), true); //remove existing file + $this->db->getGridFS()->remove(array('_id' => $oldReference), true); //remove existing file } - $id = $this->Db->getGridFS()->storeFile($filePath); + $id = $this->db->getGridFS()->storeFile($filePath); } else { - throw new InvalidArgumentException("The file $filePath does not exist"); + throw new \InvalidArgumentException("The file $filePath does not exist"); } return $id; } @@ -276,12 +276,12 @@ public function saveFile($filePath, $oldReference = null) * @param array $data * @return Morph_Object */ - private function setData(Morph_Object $object, $data) + private function setData(Object $object, $data) { if (empty($data)) { - throw new Morph_Exception_ObjectNotFound(); + throw new morph\exception\ObjectNotFound(); } - $object->__setData($data, Morph_Enum::STATE_CLEAN); + $object->__setData($data, Enum::STATE_CLEAN); return $object; } } \ No newline at end of file diff --git a/src/Morph/Utils.php b/src/morph/Utils.php similarity index 58% rename from src/Morph/Utils.php rename to src/morph/Utils.php index f38b977..1ee4f5a 100644 --- a/src/Morph/Utils.php +++ b/src/morph/Utils.php @@ -1,16 +1,16 @@ * @copyright Jonathan Moss 2009 */ - +namespace morph; /** * This class provides a few helper function for the Morph package * - * @package Morph + * @package morph */ -class Morph_Utils +class Utils { /** @@ -19,9 +19,9 @@ class Morph_Utils * @param $object * @return string */ - public static function collectionName(Morph_Object $object) + public static function collectionName(Object $object) { - return str_replace(array('_','\\'), '.', get_class($object)); + return \str_replace(array('_','\\'), '.', \get_class($object)); } /** @@ -30,8 +30,8 @@ public static function collectionName(Morph_Object $object) * @param $object * @return array */ - public static function objectReference(Morph_Object $object) + public static function objectReference(Object $object) { - return MongoDBRef::create($object->collection(), $object->id()); + return \MongoDBRef::create($object->collection(), $object->id()); } } diff --git a/src/Morph/Compare/NumericProperty.php b/src/morph/compare/NumericProperty.php similarity index 84% rename from src/Morph/Compare/NumericProperty.php rename to src/morph/compare/NumericProperty.php index 3a90a71..ab8ce6d 100644 --- a/src/Morph/Compare/NumericProperty.php +++ b/src/morph/compare/NumericProperty.php @@ -5,14 +5,14 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\compare; /** * Numeric comparator for Morph_Objects * * @package Morph * @subpackage Compare */ -class Morph_Compare_NumericProperty implements Morph_ICompare +class NumericProperty implements \morph\ICompare { /** @@ -28,7 +28,7 @@ class Morph_Compare_NumericProperty implements Morph_ICompare */ public function __construct($propertyName) { - $this->FieldName = $propertyName; + $this->fieldName = $propertyName; } /** @@ -38,7 +38,7 @@ public function __construct($propertyName) * @param Morph_Object $objectB * @return integer */ - public function compare(Morph_Object $objectA, Morph_Object $objectB) + public function compare(\morph\Object $objectA, \morph\Object $objectB) { $compare = null; $propertyA = (float)$objectA->{$this->propertyName}; diff --git a/src/Morph/Compare/Property.php b/src/morph/compare/Property.php similarity index 87% rename from src/Morph/Compare/Property.php rename to src/morph/compare/Property.php index c32d872..deac613 100644 --- a/src/Morph/Compare/Property.php +++ b/src/morph/compare/Property.php @@ -5,14 +5,14 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\compare; /** * Comparator for Morph_Object * * @package Morph * @subpackage Compare */ -class Morph_Compare_Property implements Morph_ICompare +class Property implements \morph\ICompare { /** @@ -38,7 +38,7 @@ public function __construct($propertyName) * @param Morph_Object $objectB * @return integer */ - public function compare(Morph_Object $objectA, Morph_Object $objectB) + public function compare(\morph\Object $objectA, \morph\Object $objectB) { $compare = null; if ($objectA->{$this->propertyName} == $objectB->{$this->propertyName}){ diff --git a/src/Morph/Exception/ObjectNotFound.php b/src/morph/exception/ObjectNotFound.php similarity index 77% rename from src/Morph/Exception/ObjectNotFound.php rename to src/morph/exception/ObjectNotFound.php index c381087..b994e69 100644 --- a/src/Morph/Exception/ObjectNotFound.php +++ b/src/morph/exception/ObjectNotFound.php @@ -5,14 +5,14 @@ * @version SVN: $Id$ * @author Jonathan Moss */ - +namespace morph\exception; /** * thrown when a requested object could not be found * * @package Morph * @subpackage Exception */ -class Morph_Exception_ObjectNotFound extends RuntimeException +class ObjectNotFound extends \RuntimeException { } \ No newline at end of file diff --git a/src/Morph/Property/Boolean.php b/src/morph/property/Boolean.php similarity index 74% rename from src/Morph/Property/Boolean.php rename to src/morph/property/Boolean.php index 1abf026..6062cc3 100644 --- a/src/Morph/Property/Boolean.php +++ b/src/morph/property/Boolean.php @@ -5,34 +5,21 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * Class to represent an boolean property * * @package Morph * @subpackage Property */ -class Morph_Property_Boolean extends Morph_Property_Generic +class Boolean extends Generic { - - /** - * The minimum allowed value - * @var integer - */ - protected $Minimum; - - /** - * The maximum allowed value - * @var integer - */ - protected $Maximum; - /** * @param string $name * @param boolean $default */ public function __construct($name, $default = null){ - if (!is_null($default)) { + if (!\is_null($default)) { $default = (boolean)$default; } parent::__construct($name, $default); diff --git a/src/Morph/Property/ComposeMany.php b/src/morph/property/ComposeMany.php similarity index 73% rename from src/Morph/Property/ComposeMany.php rename to src/morph/property/ComposeMany.php index 3c15c18..5bbbc04 100644 --- a/src/Morph/Property/ComposeMany.php +++ b/src/morph/property/ComposeMany.php @@ -5,7 +5,7 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * Allows a Morph_Object to compose many Morph_Objects * @@ -16,14 +16,14 @@ * @package Morph * @subpackage Property */ -class Morph_Property_ComposeMany extends Morph_Property_Generic +class ComposeMany extends Generic { /** * Holds the name of the class this property should contain * @var string */ - protected $Type; + protected $type; /** @@ -32,8 +32,8 @@ class Morph_Property_ComposeMany extends Morph_Property_Generic */ public function __construct($name, $type) { - $this->Type = $type; - $default = new Morph_Collection(); + $this->type = $type; + $default = new \morph\Collection(); $default->setPermissableType($type); parent::__construct($name, $default); } @@ -44,20 +44,20 @@ public function __construct($name, $type) */ public function getValue() { - return $this->Value; + return $this->value; } /** * (non-PHPdoc) * @see tao/classes/Morph/property/Morph_Property_Generic#setValue() */ - public function setValue(Morph_Collection $value){ + public function setValue(\morph\Collection $value){ if ($value->count() > 0) { foreach ($value as $object) { $this->isPermissableType($object); } } - $this->Value = $value; + $this->value = $value; } /** @@ -66,15 +66,15 @@ public function setValue(Morph_Collection $value){ */ public function __setRawValue($value) { - $collection = new Morph_Collection(); + $collection = new \morph\collection(); if (count($value) > 0) { foreach ($value as $item) { - $object = new $this->Type; - $object->__setData($item, Morph_Enum::STATE_CLEAN); + $object = new $this->type; + $object->__setData($item, \morph\Enum::STATE_CLEAN); $collection->append($object); } } - $this->Value = $collection; + $this->value = $collection; } /** @@ -84,9 +84,9 @@ public function __setRawValue($value) public function __getRawValue() { $rawValue = array(); - if($this->Value->count() > 0){ + if($this->value->count() > 0){ //$rawValue = $this->Value->getArrayCopy(); - foreach ($this->Value as $value) { + foreach ($this->value as $value) { $rawValue[] = $value->__getData(); } } @@ -100,9 +100,9 @@ public function __getRawValue() */ private function isPermissableType($object) { - if(!($object instanceof $this->Type) && !is_null($object)){ - throw new RuntimeException(get_class($object) . " is not an instance of {$this->Type}"); + if(!($object instanceof $this->type) && !\is_null($object)){ + throw new \RuntimeException(\get_class($object) . " is not an instance of {$this->Type}"); } } -} +} \ No newline at end of file diff --git a/src/Morph/Property/ComposeOne.php b/src/morph/property/ComposeOne.php similarity index 75% rename from src/Morph/Property/ComposeOne.php rename to src/morph/property/ComposeOne.php index 6b66759..a95bbea 100644 --- a/src/Morph/Property/ComposeOne.php +++ b/src/morph/property/ComposeOne.php @@ -5,7 +5,7 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * The property type allows the composition of another Morph_Object * derived class. Objects placed in this kind of property are stored @@ -15,14 +15,14 @@ * @package Morph * @subpackage Property */ -class Morph_Property_ComposeOne extends Morph_Property_Generic +class ComposeOne extends Generic { /** * The class that this property should contain * @var string */ - protected $Type; + protected $type; /** * Creates a property to contain a reference to another Morph_Object @@ -33,7 +33,7 @@ class Morph_Property_ComposeOne extends Morph_Property_Generic */ public function __construct($name, $type) { - $this->Type = $type; + $this->type = $type; parent::__construct($name); } @@ -43,7 +43,7 @@ public function __construct($name, $type) */ public function getValue() { - return $this->Value; + return $this->value; } /** @@ -52,7 +52,7 @@ public function getValue() */ public function setValue($value){ $this->isPermissableType($value); - $this->Value = $value; + $this->value = $value; } /** @@ -61,8 +61,8 @@ public function setValue($value){ */ public function __setRawValue($value) { - $this->Value = new $this->Type; - $this->Value->__setData($value, Morph_Enum::STATE_CLEAN); + $this->value = new $this->type; + $this->value->__setData($value, \morph\Enum::STATE_CLEAN); } /** @@ -72,8 +72,8 @@ public function __setRawValue($value) public function __getRawValue() { $rawValue = null; - if(isset($this->Value)){ - $rawValue = $this->Value->__getData(); + if(isset($this->value)){ + $rawValue = $this->value->__getData(); } return $rawValue; } @@ -85,8 +85,8 @@ public function __getRawValue() */ private function isPermissableType($object) { - if(!($object instanceof $this->Type) && !is_null($object)){ - throw new RuntimeException(get_class($object) . " is not an instance of {$this->Type}"); + if(!($object instanceof $this->type) && !\is_null($object)){ + throw new \RuntimeException(\get_class($object) . " is not an instance of {$this->type}"); } } @@ -96,7 +96,7 @@ private function isPermissableType($object) */ public function __toString() { - return $this->getName() . ": " . json_encode($this->__getRawValue()); + return $this->getName() . ": " . \json_encode($this->__getRawValue()); } } diff --git a/src/Morph/Property/Date.php b/src/morph/property/Date.php similarity index 61% rename from src/Morph/Property/Date.php rename to src/morph/property/Date.php index 81105f7..bcb0bac 100644 --- a/src/Morph/Property/Date.php +++ b/src/morph/property/Date.php @@ -6,7 +6,7 @@ * @copyright 2009 Jonathan Moss * @version SVN: $Id$ */ - +namespace morph\property; /** * Short summary of class * @@ -15,22 +15,9 @@ * @package Morph * @subpackage Property */ -class Morph_Property_Date extends Morph_Property_Generic +class Date extends Generic { - - /** - * - * @param string $name - * @param mixed $default - * @return Morph_Property_Date - */ - public function __construct($name, $default = null) - { - $this->Name = $name; - $this->Value = $default; - } - /** * Returns the date associated with this property as a timestamp * @@ -38,7 +25,7 @@ public function __construct($name, $default = null) */ public function getValue() { - return $this->Value; + return $this->value; } /** @@ -50,9 +37,9 @@ public function getValue() public function setValue($value) { if (isset($value)) { - $this->Value = (int)$value; + $this->value = (int)$value; } else { - $this->Value = null; + $this->value = null; } } @@ -63,8 +50,8 @@ public function setValue($value) */ public function __getRawValue() { - if (! isset($this->Value)) return null; - $rawValue = new MongoDate($this->Value); + if (! isset($this->value)) return null; + $rawValue = new \MongoDate($this->value); return $rawValue; } @@ -76,16 +63,15 @@ public function __getRawValue() */ public function __setRawValue($value) { - if ($value instanceof MongoDate) { - $this->Value = (int) $value->sec; + if ($value instanceof \MongoDate) { + $this->value = (int) $value->sec; } else { if (isset($value)) { - $this->Value = (int) $value; + $this->value = (int) $value; } else { - $this->Value = null; + $this->value = null; } } - return $this; } diff --git a/src/Morph/Property/Enum.php b/src/morph/property/Enum.php similarity index 74% rename from src/Morph/Property/Enum.php rename to src/morph/property/Enum.php index c294bff..4f50c38 100644 --- a/src/Morph/Property/Enum.php +++ b/src/morph/property/Enum.php @@ -5,21 +5,21 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * Field object to represent an Enum property * * @package Morph * @subpackage Property */ -class Morph_Property_Enum extends Morph_Property_Generic +class Enum extends Generic { /** * An array containing permitted values * @var array */ - private $Enums; + private $choices; /** * @@ -28,9 +28,9 @@ class Morph_Property_Enum extends Morph_Property_Generic * @param array $enums An array of valid enum values * @return ar_Property_Enum */ - public function __construct($name, $default, array $enums) + public function __construct($name, $default, array $choices) { - $this->Enums = $enums; + $this->choices = $choices; parent::__construct($name, $default); } @@ -41,7 +41,7 @@ public function __construct($name, $default, array $enums) */ public function setValue($value) { - if($this->isValidEnum($value)){ + if($this->isValidChoice($value)){ parent::setValue($value); } } @@ -51,9 +51,9 @@ public function setValue($value) * * @return array */ - public function getEnums() + public function getChoices() { - return $this->Enums; + return $this->choices; } /** @@ -61,10 +61,10 @@ public function getEnums() * @param $value * @return boolean */ - private function isValidEnum($value) + private function isValidChoice($value) { $isValidEnum = false; - if(in_array($value, $this->Enums)){ + if(in_array($value, $this->getChoices())){ $isValidEnum = true; } return $isValidEnum; diff --git a/src/Morph/Property/File.php b/src/morph/property/File.php similarity index 63% rename from src/Morph/Property/File.php rename to src/morph/property/File.php index 711e177..1668ba1 100644 --- a/src/Morph/Property/File.php +++ b/src/morph/property/File.php @@ -5,7 +5,7 @@ * @author Jonathan Moss FilePath = realpath($value); - unset($this->Value); + if (\file_exists($value)) { + $this->filePath = \realpath($value); + unset($this->value); } else { - throw new InvalidArgumentException("The file $value does not exist"); + throw new \InvalidArgumentException("The file $value does not exist"); } return $this; } @@ -69,10 +69,10 @@ public function setValue($value) * @return MongoGridFSFile */ public function getValue(){ - if(!isset($this->Value) && !is_null($this->Reference)){ - $this->Value = Morph_Storage::instance()->fetchFile($this->Reference); + if(!isset($this->value) && !\is_null($this->reference)){ + $this->value = \morph\Storage::instance()->fetchFile($this->reference); } - return $this->Value; + return $this->value; } /** @@ -81,10 +81,10 @@ public function getValue(){ */ public function __getRawValue() { - if (!is_null($this->FilePath)) { - $this->Reference = Morph_Storage::instance()->saveFile($this->FilePath, $this->Reference); + if (!is_null($this->filePath)) { + $this->reference = \morph\Storage::instance()->saveFile($this->filePath, $this->reference); } - return $this->Reference; + return $this->reference; } /** @@ -93,9 +93,9 @@ public function __getRawValue() */ public function __setRawValue($value) { - unset($this->Value); - unset($this->FilePath); - $this->Reference = $value; + unset($this->value); + unset($this->filePath); + $this->reference = $value; } /** @@ -105,10 +105,10 @@ public function __setRawValue($value) public function __toString() { $id = ''; - if (!is_null($this->Reference)) { - $id = $this->Reference; - } elseif (!is_null($this->FilePath)) { - $id = $this->FilePath; + if (!\is_null($this->reference)) { + $id = $this->reference; + } elseif (!\is_null($this->filePath)) { + $id = $this->filePath; } return $this->getName() . ": {File: $id}"; } diff --git a/src/Morph/Property/Float.php b/src/morph/property/Float.php similarity index 68% rename from src/Morph/Property/Float.php rename to src/morph/property/Float.php index 0755f35..3608a2c 100644 --- a/src/Morph/Property/Float.php +++ b/src/morph/property/Float.php @@ -5,27 +5,27 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * Class to represent a float property * * @package Morph * @subpackage Property */ -class Morph_Property_Float extends Morph_Property_Generic +class Float extends Generic { /** * Minimum value * @var float */ - protected $Minimum; + protected $minimum; /** * Maximum value * @var float */ - protected $Maximum; + protected $maximum; /** * @param string $name @@ -35,8 +35,8 @@ class Morph_Property_Float extends Morph_Property_Generic */ public function __construct($name, $default = null, $minimum = null, $maximum = null){ parent::__construct($name, $default); - $this->Minimum = $minimum; - $this->Maximum = $maximum; + $this->minimum = (\is_null($minimum))? null : (float)$minimum; + $this->maximum = (\is_null($maximum))? null : (float)$maximum; } /** @@ -45,14 +45,14 @@ public function __construct($name, $default = null, $minimum = null, $maximum = * @param float $Value */ public function setValue($value){ - $cleanValue = floatval($value); - if(!empty($this->Minimum) && ($cleanValue < $this->Minimum) ){ + $cleanValue = (float)$value; + if(!empty($this->minimum) && ($cleanValue < $this->minimum) ){ //throw validation exception - $cleanValue = $this->Minimum; + $cleanValue = $this->minimum; } - if(!empty($this->Maximum) && ($cleanValue > $this->Maximum) ){ + if(!empty($this->maximum) && ($cleanValue > $this->maximum) ){ //throw validation exception - $cleanValue = $this->Maximum; + $cleanValue = $this->maximum; } parent::setValue($cleanValue); } diff --git a/src/Morph/Property/Generic.php b/src/morph/property/Generic.php similarity index 88% rename from src/Morph/Property/Generic.php rename to src/morph/property/Generic.php index 132af29..006d907 100644 --- a/src/Morph/Property/Generic.php +++ b/src/morph/property/Generic.php @@ -5,7 +5,7 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * Class to represent a property within a table * @@ -18,20 +18,20 @@ * @package Morph * @subpackage Property */ -class Morph_Property_Generic +class Generic { /** * The name of this property * @var string */ - protected $Name; + protected $name; /** * The current value of this property * @var mixed */ - protected $Value; + protected $value; /** * @@ -41,8 +41,8 @@ class Morph_Property_Generic */ public function __construct($name, $default = null) { - $this->Name = $name; - $this->Value = $default; + $this->name = $name; + $this->value = $default; } /** @@ -73,7 +73,7 @@ public function setValue($value) */ public function __getRawValue() { - return $this->Value; + return $this->value; } /** @@ -85,7 +85,7 @@ public function __getRawValue() */ public function __setRawValue($value) { - $this->Value = $value; + $this->value = $value; return $this; } @@ -95,7 +95,7 @@ public function __setRawValue($value) */ public final function getName() { - return $this->Name; + return $this->name; } /** diff --git a/src/Morph/Property/HasMany.php b/src/morph/property/HasMany.php similarity index 62% rename from src/Morph/Property/HasMany.php rename to src/morph/property/HasMany.php index 3118dfe..d172e02 100644 --- a/src/Morph/Property/HasMany.php +++ b/src/morph/property/HasMany.php @@ -5,7 +5,7 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * This property type represents a collection of many Morph_Objects. * @@ -15,23 +15,23 @@ * @package Morph * @subpackage Property */ -class Morph_Property_HasMany extends Morph_Property_Generic +class HasMany extends Generic { /** * @var boolean */ - protected $Loaded = false; + protected $loaded = false; /** * @var String */ - protected $Type; + protected $type; /** * @var array */ - protected $References; + protected $references; /** @@ -42,8 +42,8 @@ class Morph_Property_HasMany extends Morph_Property_Generic */ public function __construct($name, $type) { - $this->Type = $type; - $default = new Morph_Collection(); + $this->type = $type; + $default = new \morph\Collection(); $default->setPermissableType($type); parent::__construct($name, $default); } @@ -54,7 +54,7 @@ public function __construct($name, $type) */ public function __setRawValue($value) { - $this->References = $value; + $this->references = $value; } /** @@ -63,17 +63,17 @@ public function __setRawValue($value) */ public function __getRawValue() { - if(count($this->Value) > 0){ + if(count($this->value) > 0){ $refs = array(); - foreach ($this->Value as $object){ - if($object->state() != Morph_Enum::STATE_CLEAN){ - Morph_Storage::instance()->save($object); + foreach ($this->value as $object){ + if($object->state() != \morph\enum::STATE_CLEAN){ + \morph\Storage::instance()->save($object); } - $refs[] = Morph_Utils::objectReference($object); + $refs[] = \morph\Utils::objectReference($object); } - $this->References = $refs; + $this->references = $refs; } - return $this->References; + return $this->references; } /** @@ -82,10 +82,10 @@ public function __getRawValue() */ public function getValue() { - if($this->Loaded === false){ + if($this->loaded === false){ $this->loadFromReferences(); } - return $this->Value; + return $this->value; } /** @@ -94,9 +94,9 @@ public function getValue() */ public function setValue($value) { - if($value instanceof Morph_Collection){ - $this->Value = $value; - $this->References = array(); + if($value instanceof \morph\Collection) { + $this->value = $value; + $this->references = array(); } } @@ -108,21 +108,21 @@ public function setValue($value) private function loadFromReferences() { $ids = array(); - if (count($this->References) > 0) { - foreach ($this->References as $reference){ + if (count($this->references) > 0) { + foreach ($this->references as $reference){ $ids[] = $reference['$id']; } - $query = new Morph_Query(); + $query = new \morph\Query(); $query->property('_id')->in($ids); - $object = new $this->Type; + $object = new $this->type; //@todo this could get nasty with large collections! - $this->Value = Morph_Storage::instance()->findByQuery($object, $query)->toCollection(); + $this->value = \morph\Storage::instance()->findByQuery($object, $query)->toCollection(); } else { - $this->Value = new Morph_Collection(); + $this->value = new \morph\Collection(); } - $this->Loaded = true; + $this->loaded = true; } } diff --git a/src/Morph/Property/HasOne.php b/src/morph/property/HasOne.php similarity index 61% rename from src/Morph/Property/HasOne.php rename to src/morph/property/HasOne.php index a1eefea..f872c4b 100644 --- a/src/Morph/Property/HasOne.php +++ b/src/morph/property/HasOne.php @@ -5,7 +5,7 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * Class to represent a related object * @@ -16,26 +16,26 @@ * @subpackage Property */ -class Morph_Property_HasOne extends Morph_Property_Generic +class HasOne extends Generic { /** * * @var Morph_Object */ - protected $Value; + protected $value; /** * Contains the reference details for this object * @var array */ - protected $Reference; + protected $reference; /** * The class that this object should hold * @var string */ - protected $Type; + protected $type; /** * @@ -44,9 +44,9 @@ class Morph_Property_HasOne extends Morph_Property_Generic * @param $default * @return Morph_Property_hasOne */ - public function __construct($name, $type, Morph_Object $default = null) + public function __construct($name, $type, \morph\Object $default = null) { - $this->Type = $type; + $this->type = $type; $this->isPermissableType($default); parent::__construct($name, $default); } @@ -59,7 +59,7 @@ public function __construct($name, $type, Morph_Object $default = null) public function setValue($value) { $this->isPermissableType($value); - $this->Value = $value; + $this->value = $value; return $this; } @@ -68,11 +68,11 @@ public function setValue($value) * @see tao/classes/Morph/property/Morph_Property_Generic#getValue() */ public function getValue(){ - if(is_null($this->Value) && !is_null($this->Reference)){ - $this->Value = new $this->Type; - $this->Value = Morph_Storage::instance()->fetchByDbRef($this->Value, $this->Reference); + if(\is_null($this->value) && !\is_null($this->reference)) { + $this->value = new $this->type; + $this->value = \morph\Storage::instance()->fetchByDbRef($this->value, $this->reference); } - return $this->Value; + return $this->value; } /** @@ -81,14 +81,14 @@ public function getValue(){ */ public function __getRawValue() { - if(!is_null($this->Value) && is_null($this->Reference)){ - if($this->Value->state() != Morph_Enum::STATE_CLEAN){ + if(!is_null($this->value) && \is_null($this->reference)) { + if($this->value->state() != \morph\Enum::STATE_CLEAN) { //save value - Morph_Storage::instance()->save($this->Value); + \morph\Storage::instance()->save($this->value); } - $this->Reference = Morph_Utils::objectReference($this->Value); + $this->reference = \morph\Utils::objectReference($this->value); } - return $this->Reference; + return $this->reference; } /** @@ -97,7 +97,7 @@ public function __getRawValue() */ public function __setRawValue($value) { - $this->Reference = $value; + $this->reference = $value; } /** @@ -107,8 +107,8 @@ public function __setRawValue($value) */ private function isPermissableType($object) { - if(!($object instanceof $this->Type) && !is_null($object)){ - throw new RuntimeException(get_class($object) . " is not an instance of {$this->Type}"); + if(!($object instanceof $this->type) && !\is_null($object)){ + throw new \RuntimeException(\get_class($object) . " is not an instance of {$this->type}"); } } @@ -119,11 +119,11 @@ private function isPermissableType($object) public function __toString() { $id = ''; - if(isset($this->Value)){ - $id = $this->Value->id(); - }elseif(isset($this->Reference)){ - $id = $this->Reference['$id']; + if(isset($this->value)){ + $id = $this->value->id(); + }elseif(isset($this->reference)){ + $id = $this->reference['$id']; } - return $this->getName() . ": {" . $this->Type . ": $id}"; + return $this->getName() . ": {" . $this->type . ": $id}"; } -} +} \ No newline at end of file diff --git a/src/Morph/Property/Integer.php b/src/morph/property/Integer.php similarity index 68% rename from src/Morph/Property/Integer.php rename to src/morph/property/Integer.php index e58abb0..7c31819 100644 --- a/src/Morph/Property/Integer.php +++ b/src/morph/property/Integer.php @@ -5,27 +5,27 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * Class to represent an integer property * * @package Morph * @subpackage Property */ -class Morph_Property_Integer extends Morph_Property_Generic +class Integer extends Generic { /** * The minimum allowed value * @var integer */ - protected $Minimum; + protected $minimum; /** * The maximum allowed value * @var integer */ - protected $Maximum; + protected $maximum; /** * @param string $Name @@ -35,8 +35,8 @@ class Morph_Property_Integer extends Morph_Property_Generic */ public function __construct($name, $default = null, $minimum = null, $maximum = null){ parent::__construct($name, $default); - $this->Minimum = $minimum; - $this->Maximum = $maximum; + $this->minimum = (\is_null($minimum))? null : (int)$minimum; + $this->maximum = (\is_null($maximum))? null : (int)$maximum; } /** @@ -45,14 +45,14 @@ public function __construct($name, $default = null, $minimum = null, $maximum = * @param integer $Value */ public function setValue($value){ - $cleanValue = intval($value); - if(!empty($this->Minimum) && ($cleanValue < $this->Minimum) ){ + $cleanValue = (int)$value; + if(!empty($this->minimum) && ($cleanValue < $this->minimum) ){ //throw validation exception - $cleanValue = $this->Minimum; + $cleanValue = $this->minimum; } - if(!empty($this->Maximum) && ($cleanValue > $this->Maximum) ){ + if(!empty($this->maximum) && ($cleanValue > $this->maximum) ){ //throw validation exception - $cleanValue = $this->Maximum; + $cleanValue = $this->maximum; } parent::setValue($cleanValue); } diff --git a/src/Morph/Property/String.php b/src/morph/property/String.php similarity index 69% rename from src/Morph/Property/String.php rename to src/morph/property/String.php index 0aa7b98..5af063f 100644 --- a/src/Morph/Property/String.php +++ b/src/morph/property/String.php @@ -5,21 +5,21 @@ * @author Jonathan Moss * @copyright Jonathan Moss 2009 */ - +namespace morph\property; /** * Class to represent a string property * * @package Morph * @subpackage Property */ -class Morph_Property_String extends Morph_Property_Generic +class String extends Generic { /** * The maximum string length permitted * @var integer */ - protected $MaximumLength; + protected $maximumLength; /** * @param string $Name @@ -28,7 +28,7 @@ class Morph_Property_String extends Morph_Property_Generic */ public function __construct($name, $default = null, $maximumLength = null){ parent::__construct($name, $default); - $this->MaximumLength = $maximumLength; + $this->maximumLength = (\is_null($maximumLength)) ? null : (int)$maximumLength; } /** @@ -37,10 +37,10 @@ public function __construct($name, $default = null, $maximumLength = null){ * @param integer $Value */ public function setValue($value){ - $cleanValue = strval($value); - if(!empty($this->MaximumLength) && (strlen($cleanValue) > $this->MaximumLength) ){ + $cleanValue = (string)$value; + if(!empty($this->maximumLength) && (strlen($cleanValue) > $this->maximumLength) ){ //throw validation exception - $cleanValue = substr($cleanValue,0,$this->MaximumLength); + $cleanValue = substr($cleanValue, 0, $this->maximumLength); } parent::setValue($cleanValue); } @@ -48,7 +48,7 @@ public function setValue($value){ /** * Returns this attributes value * - * @return integer + * @return string */ public function getValue(){ return (string)parent::getValue(); diff --git a/src/Morph/Query/Property.php b/src/morph/query/Property.php similarity index 90% rename from src/Morph/Query/Property.php rename to src/morph/query/Property.php index 40a559f..54cd7cf 100644 --- a/src/Morph/Query/Property.php +++ b/src/morph/query/Property.php @@ -6,7 +6,7 @@ * @copyright 2009 Jonathan Moss * @version SVN: $Id$ */ - +namespace morph\query; /** * Represents a series of constraints to be applied to a property when querying * @@ -14,7 +14,7 @@ * @package Morph * @subpackage Query */ -class Morph_Query_Property implements Morph_IQuery +class Property implements \morph\IQuery { /** @@ -55,7 +55,7 @@ class Morph_Query_Property implements Morph_IQuery * @param $query * @return Morph_Query_Property */ - public function __construct(Morph_Query $query) + public function __construct(\morph\Query $query) { $this->query = $query; $this->constraints = array(); @@ -121,7 +121,7 @@ public function getSkip() */ public function getLimit() { - return $this->getLimit(); + return $this->query->getLimit(); } ////////////////////////// @@ -249,7 +249,7 @@ public function all(array $value) */ public function regex($regex) { - $this->setSingularConstraint(new MongoRegex($regex)); + $this->setSingularConstraint(new \MongoRegex($regex)); return $this; } @@ -305,17 +305,17 @@ public function exists($exists = true) * @param $direction * @return Morph_Query_Property */ - public function sort($direction = Morph_Enum::DIRECTION_ASC) + public function sort($direction = \morph\Enum::DIRECTION_ASC) { switch ($direction) { - case Morph_Enum::DIRECTION_ASC: - $this->sortDirection = Morph_Enum::DIRECTION_ASC; + case \morph\Enum::DIRECTION_ASC: + $this->sortDirection = \morph\Enum::DIRECTION_ASC; break; - case Morph_Enum::DIRECTION_DESC: - $this->sortDirection = Morph_Enum::DIRECTION_DESC; + case \morph\Enum::DIRECTION_DESC: + $this->sortDirection = \morph\Enum::DIRECTION_DESC; break; default: - throw new InvalidArgumentException("Sort direction should be -1 or 1"); + throw new \InvalidArgumentException("Sort direction should be -1 or 1"); } return $this; } @@ -357,7 +357,7 @@ private function addCompoundConstraint($type, $value) if ($this->isPermitted(self::MODE_COMPOUND)) { $this->constraints[$type] = $value; } else { - throw new RuntimeException("You cannot use a a property in both compound and singular modes"); + throw new \RuntimeException("You cannot use a a property in both compound and singular modes"); } } @@ -373,7 +373,7 @@ private function setSingularConstraint($value) if ($this->isPermitted(self::MODE_SINGULAR)) { $this->constraints = $value; } else { - throw new RuntimeException("You cannot use a a property in both compound and singular modes"); + throw new \RuntimeException("You cannot use a a property in both compound and singular modes"); } } diff --git a/unit-tests/ForTesting.php b/unit-tests/ForTesting.php index 5666b9d..cdd3763 100644 --- a/unit-tests/ForTesting.php +++ b/unit-tests/ForTesting.php @@ -5,7 +5,7 @@ * @copyright 2009 Jonathan Moss * @version SVN: $Id$ */ - +namespace morph; /** * Short summary of class * @@ -13,14 +13,13 @@ * * @package Morph */ -class Morph_ForTesting extends Morph_Object +class ForTesting extends Object { public function __construct($id = null) { parent::__construct($id); - $this->addProperty(new Morph_Property_Generic('TestField')); + $this->addProperty(new \morph\property\Generic('testField')); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/unit-tests/TestObject.php b/unit-tests/TestObject.php index b1bca7d..1a96a2f 100644 --- a/unit-tests/TestObject.php +++ b/unit-tests/TestObject.php @@ -1,29 +1,29 @@ assertEquals('Morph.ForTesting', $obj->collection()); + $obj = new ForTesting(); + $this->assertEquals('morph.ForTesting', $obj->collection()); } public function testCollectionOverride() { - $obj = new Morph_ForTesting(); + $obj = new ForTesting(); $collectionName = "TestCollection"; $obj->collection($collectionName); $this->assertEquals($collectionName, $obj->collection()); @@ -32,50 +32,50 @@ public function testCollectionOverride() public function testMagicGettersSetter() { $testValue = 'TestValue'; - $obj = new Morph_ForTesting(); - $obj->TestField = $testValue; - $this->assertEquals($testValue, $obj->TestField); + $obj = new ForTesting(); + $obj->testField = $testValue; + $this->assertEquals($testValue, $obj->testField); } public function testSetData() { - $data = array('TestField' => 'value1'); - $obj = new Morph_ForTesting(); + $data = array('testField' => 'value1'); + $obj = new ForTesting(); $obj->__setData($data); - $this->assertEquals($data['TestField'], $obj->TestField); - $this->assertEquals(Morph_Enum::STATE_DIRTY, $obj->state()); + $this->assertEquals($data['testField'], $obj->testField); + $this->assertEquals(Enum::STATE_DIRTY, $obj->state()); } public function testGetData() { $data = array( - '_ns' => 'Morph_ForTesting', - 'TestField' => 'value1', + '_ns' => 'morph\ForTesting', + 'testField' => 'value1', 'instanceOf' => 'Morph_ForTesting' ); - $obj = new Morph_ForTesting(); + $obj = new ForTesting(); $obj->__setData($data); $this->assertEquals($data, $obj->__getData()); - $this->assertEquals(Morph_Enum::STATE_DIRTY, $obj->state()); + $this->assertEquals(Enum::STATE_DIRTY, $obj->state()); } public function test__toArray() { $testValue = 'TestValue'; $expectedArray = array( - 'TestField' => 'TestValue' + 'testField' => 'TestValue' ); - $obj = new Morph_ForTesting(); - $obj->TestField = $testValue; + $obj = new ForTesting(); + $obj->testField = $testValue; $this->assertEquals($expectedArray, $obj->__toArray()); } public function test__toString() { - $expected = "Id: \nState: New\nTestField: TEST\n"; - $obj = new Morph_ForTesting(); - $obj->TestField = 'TEST'; + $expected = "Id: \nState: New\ntestField: TEST\n"; + $obj = new ForTesting(); + $obj->testField = 'TEST'; $this->assertEquals($expected, $obj->__toString()); } diff --git a/unit-tests/TestPropertySet.php b/unit-tests/TestPropertySet.php index 24c4683..b549a95 100644 --- a/unit-tests/TestPropertySet.php +++ b/unit-tests/TestPropertySet.php @@ -5,19 +5,19 @@ * @copyright 2009 Jonathan Moss * @version SVN: $Id$ */ -require_once 'PHPUnit/Framework/TestCase.php'; -require_once dirname(__FILE__).'/../src/Morph/Property/Generic.php'; -require_once dirname(__FILE__).'/../src/Morph/PropertySet.php'; +namespace morph; +require_once dirname(__FILE__).'/../src/morph/property/Generic.php'; +require_once dirname(__FILE__).'/../src/morph/PropertySet.php'; /** * * @package Morph */ -class TestPropertySet extends PHPUnit_Framework_TestCase +class TestPropertySet extends \PHPUnit_Framework_TestCase { public function testAddingProperty() { - $propertySet = new Morph_PropertySet(); + $propertySet = new PropertySet(); $property = $this->getMockProperty(); $propertySet['AProperty'] = $property; $this->assertContains($property, $propertySet->getArrayCopy()); @@ -25,7 +25,7 @@ public function testAddingProperty() public function testAddingInvalidValue() { - $propertySet = new Morph_PropertySet(); + $propertySet = new PropertySet(); $property = "I'm just wrong"; $this->setExpectedException('InvalidArgumentException'); $propertySet['AProperty'] = $property; @@ -33,7 +33,7 @@ public function testAddingInvalidValue() public function testAddingUnnamedProperty() { - $propertySet = new Morph_PropertySet(); + $propertySet = new PropertySet(); $property = $this->getMockProperty(); $this->setExpectedException('RuntimeException'); $propertySet[] = $property; @@ -41,7 +41,7 @@ public function testAddingUnnamedProperty() public function testAppendProperty() { - $propertySet = new Morph_PropertySet(); + $propertySet = new PropertySet(); $property = $this->getMockProperty(); $this->setExpectedException('RuntimeException'); $propertySet->append($property); @@ -49,7 +49,7 @@ public function testAppendProperty() public function testAddingMultipleProperties() { - $propertySet = new Morph_PropertySet(); + $propertySet = new PropertySet(); $property1 = $this->getMockProperty(); $property2 = $this->getMockProperty(); $property = $this->getMockProperty(); @@ -62,7 +62,7 @@ public function testAddingMultipleProperties() public function testGetPropertyValue() { $expected = 'AValue'; - $propertySet = new Morph_PropertySet(); + $propertySet = new PropertySet(); $propertySet['P1'] = $this->getMockPropertyForGet($expected); $this->assertEquals($expected, $propertySet->getPropertyValue('P1')); } @@ -70,7 +70,7 @@ public function testGetPropertyValue() public function testSetPropertyValue() { $expected = 'AValue'; - $propertySet = new Morph_PropertySet(); + $propertySet = new PropertySet(); $propertySet['P1'] = $this->getMockPropertyForSet($expected); $propertySet->setPropertyValue('P1', $expected); } @@ -78,7 +78,7 @@ public function testSetPropertyValue() public function testGetRawPropertyValue() { $expected = 'AValue'; - $propertySet = new Morph_PropertySet(); + $propertySet = new PropertySet(); $propertySet['P1'] = $this->getMockPropertyFor__RawGet($expected); $this->assertEquals($expected, $propertySet->__getRawPropertyValue('P1')); } @@ -86,7 +86,7 @@ public function testGetRawPropertyValue() public function testSetRawPropertyValue() { $expected = 'AValue'; - $propertySet = new Morph_PropertySet(); + $propertySet = new PropertySet(); $propertySet['P1'] = $this->getMockPropertyFor__RawSet($expected); $propertySet->__setRawPropertyValue('P1', $expected); } @@ -95,12 +95,12 @@ public function testSetRawPropertyValue() private function getMockProperty() { - return $this->getMock('Morph_Property_Generic', array(), array('name')); + return $this->getMock('\morph\property\Generic', array(), array('name')); } private function getMockPropertyForGet($value) { - $property = $this->getMock('Morph_Property_Generic', array('getValue'), array('name')); + $property = $this->getMock('\morph\property\Generic', array('getValue'), array('name')); $property->expects($this->once()) ->method('getValue') ->will($this->returnValue($value)); @@ -109,7 +109,7 @@ private function getMockPropertyForGet($value) private function getMockPropertyForSet($value) { - $property = $this->getMock('Morph_Property_Generic', array('setValue'), array('name')); + $property = $this->getMock('\morph\property\Generic', array('setValue'), array('name')); $property->expects($this->once()) ->method('setValue') ->with($this->equalTo($value)); @@ -118,16 +118,16 @@ private function getMockPropertyForSet($value) private function getMockPropertyForSetStorage() { - $property = $this->getMock('Morph_Property_Generic', array('setStorage'), array('name')); + $property = $this->getMock('\morph\property\Generic', array('setStorage'), array('name')); $property->expects($this->once()) ->method('setStorage') - ->with($this->isInstanceOf('Morph_Storage')); + ->with($this->isInstanceOf('\morph\Storage')); return $property; } private function getMockPropertyFor__RawGet($value) { - $property = $this->getMock('Morph_Property_Generic', array('__getRawValue'), array('name')); + $property = $this->getMock('\morph\property\Generic', array('__getRawValue'), array('name')); $property->expects($this->once()) ->method('__getRawValue') ->will($this->returnValue($value)); @@ -136,7 +136,7 @@ private function getMockPropertyFor__RawGet($value) private function getMockPropertyFor__RawSet($value) { - $property = $this->getMock('Morph_Property_Generic', array('__setRawValue'), array('name')); + $property = $this->getMock('\morph\property\Generic', array('__setRawValue'), array('name')); $property->expects($this->once()) ->method('__setRawValue') ->with($this->equalTo($value)); diff --git a/unit-tests/TestQuery.php b/unit-tests/TestQuery.php index 2510ad0..080ca72 100644 --- a/unit-tests/TestQuery.php +++ b/unit-tests/TestQuery.php @@ -5,29 +5,29 @@ * @copyright 2009 Jonathan Moss * @version SVN: $Id$ */ -require_once 'PHPUnit/Framework/TestCase.php'; +namespace morph; -require_once dirname(__FILE__).'/../src/Morph/Enum.php'; -require_once dirname(__FILE__).'/../src/Morph/IQuery.php'; -require_once dirname(__FILE__).'/../src/Morph/Query/Property.php'; -require_once dirname(__FILE__).'/../src/Morph/Query.php'; +require_once dirname(__FILE__).'/../src/morph/Enum.php'; +require_once dirname(__FILE__).'/../src/morph/IQuery.php'; +require_once dirname(__FILE__).'/../src/morph/query/Property.php'; +require_once dirname(__FILE__).'/../src/morph/Query.php'; /** * @package Morph */ -class TestQuery extends PHPUnit_Framework_TestCase +class TestQuery extends \PHPUnit_Framework_TestCase { public function testLimit() { - $query = new Morph_Query(); + $query = new Query(); $query->limit(10); $this->assertEquals(10, $query->getLimit()); } public function testSkip() { - $query = new Morph_Query(); + $query = new Query(); $query->skip(10); $this->assertEquals(10, $query->getSkip()); } @@ -35,7 +35,7 @@ public function testSkip() public function testProperty() { $expected = array('bob' => 'hoskins'); - $query = new Morph_Query(); + $query = new Query(); $query->property('bob')->equals('hoskins'); $this->assertEquals($expected, $query->getRawQuery()); @@ -44,8 +44,8 @@ public function testProperty() public function testFluent() { $expected = array('bob' => 'hoskins'); - $query = new Morph_Query(); - $query->property('bob') + $query = Query::instance() + ->property('bob') ->equals('hoskins'); $this->assertEquals($expected, $query->getRawQuery()); } @@ -53,8 +53,8 @@ public function testFluent() public function testMultipleProperties() { $expected = array('bob' => 'hoskins', 'abc' => 12); - $query = new Morph_Query(); - $query->property('bob') + $query = Query::instance() + ->property('bob') ->equals('hoskins') ->property('abc') ->equals(12); @@ -64,8 +64,8 @@ public function testMultipleProperties() public function testFullFluency() { $expected = array('bob' => 'hoskins', 'abc' => 12); - $query = new Morph_Query(); - $query->limit(10)->skip(12) + $query = Query::instance() + ->limit(10)->skip(12) ->property('bob') ->equals('hoskins') ->sort(1) @@ -76,5 +76,4 @@ public function testFullFluency() $this->assertEquals(12, $query->getSkip()); $this->assertEquals(array('bob'=>1), $query->getRawSort()); } -} -?> \ No newline at end of file +} \ No newline at end of file diff --git a/unit-tests/TestUtils.php b/unit-tests/TestUtils.php index 8cb867f..8167af3 100644 --- a/unit-tests/TestUtils.php +++ b/unit-tests/TestUtils.php @@ -1,41 +1,33 @@ getMock('Morph_Object', array(), array(), 'user_Profile'); - $collectionName = Morph_Utils::collectionName($object); - $this->assertEquals('user.Profile', $collectionName); - } - - public function testNamespacedCollectionName() - { - if (version_compare(PHP_VERSION, '5.3.0') === -1) { - $this->markTestSkipped("Skipped for PHP Versions lower than 5.3.0"); - return; - } - $mockMorphObject = $this->getMock('Morph_Object'); - require dirname(__FILE__) . '/namespaced_stub.php'; - $object = new user\Profile(); - $collectionName = Morph_Utils::collectionName($object); - $this->assertEquals('user.Profile', $collectionName); + $object = $this->getMock('\morph\Object', array(), array()); + $className = str_replace("_", ".", \get_class($object)); + $collectionName = Utils::collectionName($object); + $this->assertEquals($className, $collectionName); } public function testObjectReference() { - $object = $this->getMock('Morph_Object', array('id', 'collection')); + $object = $this->getMock('\morph\Object', array('id', 'collection')); $object->expects($this->once()) ->method('id') ->will($this->returnValue('anId')); $object->expects($this->once()) ->method('collection') ->will($this->returnValue('aCollection')); - $ref = Morph_Utils::objectReference($object); + $ref = Utils::objectReference($object); $expectedArray = array( '$ref' => 'aCollection', '$id' => 'anId' diff --git a/unit-tests/UnitTests.php b/unit-tests/UnitTests.php index 6197ca0..78f4b96 100644 --- a/unit-tests/UnitTests.php +++ b/unit-tests/UnitTests.php @@ -2,8 +2,8 @@ require_once dirname(__FILE__).'/TestPropertySet.php'; require_once dirname(__FILE__).'/TestUtils.php'; -require_once dirname(__FILE__).'/Property/TestProperties.php'; -require_once dirname(__FILE__).'/Query/TestProperty.php'; +require_once dirname(__FILE__).'/property/TestProperties.php'; +require_once dirname(__FILE__).'/query/TestProperty.php'; require_once dirname(__FILE__).'/TestQuery.php'; require_once dirname(__FILE__).'/TestObject.php'; @@ -12,12 +12,12 @@ class AllTests public static function suite() { $suite = new PHPUnit_Framework_TestSuite(); - $suite->addTestSuite('TestPropertySet'); - $suite->addTestSuite('TestUtils'); - $suite->addTestSuite('TestProperties'); - $suite->addTestSuite('TestProperty'); - $suite->addTestSuite('TestQuery'); - $suite->addTestSuite('TestObject'); + $suite->addTestSuite('\morph\TestPropertySet'); + $suite->addTestSuite('\morph\TestUtils'); + $suite->addTestSuite('\morph\property\TestProperties'); + $suite->addTestSuite('\morph\query\TestProperty'); + $suite->addTestSuite('\morph\TestQuery'); + $suite->addTestSuite('\morph\TestObject'); return $suite; } } diff --git a/unit-tests/namespaced_stub.php b/unit-tests/namespaced_stub.php index 90d57aa..a59dff8 100644 --- a/unit-tests/namespaced_stub.php +++ b/unit-tests/namespaced_stub.php @@ -2,7 +2,7 @@ namespace user; -class Profile extends \Morph_Object +class Profile extends \morph\Object { } \ No newline at end of file diff --git a/unit-tests/Property/TestProperties.php b/unit-tests/property/TestProperties.php similarity index 67% rename from unit-tests/Property/TestProperties.php rename to unit-tests/property/TestProperties.php index 4fb67ce..a1b0b9b 100644 --- a/unit-tests/Property/TestProperties.php +++ b/unit-tests/property/TestProperties.php @@ -1,34 +1,35 @@ assertEquals('TestValue', $property->getValue()); } public function testName() { - $property = new Morph_Property_Generic('TestProperty', 'TestValue'); + $property = new Generic('TestProperty', 'TestValue'); $this->assertEquals('TestProperty', $property->getName()); } public function testValue() { - $property = new Morph_Property_Generic('TestProperty', 'TestValue'); + $property = new generic('TestProperty', 'TestValue'); $property->setValue('AValue'); $this->assertEquals('AValue', $property->getValue()); } @@ -37,7 +38,7 @@ public function testStringProperty() { $validString = 'ABCDEFGHIJKLMNOP'; $invalidString = 'ABCDEFGHIJKLMNOPQR'; - $property = new Morph_Property_String('Name', null, 16); + $property = new String('Name', null, 16); $property->setValue($validString); $this->assertEquals($validString, $property->getValue()); $property->setValue($invalidString); @@ -51,7 +52,7 @@ public function testIntegerProperty() $validInteger = 5; $toLarge = 102; $toSmall = 0; - $property = new Morph_Property_Integer('AProperty', null, $min, $max); + $property = new Integer('AProperty', null, $min, $max); $property->setValue($validInteger); $this->assertEquals($validInteger, $property->getValue()); @@ -70,7 +71,7 @@ public function testFloatProperty() $validFloat = 5.0; $toLarge = 100.1; $toSmall = 0.1; - $property = new Morph_Property_Float('AProperty', null, $min, $max); + $property = new Float('AProperty', null, $min, $max); $property->setValue($validFloat); $this->assertEquals($validFloat, $property->getValue()); @@ -88,9 +89,9 @@ public function testEnumProperty() $valid = 'Yes'; $invalid = 'Bob'; - $property = new Morph_Property_Enum('AProperty', $valid, $enums); + $property = new Enum('AProperty', $valid, $enums); - $this->assertEquals($enums, $property->getEnums()); + $this->assertEquals($enums, $property->getChoices()); $property->setValue($valid); $this->assertEquals($valid, $property->getValue()); @@ -102,7 +103,7 @@ public function testEnumProperty() public function testDateProperty() { - $property = new Morph_Property_Date('AProperty'); + $property = new Date('AProperty'); $time = time(); //check it stores the value correctly @@ -110,7 +111,7 @@ public function testDateProperty() $this->assertEquals($time, $property->getValue()); //check the output type is correct - $this->assertType('MongoDate', $property->__getRawValue()); + $this->assertType('\MongoDate', $property->__getRawValue()); //check the MorphDate objects content is correct $this->assertEquals($time, $property->__getRawValue()->sec); diff --git a/unit-tests/Query/TestProperty.php b/unit-tests/query/TestProperty.php similarity index 65% rename from unit-tests/Query/TestProperty.php rename to unit-tests/query/TestProperty.php index 0d4ce85..8b72a46 100644 --- a/unit-tests/Query/TestProperty.php +++ b/unit-tests/query/TestProperty.php @@ -1,9 +1,10 @@ getMockQuery()); + $property = new Property($this->getMockQuery()); $property->equals('ABC'); $this->assertEquals('ABC', $property->getConstraints()); } @@ -27,14 +28,14 @@ public function testEquals() public function testLessThan() { $expected = array('$lt' => 25); - $property = new Morph_Query_Property($this->getMockQuery()); + $property = new Property($this->getMockQuery()); $property->lessThan(25); $this->assertEquals($expected, $property->getConstraints()); } public function testInvalidConstraintCombo() { - $property = new Morph_Query_Property($this->getMockQuery()); + $property = new Property($this->getMockQuery()); $property->equals('ABC'); $this->setExpectedException('RuntimeException'); $property->greaterThan(25); @@ -43,7 +44,7 @@ public function testInvalidConstraintCombo() public function testCombinationConstraints() { $expected = array('$lte' => 25, '$gte' => 10); - $property = new Morph_Query_Property($this->getMockQuery()); + $property = new Property($this->getMockQuery()); $property->lessThanOrEqualTo(25); $property->greaterThanOrEqualTo(10); $this->assertEquals($expected, $property->getConstraints()); @@ -52,7 +53,7 @@ public function testCombinationConstraints() public function testCombinationConstraintsFluent() { $expected = array('$lte' => 25, '$gte' => 10); - $property = new Morph_Query_Property($this->getMockQuery()); + $property = new Property($this->getMockQuery()); $property->lessThanOrEqualTo(25) ->greaterThanOrEqualTo(10); $this->assertEquals($expected, $property->getConstraints()); @@ -61,7 +62,7 @@ public function testCombinationConstraintsFluent() public function testNotEqualTo() { $expected = array('$ne' => 25); - $property = new Morph_Query_Property($this->getMockQuery()); + $property = new Property($this->getMockQuery()); $property->notEqualTo(25); $this->assertEquals($expected, $property->getConstraints()); } @@ -69,7 +70,7 @@ public function testNotEqualTo() public function testAll() { $expected = array('$all' => array('a', 'b', 'c')); - $property = new Morph_Query_Property($this->getMockQuery()); + $property = new Property($this->getMockQuery()); $property->all(array('a', 'b', 'c')); $this->assertEquals($expected, $property->getConstraints()); } @@ -77,29 +78,29 @@ public function testAll() public function testIn() { $expected = array('$in' => array('a', 'b', 'c')); - $property = new Morph_Query_Property($this->getMockQuery()); + $property = new Property($this->getMockQuery()); $property->in(array('a', 'b', 'c')); $this->assertEquals($expected, $property->getConstraints()); } public function testPropertyFluency() { - $property = new Morph_Query_Property($this->getMockQuery(true)); + $property = new Property($this->getMockQuery(true)); $newField = $property->property('bob'); - $this->assertTrue($newField instanceof Morph_Query_Property); + $this->assertTrue($newField instanceof Property); } public function testRegexConstraint() { - $property = new Morph_Query_Property($this->getMockQuery(false)); + $property = new Property($this->getMockQuery(false)); $property->regex('/abc.*/'); - $this->assertTrue(($property->getConstraints() instanceof MongoRegex)); + $this->assertTrue(($property->getConstraints() instanceof \MongoRegex)); } public function testSort() { - $property = new Morph_Query_Property($this->getMockQuery(false)); + $property = new Property($this->getMockQuery(false)); $property->sort(1); $this->assertEquals(1, $property->getSort()); @@ -107,14 +108,13 @@ public function testSort() private function getMockQuery($willCallField = false) { - $query = $this->getMock('Morph_Query', array('property')); + $query = $this->getMock('\morph\Query', array('property')); if ($willCallField) { $query->expects($this->once()) ->method('property') - ->will($this->returnValue(new Morph_Query_Property($query))); + ->will($this->returnValue(new Property($query))); } return $query; } -} -?> \ No newline at end of file +} \ No newline at end of file