diff --git a/README.md b/README.md index da765d9..b51cf0c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Simple Mongo ODM library. Add package to your require section in the composer.json file. ```bash -composer require mrsuh/mongo-odm:1.* +composer require mrsuh/mongo-odm:2.* ``` ## Usage ## @@ -24,20 +24,20 @@ require 'vendor/autoload.php'; use ODM\DBAL; use ODM\Document\Document; -use ODM\DocumentMapper\DocumentManagerFactory; +use ODM\DocumentManager\DocumentManagerFactory; /** - * @ODM\Mapping\Annotator\Collection(name="alphabet") + * @Collection(name="alphabet") */ class Alphabet extends Document { /** - * @ODM\Mapping\Annotator\Field(name="language", type="string") + * @Field(name="language", type="string") */ private $language; /** - * @ODM\Mapping\Annotator\Field(name="words", type="Tests\Word[]") + * @Field(name="words", type="Tests\Word[]") */ private $words; @@ -91,7 +91,7 @@ class Alphabet extends Document { class Word { /** - * @ODM\Mapping\Annotator\Field(name="name", type="string") + * @Field(name="name", type="string") */ private $name; diff --git a/src/Document/Document.php b/src/Document/Document.php index a56a529..c4405e9 100644 --- a/src/Document/Document.php +++ b/src/Document/Document.php @@ -5,9 +5,9 @@ class Document { /** - * @ODM\Mapping\Annotator\Field(name="_id", type="string") + * @Field(name="_id", type="string") */ - private $id; + protected $id; /** * @return mixed diff --git a/src/DocumentManager/DocumentManager.php b/src/DocumentManager/DocumentManager.php index 5999bcc..3d495e5 100644 --- a/src/DocumentManager/DocumentManager.php +++ b/src/DocumentManager/DocumentManager.php @@ -1,9 +1,9 @@ mapper->getAnnotator()->isCollection()) { - throw new MapperException('There is no collection name for class ' . $class_name); + throw new MappingException('There is no collection name for class ' . $class_name); } } diff --git a/src/DocumentManager/DocumentManagerFactory.php b/src/DocumentManager/DocumentManagerFactory.php index 848b0ce..7a52914 100644 --- a/src/DocumentManager/DocumentManagerFactory.php +++ b/src/DocumentManager/DocumentManagerFactory.php @@ -1,6 +1,6 @@ parseCollection($metadata->getReflectionClass()); foreach($metadata->getReflectionProperties() as $property) { - $this->parseFields($property); + $this->parseField($property); } } @@ -48,7 +48,7 @@ public function __construct(Metadata $metadata) */ private function parseCollection(\ReflectionClass $reflection_class) { - $pattern = '/@' . preg_quote(Collection::class) . '\((.*)\)/'; + $pattern = '/@Collection\((.*)\)/'; preg_match($pattern, $reflection_class->getDocComment(), $matches); $doc = array_key_exists(1, $matches) ? $matches[1] : ''; @@ -64,9 +64,9 @@ private function parseCollection(\ReflectionClass $reflection_class) * @param \ReflectionProperty $reflection_property * @return bool */ - private function parseFields(\ReflectionProperty $reflection_property) + private function parseField(\ReflectionProperty $reflection_property) { - $pattern = '/@' . preg_quote(Field::class) . '\((.*)\)/'; + $pattern = '/@Field\((.*)\)/'; preg_match($pattern, $reflection_property->getDocComment(), $matches); $doc = array_key_exists(1, $matches) ? $matches[1] : ''; diff --git a/src/Mapping/Annotator/Collection.php b/src/Mapping/Annotator/Collection.php deleted file mode 100644 index ec3df81..0000000 --- a/src/Mapping/Annotator/Collection.php +++ /dev/null @@ -1,8 +0,0 @@ -get($class_name); @@ -221,7 +224,7 @@ private function typeCast(string $type, $value, int $to) break; } - throw new MapperException('Invalid type ' . $type); + throw new MappingException('Invalid type ' . $type); } return $value;