Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added the not ActiveRecord implementation

  • Loading branch information...
commit 9614c57729cb6998a6e6e4aa615b59c4afa3ac44 1 parent aaab36d
@pablodip authored
Showing with 429 additions and 6 deletions.
  1. +1 −0  .gitignore
  2. +95 −6 lib/Doctrator/Extension/Core.php
  3. +10 −0 tests/ModelNotAR/Article.php
  4. +10 −0 tests/ModelNotAR/ArticleRepository.php
  5. +10 −0 tests/ModelNotAR/Category.php
  6. +10 −0 tests/ModelNotAR/CategoryRepository.php
  7. +10 −0 tests/ModelNotAR/Hashable.php
  8. +10 −0 tests/ModelNotAR/HashableRepository.php
  9. +10 −0 tests/ModelNotAR/IdentifierStrategyIdentity.php
  10. +10 −0 tests/ModelNotAR/IdentifierStrategyIdentityRepository.php
  11. +10 −0 tests/ModelNotAR/IdentifierStrategyNone.php
  12. +10 −0 tests/ModelNotAR/IdentifierStrategyNoneRepository.php
  13. +10 −0 tests/ModelNotAR/Ipable.php
  14. +10 −0 tests/ModelNotAR/IpableRepository.php
  15. +10 −0 tests/ModelNotAR/Simple.php
  16. +10 −0 tests/ModelNotAR/SimpleRepository.php
  17. +10 −0 tests/ModelNotAR/Sluggable.php
  18. +10 −0 tests/ModelNotAR/SluggableRepository.php
  19. +10 −0 tests/ModelNotAR/SluggableUpdate.php
  20. +10 −0 tests/ModelNotAR/SluggableUpdateRepository.php
  21. +10 −0 tests/ModelNotAR/Sortable.php
  22. +10 −0 tests/ModelNotAR/SortableRepository.php
  23. +10 −0 tests/ModelNotAR/Taggable.php
  24. +10 −0 tests/ModelNotAR/TaggableRepository.php
  25. +10 −0 tests/ModelNotAR/TaggableTag.php
  26. +10 −0 tests/ModelNotAR/TaggableTagRepository.php
  27. +10 −0 tests/ModelNotAR/TaggableTagging.php
  28. +10 −0 tests/ModelNotAR/TaggableTaggingRepository.php
  29. +10 −0 tests/ModelNotAR/Timestampable.php
  30. +10 −0 tests/ModelNotAR/TimestampableRepository.php
  31. +10 −0 tests/ModelNotAR/Translatable.php
  32. +10 −0 tests/ModelNotAR/TranslatableRepository.php
  33. +10 −0 tests/ModelNotAR/TranslatableTranslation.php
  34. +10 −0 tests/ModelNotAR/TranslatableTranslationRepository.php
  35. +13 −0 tests/bootstrap.php
View
1  .gitignore
@@ -1,3 +1,4 @@
phpunit.xml
tests/config.php
tests/Model/Base
+tests/ModelNotAR/Base
View
101 lib/Doctrator/Extension/Core.php
@@ -46,6 +46,7 @@ protected function setup()
{
$this->addOptions(array(
'default_output' => null,
+ 'active_record' => true,
'default_behaviors' => array(),
));
}
@@ -111,8 +112,16 @@ protected function doProcess()
$this->processCheckIsNotModifiedMethod();
$this->processGetModifiedMethod();
$this->processRefreshMethod();
- $this->processSaveMethod();
- $this->processDeleteMethod();
+
+ if ($this->getOption('active_record')) {
+ $this->processActiveRecordSaveMethod();
+ $this->processActiveRecordDeleteMethod();
+ } else {
+ $this->processNotActiveRecordPersistMethod();
+ $this->processNotActiveRecordRemoveMethod();
+ $this->processNotActiveRecordSaveMethod();
+ $this->processNotActiveRecordDeleteMethod();
+ }
// events methods
$this->processEventsMethods();
@@ -1037,9 +1046,9 @@ protected function processRefreshMethod()
}
/*
- * "save" method
+ * "save" active record method
*/
- protected function processSaveMethod()
+ protected function processActiveRecordSaveMethod()
{
$method = new Method('public', 'save', '', <<<EOF
\$this->checkEntityManagerIsClear();
@@ -1061,9 +1070,9 @@ protected function processSaveMethod()
}
/*
- * "delete" method
+ * "delete" active record method
*/
- protected function processDeleteMethod()
+ protected function processActiveRecordDeleteMethod()
{
$method = new Method('public', 'delete', '', <<<EOF
\$this->checkEntityManagerIsClear();
@@ -1085,6 +1094,86 @@ protected function processDeleteMethod()
}
/*
+ * "persist" not active record method
+ */
+ protected function processNotActiveRecordPersistMethod()
+ {
+ $method = new Method('public', 'persist', '', <<<EOF
+ \$this->getEntityManager()->persist(\$this);
+EOF
+ );
+ $method->setDocComment(<<<EOF
+ /**
+ * Persist the entity (the same that \$em->persist(\$entity);)
+ */
+EOF
+ );
+
+ $this->definitions['entity_base']->addMethod($method);
+ }
+
+ /*
+ * "remove" not active record method
+ */
+ protected function processNotActiveRecordRemoveMethod()
+ {
+ $method = new Method('public', 'persist', '', <<<EOF
+ \$this->getEntityManager()->remove(\$this);
+EOF
+ );
+ $method->setDocComment(<<<EOF
+ /**
+ * Remove the entity (the same that \$em->remove(\$entity);)
+ */
+EOF
+ );
+
+ $this->definitions['entity_base']->addMethod($method);
+ }
+
+ /*
+ * "save" not active record method
+ */
+ protected function processNotActiveRecordSaveMethod()
+ {
+ $method = new Method('public', 'save', '', <<<EOF
+ \$this->persist();
+EOF
+ );
+ $method->setDocComment(<<<EOF
+ /**
+ * Save the entity (equivalent to the ->persist() method)
+ *
+ * This is the not ActiveRecord implementation of Doctrator.
+ */
+EOF
+ );
+
+ $this->definitions['entity_base']->addMethod($method);
+ }
+
+ /*
+ * "delete" not active record method
+ */
+ protected function processNotActiveRecordDeleteMethod()
+ {
+ $method = new Method('public', 'delete', '', <<<EOF
+ \$this->remove();
+EOF
+ );
+ $method->setDocComment(<<<EOF
+ /**
+ * Delete the entity (equivalent to the ->remove() method)
+ *
+ * This is the not ActiveRecord implementation of Doctrator.
+ */
+EOF
+ );
+
+ $this->definitions['entity_base']->addMethod($method);
+ }
+
+ /*
* events methods
*/
protected function processEventsMethods()
View
10 tests/ModelNotAR/Article.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Article entity.
+ */
+class Article extends \Model\Base\Article
+{
+}
View
10 tests/ModelNotAR/ArticleRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Article entity.
+ */
+class ArticleRepository extends \Model\Base\ArticleRepository
+{
+}
View
10 tests/ModelNotAR/Category.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Category entity.
+ */
+class Category extends \Model\Base\Category
+{
+}
View
10 tests/ModelNotAR/CategoryRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Category entity.
+ */
+class CategoryRepository extends \Model\Base\CategoryRepository
+{
+}
View
10 tests/ModelNotAR/Hashable.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Hashable entity.
+ */
+class Hashable extends \Model\Base\Hashable
+{
+}
View
10 tests/ModelNotAR/HashableRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Hashable entity.
+ */
+class HashableRepository extends \Model\Base\HashableRepository
+{
+}
View
10 tests/ModelNotAR/IdentifierStrategyIdentity.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\IdentifierStrategyIdentity entity.
+ */
+class IdentifierStrategyIdentity extends \Model\Base\IdentifierStrategyIdentity
+{
+}
View
10 tests/ModelNotAR/IdentifierStrategyIdentityRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\IdentifierStrategyIdentity entity.
+ */
+class IdentifierStrategyIdentityRepository extends \Model\Base\IdentifierStrategyIdentityRepository
+{
+}
View
10 tests/ModelNotAR/IdentifierStrategyNone.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\IdentifierStrategyNone entity.
+ */
+class IdentifierStrategyNone extends \Model\Base\IdentifierStrategyNone
+{
+}
View
10 tests/ModelNotAR/IdentifierStrategyNoneRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\IdentifierStrategyNone entity.
+ */
+class IdentifierStrategyNoneRepository extends \Model\Base\IdentifierStrategyNoneRepository
+{
+}
View
10 tests/ModelNotAR/Ipable.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Ipable entity.
+ */
+class Ipable extends \Model\Base\Ipable
+{
+}
View
10 tests/ModelNotAR/IpableRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Ipable entity.
+ */
+class IpableRepository extends \Model\Base\IpableRepository
+{
+}
View
10 tests/ModelNotAR/Simple.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Simple entity.
+ */
+class Simple extends \Model\Base\Simple
+{
+}
View
10 tests/ModelNotAR/SimpleRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Simple entity.
+ */
+class SimpleRepository extends \Model\Base\SimpleRepository
+{
+}
View
10 tests/ModelNotAR/Sluggable.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Sluggable entity.
+ */
+class Sluggable extends \Model\Base\Sluggable
+{
+}
View
10 tests/ModelNotAR/SluggableRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Sluggable entity.
+ */
+class SluggableRepository extends \Model\Base\SluggableRepository
+{
+}
View
10 tests/ModelNotAR/SluggableUpdate.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\SluggableUpdate entity.
+ */
+class SluggableUpdate extends \Model\Base\SluggableUpdate
+{
+}
View
10 tests/ModelNotAR/SluggableUpdateRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\SluggableUpdate entity.
+ */
+class SluggableUpdateRepository extends \Model\Base\SluggableUpdateRepository
+{
+}
View
10 tests/ModelNotAR/Sortable.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Sortable entity.
+ */
+class Sortable extends \Model\Base\Sortable
+{
+}
View
10 tests/ModelNotAR/SortableRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Sortable entity.
+ */
+class SortableRepository extends \Model\Base\SortableRepository
+{
+}
View
10 tests/ModelNotAR/Taggable.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Taggable entity.
+ */
+class Taggable extends \Model\Base\Taggable
+{
+}
View
10 tests/ModelNotAR/TaggableRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Taggable entity.
+ */
+class TaggableRepository extends \Model\Base\TaggableRepository
+{
+}
View
10 tests/ModelNotAR/TaggableTag.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\TaggableTag entity.
+ */
+class TaggableTag extends \Model\Base\TaggableTag
+{
+}
View
10 tests/ModelNotAR/TaggableTagRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\TaggableTag entity.
+ */
+class TaggableTagRepository extends \Model\Base\TaggableTagRepository
+{
+}
View
10 tests/ModelNotAR/TaggableTagging.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\TaggableTagging entity.
+ */
+class TaggableTagging extends \Model\Base\TaggableTagging
+{
+}
View
10 tests/ModelNotAR/TaggableTaggingRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\TaggableTagging entity.
+ */
+class TaggableTaggingRepository extends \Model\Base\TaggableTaggingRepository
+{
+}
View
10 tests/ModelNotAR/Timestampable.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Timestampable entity.
+ */
+class Timestampable extends \Model\Base\Timestampable
+{
+}
View
10 tests/ModelNotAR/TimestampableRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Timestampable entity.
+ */
+class TimestampableRepository extends \Model\Base\TimestampableRepository
+{
+}
View
10 tests/ModelNotAR/Translatable.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\Translatable entity.
+ */
+class Translatable extends \Model\Base\Translatable
+{
+}
View
10 tests/ModelNotAR/TranslatableRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\Translatable entity.
+ */
+class TranslatableRepository extends \Model\Base\TranslatableRepository
+{
+}
View
10 tests/ModelNotAR/TranslatableTranslation.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Model\TranslatableTranslation entity.
+ */
+class TranslatableTranslation extends \Model\Base\TranslatableTranslation
+{
+}
View
10 tests/ModelNotAR/TranslatableTranslationRepository.php
@@ -0,0 +1,10 @@
+<?php
+
+namespace Model;
+
+/**
+ * Repository of the Model\TranslatableTranslation entity.
+ */
+class TranslatableTranslationRepository extends \Model\Base\TranslatableTranslationRepository
+{
+}
View
13 tests/bootstrap.php
@@ -165,3 +165,16 @@
new Doctrator\Extension\EntityPropertyOverloading(),
));
$mondator->process();
+
+/*
+ * Not ActiveRecord
+ */
+$mondator = new Mondator();
+$mondator->setConfigClasses($configClasses);
+$mondator->setExtensions(array(
+ new Doctrator\Extension\Core(array(
+ 'default_output' => __DIR__.'/ModelNotAR',
+ 'active_record' => false,
+ )),
+));
+$mondator->process();
Please sign in to comment.
Something went wrong with that request. Please try again.