From d1d130b763b9b572211989b7396a3ba629a8097d Mon Sep 17 00:00:00 2001 From: anton Date: Tue, 18 Jul 2017 23:20:59 +0300 Subject: [PATCH 1/3] annotations --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da765d9..ce925a3 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 ## From 1b0bd0188306653d3fb3b918e7289bebddc5acea Mon Sep 17 00:00:00 2001 From: anton Date: Tue, 18 Jul 2017 23:57:34 +0300 Subject: [PATCH 2/3] annotations --- src/DocumentManager/DocumentManager.php | 8 ++++---- src/DocumentManager/DocumentManagerFactory.php | 2 +- src/Exception/MapperException.php | 8 -------- src/Exception/MappingException.php | 8 ++++++++ src/Mapping/DataMapper.php | 10 +++++----- 5 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 src/Exception/MapperException.php create mode 100644 src/Exception/MappingException.php 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 @@ get($class_name); @@ -221,7 +221,7 @@ private function typeCast(string $type, $value, int $to) break; } - throw new MapperException('Invalid type ' . $type); + throw new MappingException('Invalid type ' . $type); } return $value; From 73c1c46893db0b7863d7717330cf45b04a48a597 Mon Sep 17 00:00:00 2001 From: anton Date: Wed, 19 Jul 2017 23:25:12 +0300 Subject: [PATCH 3/3] annotations --- README.md | 10 +++++----- src/Document/Document.php | 4 ++-- src/Mapping/Annotator/Annotator.php | 8 ++++---- src/Mapping/Annotator/Collection.php | 8 -------- src/Mapping/Annotator/Field.php | 8 -------- src/Mapping/DataMapper.php | 3 +++ 6 files changed, 14 insertions(+), 27 deletions(-) delete mode 100644 src/Mapping/Annotator/Collection.php delete mode 100644 src/Mapping/Annotator/Field.php diff --git a/README.md b/README.md index ce925a3..b51cf0c 100644 --- a/README.md +++ b/README.md @@ -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/Mapping/Annotator/Annotator.php b/src/Mapping/Annotator/Annotator.php index ff50175..6094032 100644 --- a/src/Mapping/Annotator/Annotator.php +++ b/src/Mapping/Annotator/Annotator.php @@ -38,7 +38,7 @@ public function __construct(Metadata $metadata) $this->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 @@ -