diff --git a/.gitignore b/.gitignore index 22d0d82..fdb5924 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ vendor +.idea +composer.lock \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 0b1843c..3dad1cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ php: - hhvm env: + - SYMFONY_VERSION=2.2.* - SYMFONY_VERSION=2.3.* - SYMFONY_VERSION=2.4.* - SYMFONY_VERSION=dev-master diff --git a/DependencyInjection/Compiler/RegisterMappingsPass.php b/DependencyInjection/Compiler/RegisterMappingsPass.php new file mode 100644 index 0000000..b94fedb --- /dev/null +++ b/DependencyInjection/Compiler/RegisterMappingsPass.php @@ -0,0 +1,123 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Ekino\WordpressBundle\DependencyInjection\Compiler; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException; + +/** + * Class EkinoWordpressExtension + * + * This is the bundle Symfony extension class + * + * @author Xavier Coureau + * @author David Buchmann + */ +class RegisterMappingsPass implements CompilerPassInterface +{ + /** + * @var \Symfony\Component\DependencyInjection\Definition + */ + private $driver; + + /** + * @var string + */ + private $driverPattern; + + /** + * @var array + */ + private $namespaces; + + /** + * @var string + */ + private $enabledParameter; + + /** + * @var string + */ + private $fallbackManagerParameter; + + /** + * @param Definition $driver + * @param string $driverPattern + * @param array $namespaces + * @param string $enabledParameter + * @param string $fallbackManagerParameter + */ + public function __construct($driver, $driverPattern, $namespaces, $enabledParameter, $fallbackManagerParameter) + { + $this->driver = $driver; + $this->driverPattern = $driverPattern; + $this->namespaces = $namespaces; + $this->enabledParameter = $enabledParameter; + $this->fallbackManagerParameter = $fallbackManagerParameter; + } + + /** + * Register mappings with the metadata drivers. + * + * @param ContainerBuilder $container + */ + public function process(ContainerBuilder $container) + { + if (!$container->hasParameter($this->enabledParameter)) { + return; + } + + $chainDriverDefService = $this->getChainDriverServiceName($container); + $chainDriverDef = $container->getDefinition($chainDriverDefService); + + foreach ($this->namespaces as $namespace) { + $chainDriverDef->addMethodCall('addDriver', array($this->driver, $namespace)); + } + } + + /** + * @param ContainerBuilder $container + * + * @return string + * + * @throws \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException + */ + protected function getChainDriverServiceName(ContainerBuilder $container) + { + foreach (array('ekino_wordpress.model_manager_name', $this->fallbackManagerParameter) as $param) { + if ($container->hasParameter($param)) { + $name = $container->getParameter($param); + if ($name) { + return sprintf($this->driverPattern, $name); + } + } + } + + throw new ParameterNotFoundException('None of the managerParameters resulted in a valid name'); + } + + /** + * @param array $mappings + * + * @return RegisterMappingsPass + */ + public static function createOrmMappingDriver(array $mappings) + { + $arguments = array($mappings, '.orm.xml'); + $locator = new Definition('Doctrine\Common\Persistence\Mapping\Driver\SymfonyFileLocator', $arguments); + $driver = new Definition('Doctrine\ORM\Mapping\Driver\XmlDriver', array($locator)); + + return new RegisterMappingsPass($driver, 'doctrine.orm.%s_metadata_driver', $mappings, 'ekino_wordpress.backend_type_orm', 'doctrine.default_entity_manager'); + } +} diff --git a/DependencyInjection/EkinoWordpressExtension.php b/DependencyInjection/EkinoWordpressExtension.php index c842412..d216ec7 100755 --- a/DependencyInjection/EkinoWordpressExtension.php +++ b/DependencyInjection/EkinoWordpressExtension.php @@ -10,6 +10,7 @@ namespace Ekino\WordpressBundle\DependencyInjection; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; use Symfony\Component\DependencyInjection\Reference; @@ -60,6 +61,8 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('ekino.wordpress.i18n_cookie_name', $config['i18n_cookie_name']); $loader->load('i18n.xml'); } + + $container->setParameter($this->getAlias() . '.backend_type_orm', true); } /** @@ -94,6 +97,10 @@ protected function loadWordpressDirectory(ContainerBuilder $container, $director $container->setDefinition($identifier, $serviceDefinition); } + /** + * @param ContainerBuilder $container + * @param EntityManagerInterface $em + */ protected function loadEntityManager(ContainerBuilder $container, $em) { $reference = new Reference(sprintf('doctrine.orm.%s_entity_manager', $em)); diff --git a/EkinoWordpressBundle.php b/EkinoWordpressBundle.php index bc8a4ff..84a8712 100755 --- a/EkinoWordpressBundle.php +++ b/EkinoWordpressBundle.php @@ -10,6 +10,9 @@ namespace Ekino\WordpressBundle; +use Ekino\WordpressBundle\DependencyInjection\Compiler\RegisterMappingsPass; +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\HttpKernel\Bundle\Bundle; /** @@ -21,4 +24,25 @@ */ class EkinoWordpressBundle extends Bundle { + /** + * @param ContainerBuilder $container + */ + public function build(ContainerBuilder $container) + { + parent::build($container); + + $this->addRegisterMappingPass($container); + } + + /** + * @param ContainerBuilder $containerBuilder + */ + public function addRegisterMappingPass(ContainerBuilder $containerBuilder) + { + $mappings = array( + realpath(__DIR__ . '/Resources/config/doctrine/model') => 'Ekino\WordpressBundle\Model', + ); + + $containerBuilder->addCompilerPass(RegisterMappingsPass::createOrmMappingDriver($mappings)); + } } diff --git a/Entity/Comment.php b/Entity/Comment.php index 0c37a46..de54ed2 100644 --- a/Entity/Comment.php +++ b/Entity/Comment.php @@ -10,6 +10,8 @@ namespace Ekino\WordpressBundle\Entity; +use Ekino\WordpressBundle\Model\Comment as CommentModel; + /** * Class Comment * @@ -17,369 +19,7 @@ * * @author Vincent Composieux */ -class Comment implements WordpressEntityInterface, WordpressContentInterface +class Comment extends CommentModel { - /** - * @var integer - */ - protected $id; - - /** - * @var Post - */ - protected $post; - - /** - * @var string - */ - protected $author; - - /** - * @var string - */ - protected $authorEmail; - - /** - * @var string - */ - protected $authorUrl; - - /** - * @var string - */ - protected $authorIp; - - /** - * @var \DateTime - */ - protected $date; - - /** - * @var \DateTime - */ - protected $dateGmt; - - /** - * @var string - */ - protected $content; - - /** - * @var integer - */ - protected $karma; - - /** - * @var string - */ - protected $approved; - - /** - * @var string - */ - protected $agent; - - /** - * @var string - */ - protected $type; - - /** - * @var Comment - */ - protected $parent; - - /** - * @var User - */ - protected $user; - - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $agent - * - * @return Comment - */ - public function setAgent($agent) - { - $this->agent = $agent; - - return $this; - } - - /** - * @return string - */ - public function getAgent() - { - return $this->agent; - } - - /** - * @param string $approved - * - * @return Comment - */ - public function setApproved($approved) - { - $this->approved = $approved; - - return $this; - } - - /** - * @return string - */ - public function getApproved() - { - return $this->approved; - } - - /** - * @param string $author - * - * @return Comment - */ - public function setAuthor($author) - { - $this->author = $author; - - return $this; - } - - /** - * @return string - */ - public function getAuthor() - { - return $this->author; - } - - /** - * @param string $authorEmail - * - * @return Comment - */ - public function setAuthorEmail($authorEmail) - { - $this->authorEmail = $authorEmail; - - return $this; - } - - /** - * @return string - */ - public function getAuthorEmail() - { - return $this->authorEmail; - } - - /** - * @param string $authorIp - * - * @return Comment - */ - public function setAuthorIp($authorIp) - { - $this->authorIp = $authorIp; - - return $this; - } - - /** - * @return string - */ - public function getAuthorIp() - { - return $this->authorIp; - } - - /** - * @param string $authorUrl - * - * @return Comment - */ - public function setAuthorUrl($authorUrl) - { - $this->authorUrl = $authorUrl; - - return $this; - } - - /** - * @return string - */ - public function getAuthorUrl() - { - return $this->authorUrl; - } - - /** - * @param string $content - * - * @return Comment - */ - public function setContent($content) - { - $this->content = $content; - - return $this; - } - - /** - * @return string - */ - public function getContent() - { - return $this->content; - } - - /** - * @param \DateTime $date - * - * @return Comment - */ - public function setDate($date) - { - $this->date = $date; - - return $this; - } - - /** - * @return \DateTime - */ - public function getDate() - { - return $this->date; - } - - /** - * @param \DateTime $dateGmt - * - * @return Comment - */ - public function setDateGmt($dateGmt) - { - $this->dateGmt = $dateGmt; - - return $this; - } - - /** - * @return \DateTime - */ - public function getDateGmt() - { - return $this->dateGmt; - } - - /** - * @param int $karma - * - * @return Comment - */ - public function setKarma($karma) - { - $this->karma = $karma; - - return $this; - } - - /** - * @return int - */ - public function getKarma() - { - return $this->karma; - } - - /** - * @param Comment $parent - * - * @return Comment - */ - public function setParent(Comment $parent) - { - $this->parent = $parent; - - return $this; - } - - /** - * @return Comment - */ - public function getParent() - { - return $this->parent; - } - - /** - * @param Post $post - * - * @return Comment - */ - public function setPost(Post $post) - { - $this->post = $post; - - return $this; - } - - /** - * @return Post - */ - public function getPost() - { - return $this->post; - } - - /** - * @param string $type - * - * @return Comment - */ - public function setType($type) - { - $this->type = $type; - - return $this; - } - - /** - * @return string - */ - public function getType() - { - return $this->type; - } - - /** - * @param User $user - * - * @return Comment - */ - public function setUser(User $user) - { - $this->user = $user; - - return $this; - } - /** - * @return User - */ - public function getUser() - { - return $this->user; - } } \ No newline at end of file diff --git a/Entity/CommentMeta.php b/Entity/CommentMeta.php index e38a079..c6e6979 100644 --- a/Entity/CommentMeta.php +++ b/Entity/CommentMeta.php @@ -10,6 +10,8 @@ namespace Ekino\WordpressBundle\Entity; +use Ekino\WordpressBundle\Model\CommentMeta as CommentMetaModel; + /** * Class CommentMeta * @@ -17,94 +19,6 @@ * * @author Vincent Composieux */ -class CommentMeta implements WordpressEntityInterface +class CommentMeta extends CommentMetaModel { - /** - * @var integer - */ - protected $id; - - /** - * @var Comment - */ - protected $comment; - - /** - * @var string - */ - protected $key; - - /** - * @var string - */ - protected $value; - - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param Comment $comment - * - * @return CommentMeta - */ - public function setComment(Comment $comment) - { - $this->comment = $comment; - - return $this; - } - - /** - * @return Comment - */ - public function getComment() - { - return $this->comment; - } - - /** - * @param string $key - * - * @return CommentMeta - */ - public function setKey($key) - { - $this->key = $key; - - return $this; - } - - /** - * @return string - */ - public function getKey() - { - return $this->key; - } - - /** - * @param string $value - * - * @return CommentMeta - */ - public function setValue($value) - { - $this->value = $value; - - return $this; - } - - /** - * @return string - */ - public function getValue() - { - return $this->value; - } } \ No newline at end of file diff --git a/Entity/Link.php b/Entity/Link.php index 0a91965..dba917d 100644 --- a/Entity/Link.php +++ b/Entity/Link.php @@ -10,6 +10,8 @@ namespace Ekino\WordpressBundle\Entity; +use Ekino\WordpressBundle\Model\Link as LinkModel; + /** * Class Link * @@ -17,319 +19,6 @@ * * @author Vincent Composieux */ -class Link implements WordpressEntityInterface +class Link extends LinkModel { - /** - * @var integer - */ - protected $id; - - /** - * @var string - */ - protected $url; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $image; - - /** - * @var string - */ - protected $target; - - /** - * @var string - */ - protected $description; - - /** - * @var string - */ - protected $visible; - - /** - * @var integer - */ - protected $owner; - - /** - * @var integer - */ - protected $rating; - - /** - * @var \DateTime - */ - protected $updated; - - /** - * @var string - */ - protected $rel; - - /** - * @var string - */ - protected $notes; - - /** - * @var string - */ - protected $rss; - - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $description - * - * @return Link - */ - public function setDescription($description) - { - $this->description = $description; - - return $this; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $image - * - * @return Link - */ - public function setImage($image) - { - $this->image = $image; - - return $this; - } - - /** - * @return string - */ - public function getImage() - { - return $this->image; - } - - /** - * @param string $name - * - * @return Link - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $notes - * - * @return Link - */ - public function setNotes($notes) - { - $this->notes = $notes; - - return $this; - } - - /** - * @return string - */ - public function getNotes() - { - return $this->notes; - } - - /** - * @param int $owner - * - * @return Link - */ - public function setOwner($owner) - { - $this->owner = $owner; - - return $this; - } - - /** - * @return int - */ - public function getOwner() - { - return $this->owner; - } - - /** - * @param int $rating - * - * @return Link - */ - public function setRating($rating) - { - $this->rating = $rating; - - return $this; - } - - /** - * @return int - */ - public function getRating() - { - return $this->rating; - } - - /** - * @param string $rel - * - * @return Link - */ - public function setRel($rel) - { - $this->rel = $rel; - - return $this; - } - - /** - * @return string - */ - public function getRel() - { - return $this->rel; - } - - /** - * @param string $rss - * - * @return Link - */ - public function setRss($rss) - { - $this->rss = $rss; - - return $this; - } - - /** - * @return string - */ - public function getRss() - { - return $this->rss; - } - - /** - * @param string $target - * - * @return Link - */ - public function setTarget($target) - { - $this->target = $target; - - return $this; - } - - /** - * @return string - */ - public function getTarget() - { - return $this->target; - } - - /** - * @param \DateTime $updated - * - * @return Link - */ - public function setUpdated($updated) - { - $this->updated = $updated; - - return $this; - } - - /** - * @return \DateTime - */ - public function getUpdated() - { - return $this->updated; - } - - /** - * @param string $url - * - * @return Link - */ - public function setUrl($url) - { - $this->url = $url; - - return $this; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $visible - * - * @return Link - */ - public function setVisible($visible) - { - $this->visible = $visible; - - return $this; - } - - /** - * @return string - */ - public function getVisible() - { - return $this->visible; - } } \ No newline at end of file diff --git a/Entity/Option.php b/Entity/Option.php index f5452c2..396c20e 100644 --- a/Entity/Option.php +++ b/Entity/Option.php @@ -10,6 +10,8 @@ namespace Ekino\WordpressBundle\Entity; +use Ekino\WordpressBundle\Model\Option as OptionModel; + /** * Class Option * @@ -17,94 +19,6 @@ * * @author Vincent Composieux */ -class Option implements WordpressEntityInterface +class Option extends OptionModel { - /** - * @var integer - */ - protected $id; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $value; - - /** - * @var string - */ - protected $autoload; - - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $autoload - * - * @return Option - */ - public function setAutoload($autoload) - { - $this->autoload = $autoload; - - return $this; - } - - /** - * @return string - */ - public function getAutoload() - { - return $this->autoload; - } - - /** - * @param string $name - * - * @return Option - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $value - * - * @return Option - */ - public function setValue($value) - { - $this->value = $value; - - return $this; - } - - /** - * @return string - */ - public function getValue() - { - return $this->value; - } } \ No newline at end of file diff --git a/Entity/Post.php b/Entity/Post.php index 42292bc..592a56a 100644 --- a/Entity/Post.php +++ b/Entity/Post.php @@ -10,8 +10,7 @@ namespace Ekino\WordpressBundle\Entity; -use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Common\Collections\Criteria; +use Ekino\WordpressBundle\Model\Post as PostModel; /** * Class Post @@ -20,803 +19,7 @@ * * @author Vincent Composieux */ -class Post implements WordpressEntityInterface, WordpressContentInterface +class Post extends PostModel { - /** - * @var integer - */ - protected $id; - - /** - * @var User - */ - protected $author; - - /** - * @var \DateTime - */ - protected $date; - - /** - * @var \DateTime - */ - protected $dateGmt; - - /** - * @var string - */ - protected $content; - - /** - * @var string - */ - protected $title; - - /** - * @var string - */ - protected $excerpt; - - /** - * @var string - */ - protected $status; - - /** - * @var string - */ - protected $commentStatus; - - /** - * @var string - */ - protected $pingStatus; - - /** - * @var string - */ - protected $password; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $toPing; - - /** - * @var string - */ - protected $pinged; - - /** - * @var \DateTime - */ - protected $modified; - - /** - * @var \DateTime - */ - protected $modifiedGmt; - - /** - * @var string - */ - protected $contentFiltered; - - /** - * @var integer - */ - protected $parent = 0; - - /** - * @var string - */ - protected $guid; - - /** - * @var integer - */ - protected $menuOrder; - - /** - * @var string - */ - protected $type; - - /** - * @var string - */ - protected $mimeType; - - /** - * @var integer - */ - protected $commentCount; - - /** - * @var ArrayCollection - */ - protected $metas; - - /** - * @var ArrayCollection - */ - protected $comments; - - /** - * @var ArrayCollection - */ - protected $termRelationships; - - /** - * Constructor - */ - public function __construct() - { - $this->metas = new ArrayCollection(); - $this->comments = new ArrayCollection(); - $this->termRelationships = new ArrayCollection(); - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param User $author - * - * @return Post - */ - public function setAuthor(User $author) - { - $this->author = $author; - - return $this; - } - - /** - * @return User - */ - public function getAuthor() - { - return $this->author; - } - - /** - * @param int $commentCount - * - * @return Post - */ - public function setCommentCount($commentCount) - { - $this->commentCount = $commentCount; - - return $this; - } - - /** - * @return int - */ - public function getCommentCount() - { - return $this->commentCount; - } - - /** - * @param string $content - * - * @return Post - */ - public function setContent($content) - { - $this->content = $content; - - return $this; - } - - /** - * @return string - */ - public function getContent() - { - return $this->content; - } - - /** - * @param string $contentFiltered - * - * @return Post - */ - public function setContentFiltered($contentFiltered) - { - $this->contentFiltered = $contentFiltered; - - return $this; - } - - /** - * @return string - */ - public function getContentFiltered() - { - return $this->contentFiltered; - } - - /** - * @param \DateTime $date - * - * @return Post - */ - public function setDate($date) - { - $this->date = $date; - - return $this; - } - - /** - * @return \DateTime - */ - public function getDate() - { - return $this->date; - } - - /** - * @param \DateTime $dateGmt - * - * @return Post - */ - public function setDateGmt($dateGmt) - { - $this->dateGmt = $dateGmt; - - return $this; - } - - /** - * @return \DateTime - */ - public function getDateGmt() - { - return $this->dateGmt; - } - - /** - * @param string $excerpt - * - * @return Post - */ - public function setExcerpt($excerpt) - { - $this->excerpt = $excerpt; - - return $this; - } - - /** - * @return string - */ - public function getExcerpt() - { - return $this->excerpt; - } - - /** - * @param string $guid - * - * @return Post - */ - public function setGuid($guid) - { - $this->guid = $guid; - - return $this; - } - - /** - * @return string - */ - public function getGuid() - { - return $this->guid; - } - - /** - * @param int $menuOrder - * - * @return Post - */ - public function setMenuOrder($menuOrder) - { - $this->menuOrder = $menuOrder; - - return $this; - } - - /** - * @return int - */ - public function getMenuOrder() - { - return $this->menuOrder; - } - - /** - * @param string $mimeType - * - * @return Post - */ - public function setMimeType($mimeType) - { - $this->mimeType = $mimeType; - - return $this; - } - - /** - * @return string - */ - public function getMimeType() - { - return $this->mimeType; - } - - /** - * @param \DateTime $modified - * - * @return Post - */ - public function setModified($modified) - { - $this->modified = $modified; - - return $this; - } - - /** - * @return \DateTime - */ - public function getModified() - { - return $this->modified; - } - - /** - * @param \DateTime $modifiedGmt - * - * @return Post - */ - public function setModifiedGmt($modifiedGmt) - { - $this->modifiedGmt = $modifiedGmt; - - return $this; - } - - /** - * @return \DateTime - */ - public function getModifiedGmt() - { - return $this->modifiedGmt; - } - - /** - * @param string $name - * - * @return Post - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param integer $parent - * - * @return Post - */ - public function setParent($parent) - { - $this->parent = $parent; - - return $this; - } - - /** - * @return integer - */ - public function getParent() - { - return $this->parent; - } - - /** - * @param string $password - * - * @return Post - */ - public function setPassword($password) - { - $this->password = $password; - - return $this; - } - - /** - * @return string - */ - public function getPassword() - { - return $this->password; - } - - /** - * @param string $status - * - * @return Post - */ - public function setStatus($status) - { - $this->status = $status; - - return $this; - } - - /** - * @return string - */ - public function getStatus() - { - return $this->status; - } - - /** - * @param string $commentStatus - * - * @return Post - */ - public function setCommentStatus($commentStatus) - { - $this->commentStatus = $commentStatus; - - return $this; - } - - /** - * @return string - */ - public function getCommentStatus() - { - return $this->commentStatus; - } - - /** - * @param string $pingStatus - * - * @return Post - */ - public function setPingStatus($pingStatus) - { - $this->pingStatus = $pingStatus; - - return $this; - } - - /** - * @return string - */ - public function getPingStatus() - { - return $this->pingStatus; - } - - /** - * @param string $pinged - * - * @return Post - */ - public function setPinged($pinged) - { - $this->pinged = $pinged; - - return $this; - } - - /** - * @return string - */ - public function getPinged() - { - return $this->pinged; - } - - /** - * @param string $title - * - * @return Post - */ - public function setTitle($title) - { - $this->title = $title; - - return $this; - } - - /** - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param string $toPing - * - * @return Post - */ - public function setToPing($toPing) - { - $this->toPing = $toPing; - - return $this; - } - - /** - * @return string - */ - public function getToPing() - { - return $this->toPing; - } - - /** - * @param string $type - * - * @return Post - */ - public function setType($type) - { - $this->type = $type; - - return $this; - } - - /** - * @return string - */ - public function getType() - { - return $this->type; - } - - /** - * @param ArrayCollection $metas - * - * @return Post - */ - public function setMetas(ArrayCollection $metas) - { - $this->metas = $metas; - - return $this; - } - - /** - * @return ArrayCollection - */ - public function getMetas() - { - return $this->metas; - } - - /** - * @param PostMeta $meta - * - * @return Post - */ - public function addMeta(PostMeta $meta) - { - $this->metas[] = $meta; - - return $this; - } - - /** - * @param PostMeta $meta - * - * @return Post - */ - public function removeMeta(PostMeta $meta) - { - if ($this->metas->contains($meta)) { - $this->metas->remove($meta); - } - - return $this; - } - - /** - * @param string $name - * - * @return \Doctrine\Common\Collections\Collection - */ - public function getMetaByKey($name) - { - $criteria = Criteria::create(); - $criteria->where(Criteria::expr()->eq('key', $name)); - - return $this->metas->matching($criteria); - } - - /** - * Returns user meta value from a meta key name - * - * @param string $name - * - * @return string|null - */ - public function getMetaValue($name) - { - /** @var PostMeta $meta */ - foreach ($this->getMetas() as $meta) { - if ($name == $meta->getKey()) { - return $meta->getValue(); - } - } - - return null; - } - - /** - * @return ArrayCollection - */ - public function getComments() - { - return $this->comments; - } - - /** - * @param Comment $comment - * - * @return Post - */ - public function addComment(Comment $comment) - { - if (!$this->comments->contains($comment)) { - $this->comments[] = $comment; - } - - return $this; - } - - /** - * @param Comment $comment - * - * @return Post - */ - public function removeComment(Comment $comment) - { - $this->comments->remove($comment); - - return $this; - } - - /** - * @return ArrayCollection - */ - public function getTermRelationships() - { - return $this->termRelationships; - } - - /** - * @param TermRelationships $relationship - * - * @return Post - */ - public function addTermRelationship(TermRelationships $relationship) - { - $this->termRelationships[] = $relationship; - - return $this; - } - - /** - * @param TermRelationships $relationship - * - * @return Post - */ - public function removeTermRelationship(TermRelationships $relationship) - { - $this->termRelationships->remove($relationship); - - return $this; - } - - /** - * @param string $type - * - * @return ArrayCollection|null - */ - public function getTaxonomiesByType($type) - { - $taxonomies = new ArrayCollection(); - - /** @var TermRelationships $relationship */ - foreach ($this->getTermRelationships() as $relationship) { - if ($type === $relationship->getTaxonomy()->getTaxonomy()) { - $taxonomies[] = $relationship->getTaxonomy(); - } - } - - return ($taxonomies->count() == 0) ? null : $taxonomies; - } - - /** - * @param $type - * - * @return ArrayCollection|null - */ - public function getTermsByType($type) - { - $terms = new ArrayCollection(); - $taxonomies = $this->getTaxonomiesByType($type); - - /** @var TermTaxonomy $taxonomy */ - if ($taxonomies !== null) { - foreach ($taxonomies as $taxonomy) { - $terms[] = $taxonomy->getTerm(); - } - } - - return ($terms->count() == 0) ? null : $terms; - } - - /** - * @return ArrayCollection - */ - public function getTags() - { - return $this->getTermsByType('post_tag'); - } - - /** - * @return ArrayCollection - */ - public function getCategories() - { - return $this->getTaxonomiesByType('category'); - } - - /** - * @return Term - */ - public function getCategory() - { - $taxonomy = $this->getCategories() ? $this->getCategories()->first() : null; - - return $taxonomy ? $taxonomy->getTerm() : null; - } } diff --git a/Entity/PostMeta.php b/Entity/PostMeta.php index 5ea18d8..e2a7cd6 100644 --- a/Entity/PostMeta.php +++ b/Entity/PostMeta.php @@ -10,6 +10,8 @@ namespace Ekino\WordpressBundle\Entity; +use Ekino\WordpressBundle\Model\PostMeta as PostMetaModel; + /** * Class PostMeta * @@ -17,94 +19,7 @@ * * @author Vincent Composieux */ -class PostMeta implements WordpressEntityInterface +class PostMeta extends PostMetaModel { - /** - * @var integer - */ - protected $id; - - /** - * @var Post - */ - protected $post; - - /** - * @var string - */ - protected $key; - - /** - * @var string - */ - protected $value; - - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $key - * - * @return PostMeta - */ - public function setKey($key) - { - $this->key = $key; - - return $this; - } - - /** - * @return string - */ - public function getKey() - { - return $this->key; - } - - /** - * @param Post $post - * - * @return PostMeta - */ - public function setPost(Post $post) - { - $this->post = $post; - - return $this; - } - - /** - * @return Post - */ - public function getPost() - { - return $this->post; - } - - /** - * @param string $value - * - * @return PostMeta - */ - public function setValue($value) - { - $this->value = $value; - - return $this; - } - /** - * @return string - */ - public function getValue() - { - return $this->value; - } } \ No newline at end of file diff --git a/Entity/Term.php b/Entity/Term.php index 256da74..6467a39 100644 --- a/Entity/Term.php +++ b/Entity/Term.php @@ -10,7 +10,7 @@ namespace Ekino\WordpressBundle\Entity; -use Doctrine\Common\Collections\ArrayCollection; +use Ekino\WordpressBundle\Model\Term as TermModel; /** * Class Term @@ -19,154 +19,7 @@ * * @author Vincent Composieux */ -class Term implements WordpressEntityInterface +class Term extends TermModel { - /** - * @var integer - */ - protected $id; - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $slug; - - /** - * @var integer - */ - protected $group; - - /** - * @var ArrayCollection - */ - protected $taxonomies; - - /** - * Constructor - */ - public function __construct() - { - $this->taxonomies = new ArrayCollection(); - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param int $group - * - * @return Term - */ - public function setGroup($group) - { - $this->group = $group; - - return $this; - } - - /** - * @return int - */ - public function getGroup() - { - return $this->group; - } - - /** - * @param string $slug - * - * @return Term - */ - public function setSlug($slug) - { - $this->slug = $slug; - - return $this; - } - - /** - * @return string - */ - public function getSlug() - { - return $this->slug; - } - - /** - * @param string $name - * - * @return Term - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param array $taxonomies - * - * @return Term - */ - public function setTaxonomies($taxonomies) - { - $this->taxonomies = $taxonomies; - - return $this; - } - - /** - * @return ArrayCollection - */ - public function getTaxonomies() - { - return $this->taxonomies; - } - - /** - * @param TermTaxonomy $taxonomy - * - * @return Term - */ - public function addTaxonomy(TermTaxonomy $taxonomy) - { - if (!$this->taxonomies->contains($taxonomy)) { - $this->taxonomies[] = $taxonomy; - } - - return $this; - } - - /** - * @param TermTaxonomy $taxonomy - * - * @return Term - */ - public function removeTaxonomy(TermTaxonomy $taxonomy) - { - if ($this->taxonomies->contains($taxonomy)) { - $this->taxonomies->remove($taxonomy); - } - - return $this; - } } \ No newline at end of file diff --git a/Entity/TermRelationships.php b/Entity/TermRelationships.php index 940a5fc..601940f 100644 --- a/Entity/TermRelationships.php +++ b/Entity/TermRelationships.php @@ -10,6 +10,8 @@ namespace Ekino\WordpressBundle\Entity; +use Ekino\WordpressBundle\Model\TermRelationships as TermRelationshipsModel; + /** * Class TermRelationships * @@ -17,81 +19,7 @@ * * @author Vincent Composieux */ -class TermRelationships implements WordpressEntityInterface +class TermRelationships extends TermRelationshipsModel { - /** - * @var TermTaxonomy - */ - protected $taxonomy; - - /** - * @var integer - */ - protected $termOrder; - - /** - * @var Post - */ - protected $post; - - /** - * @param Post $post - * - * @return TermRelationships - */ - public function setPost(Post $post) - { - $this->post = $post; - - return $this; - } - - /** - * @return Post - */ - public function getPost() - { - return $this->post; - } - - /** - * @param int $termOrder - * - * @return TermRelationships - */ - public function setTermOrder($termOrder) - { - $this->termOrder = $termOrder; - - return $this; - } - - /** - * @return int - */ - public function getTermOrder() - { - return $this->termOrder; - } - - /** - * @param TermTaxonomy $taxonomy - * - * @return TermRelationships - */ - public function setTaxonomy(TermTaxonomy $taxonomy) - { - $this->taxonomy = $taxonomy; - - return $this; - } - - /** - * @return TermTaxonomy - */ - public function getTaxonomy() - { - return $this->taxonomy; - } } \ No newline at end of file diff --git a/Entity/TermTaxonomy.php b/Entity/TermTaxonomy.php index 5193c8c..e3c4834 100644 --- a/Entity/TermTaxonomy.php +++ b/Entity/TermTaxonomy.php @@ -9,8 +9,8 @@ */ namespace Ekino\WordpressBundle\Entity; -use Doctrine\Common\Collections\ArrayCollection; +use Ekino\WordpressBundle\Model\TermTaxonomy as TermTaxonomyModel; /** * Class TermTaxonomy * @@ -18,193 +18,7 @@ * * @author Vincent Composieux */ -class TermTaxonomy implements WordpressEntityInterface +class TermTaxonomy extends TermTaxonomyModel { - /** - * @var integer - */ - protected $id; - - /** - * @var Term - */ - protected $term; - - /** - * @var string - */ - protected $taxonomy; - - /** - * @var string - */ - protected $description; - - /** - * @var TermTaxonomy - */ - protected $parent; - - /** - * @var ArrayCollection - */ - protected $relationships; - - /** - * @var integer - */ - protected $count; - - /** - * Constructor - */ - public function __construct() - { - $this->relationships = new ArrayCollection(); - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param int $count - * - * @return TermTaxonomy - */ - public function setCount($count) - { - $this->count = $count; - - return $this; - } - - /** - * @return int - */ - public function getCount() - { - return $this->count; - } - - /** - * @param string $description - * - * @return TermTaxonomy - */ - public function setDescription($description) - { - $this->description = $description; - - return $this; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param integer $parent - * - * @return TermTaxonomy - */ - public function setParent($parent) - { - $this->parent = $parent; - - return $this; - } - - /** - * @return integer - */ - public function getParent() - { - return $this->parent; - } - - /** - * @param string $taxonomy - * - * @return TermTaxonomy - */ - public function setTaxonomy($taxonomy) - { - $this->taxonomy = $taxonomy; - - return $this; - } - - /** - * @return string - */ - public function getTaxonomy() - { - return $this->taxonomy; - } - - /** - * @param Term $term - * - * @return TermTaxonomy - */ - public function setTerm(Term $term) - { - $this->term = $term; - - return $this; - } - - /** - * @return Term - */ - public function getTerm() - { - return $this->term; - } - - /** - * @return ArrayCollection - */ - public function getRelationships() - { - return $this->relationships; - } - - /** - * @param TermRelationships $relationship - * - * @return Term - */ - public function addRelationship(TermRelationships $relationship) - { - if (!$this->relationships->contains($relationship)) { - $this->relationships[] = $relationship; - } - - return $this; - } - - /** - * @param TermRelationships $relationship - * - * @return Term - */ - public function removeRelationship(TermRelationships $relationship) - { - if ($this->relationships->contains($relationship)) { - $this->relationships->remove($relationship); - } - - return $this; - } } \ No newline at end of file diff --git a/Entity/User.php b/Entity/User.php index 45af5f8..7846d19 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -10,9 +10,7 @@ namespace Ekino\WordpressBundle\Entity; -use Doctrine\Common\Collections\ArrayCollection; - -use Symfony\Component\Security\Core\User\UserInterface; +use Ekino\WordpressBundle\Model\User as UserModel; /** * Class User @@ -21,377 +19,7 @@ * * @author Vincent Composieux */ -class User implements UserInterface, WordpressEntityInterface +class User extends UserModel { - /** - * @var integer - */ - protected $id; - - /** - * @var string - */ - protected $login; - - /** - * @var string - */ - protected $pass; - - /** - * @var string - */ - protected $nicename; - - /** - * @var string - */ - protected $email; - - /** - * @var string - */ - protected $url; - - /** - * @var \DateTime - */ - protected $registered; - - /** - * @var string - */ - protected $activationKey; - - /** - * @var integer - */ - protected $status; - - /** - * @var string - */ - protected $displayName; - - /** - * @var ArrayCollection - */ - protected $metas; - - /** - * @var array - */ - protected $roles; - - - /** - * Constructor - */ - public function __construct() - { - $this->metas = new ArrayCollection(); - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $activationKey - * - * @return User - */ - public function setActivationKey($activationKey) - { - $this->activationKey = $activationKey; - - return $this; - } - - /** - * @return string - */ - public function getActivationKey() - { - return $this->activationKey; - } - - /** - * @param string $displayName - * - * @return User - */ - public function setDisplayName($displayName) - { - $this->displayName = $displayName; - - return $this; - } - - /** - * @return string - */ - public function getDisplayName() - { - return $this->displayName; - } - - /** - * @param string $email - * - * @return User - */ - public function setEmail($email) - { - $this->email = $email; - - return $this; - } - - /** - * @return string - */ - public function getEmail() - { - return $this->email; - } - - /** - * @param string $login - * - * @return User - */ - public function setLogin($login) - { - $this->login = $login; - - return $this; - } - - /** - * @return string - */ - public function getLogin() - { - return $this->login; - } - - /** - * @param string $nicename - * - * @return User - */ - public function setNicename($nicename) - { - $this->nicename = $nicename; - - return $this; - } - - /** - * @return string - */ - public function getNicename() - { - return $this->nicename; - } - - /** - * @param string $pass - * - * @return User - */ - public function setPass($pass) - { - $this->pass = $pass; - - return $this; - } - - /** - * @return string - */ - public function getPass() - { - return $this->pass; - } - - /** - * @param \DateTime $registered - * - * @return User - */ - public function setRegistered($registered) - { - $this->registered = $registered; - - return $this; - } - - /** - * @return \DateTime - */ - public function getRegistered() - { - return $this->registered; - } - - /** - * @param int $status - * - * @return User - */ - public function setStatus($status) - { - $this->status = $status; - - return $this; - } - - /** - * @return int - */ - public function getStatus() - { - return $this->status; - } - - /** - * @param string $url - * - * @return User - */ - public function setUrl($url) - { - $this->url = $url; - - return $this; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param ArrayCollection $metas - * - * @return User - */ - public function setMetas(ArrayCollection $metas) - { - $this->metas = $metas; - - return $this; - } - - /** - * Returns user meta value from a meta key name - * - * @param string $name - * - * @return string|null - */ - public function getMetaValue($name) - { - foreach ($this->getMetas() as $meta) { - if ($name == $meta->getKey()) { - return $meta->getValue(); - } - } - - return null; - } - - /** - * @return ArrayCollection - */ - public function getMetas() - { - return $this->metas; - } - - /** - * Sets user roles - * - * @param array|string $roles - * - * @return User - */ - public function setRoles($roles) - { - if (!is_array($roles)) { - $roles = array($roles); - } - - $this->roles = $roles; - - return $this; - } - - /** - * Sets Wordpress user roles by prefixing them - * - * @param array $roles An array of roles - * @param string $prefix A role prefix - * - * @return User - */ - public function setWordpressRoles(array $roles, $prefix = 'ROLE_WP_') - { - foreach ($roles as $key => $role) { - $roles[$key] = $prefix . strtoupper($role); - } - - $this->setRoles($roles); - - return $this; - } - - /** - * {@inheritdoc} - */ - public function getRoles() - { - return $this->roles ? $this->roles : array(); - } - - /** - * {@inheritdoc} - */ - public function getPassword() - { - return $this->getPass(); - } - - /** - * {@inheritdoc} - */ - public function getSalt() - { - return null; - } - - /** - * {@inheritdoc} - */ - public function getUsername() - { - return $this->getLogin(); - } - /** - * {@inheritdoc} - */ - public function eraseCredentials() - { - return $this; - } } \ No newline at end of file diff --git a/Entity/UserMeta.php b/Entity/UserMeta.php index 3c7ebfc..e5edea8 100644 --- a/Entity/UserMeta.php +++ b/Entity/UserMeta.php @@ -10,6 +10,7 @@ namespace Ekino\WordpressBundle\Entity; +use Ekino\WordpressBundle\Model\UserMeta as UserMetaModel; /** * Class UserMeta * @@ -17,94 +18,7 @@ * * @author Vincent Composieux */ -class UserMeta implements WordpressEntityInterface +class UserMeta extends UserMetaModel { - /** - * @var integer - */ - protected $id; - /** - * @var User - */ - protected $user; - - /** - * @var string - */ - protected $key; - - /** - * @var string - */ - protected $value; - - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $key - * - * @return UserMeta - */ - public function setKey($key) - { - $this->key = $key; - - return $this; - } - - /** - * @return string - */ - public function getKey() - { - return $this->key; - } - - /** - * @param User $user - * - * @return UserMeta - */ - public function setUser(User $user) - { - $this->user = $user; - - return $this; - } - - /** - * @return User - */ - public function getUser() - { - return $this->user; - } - - /** - * @param string $value - * - * @return UserMeta - */ - public function setValue($value) - { - $this->value = $value; - - return $this; - } - - /** - * @return string - */ - public function getValue() - { - return $this->value; - } } \ No newline at end of file diff --git a/Model/Comment.php b/Model/Comment.php new file mode 100644 index 0000000..557438e --- /dev/null +++ b/Model/Comment.php @@ -0,0 +1,385 @@ + + */ +abstract class Comment implements WordpressEntityInterface, WordpressContentInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var Post + */ + protected $post; + + /** + * @var string + */ + protected $author; + + /** + * @var string + */ + protected $authorEmail; + + /** + * @var string + */ + protected $authorUrl; + + /** + * @var string + */ + protected $authorIp; + + /** + * @var \DateTime + */ + protected $date; + + /** + * @var \DateTime + */ + protected $dateGmt; + + /** + * @var string + */ + protected $content; + + /** + * @var integer + */ + protected $karma; + + /** + * @var string + */ + protected $approved; + + /** + * @var string + */ + protected $agent; + + /** + * @var string + */ + protected $type; + + /** + * @var Comment + */ + protected $parent; + + /** + * @var User + */ + protected $user; + + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $agent + * + * @return Comment + */ + public function setAgent($agent) + { + $this->agent = $agent; + + return $this; + } + + /** + * @return string + */ + public function getAgent() + { + return $this->agent; + } + + /** + * @param string $approved + * + * @return Comment + */ + public function setApproved($approved) + { + $this->approved = $approved; + + return $this; + } + + /** + * @return string + */ + public function getApproved() + { + return $this->approved; + } + + /** + * @param string $author + * + * @return Comment + */ + public function setAuthor($author) + { + $this->author = $author; + + return $this; + } + + /** + * @return string + */ + public function getAuthor() + { + return $this->author; + } + + /** + * @param string $authorEmail + * + * @return Comment + */ + public function setAuthorEmail($authorEmail) + { + $this->authorEmail = $authorEmail; + + return $this; + } + + /** + * @return string + */ + public function getAuthorEmail() + { + return $this->authorEmail; + } + + /** + * @param string $authorIp + * + * @return Comment + */ + public function setAuthorIp($authorIp) + { + $this->authorIp = $authorIp; + + return $this; + } + + /** + * @return string + */ + public function getAuthorIp() + { + return $this->authorIp; + } + + /** + * @param string $authorUrl + * + * @return Comment + */ + public function setAuthorUrl($authorUrl) + { + $this->authorUrl = $authorUrl; + + return $this; + } + + /** + * @return string + */ + public function getAuthorUrl() + { + return $this->authorUrl; + } + + /** + * @param string $content + * + * @return Comment + */ + public function setContent($content) + { + $this->content = $content; + + return $this; + } + + /** + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * @param \DateTime $date + * + * @return Comment + */ + public function setDate($date) + { + $this->date = $date; + + return $this; + } + + /** + * @return \DateTime + */ + public function getDate() + { + return $this->date; + } + + /** + * @param \DateTime $dateGmt + * + * @return Comment + */ + public function setDateGmt($dateGmt) + { + $this->dateGmt = $dateGmt; + + return $this; + } + + /** + * @return \DateTime + */ + public function getDateGmt() + { + return $this->dateGmt; + } + + /** + * @param int $karma + * + * @return Comment + */ + public function setKarma($karma) + { + $this->karma = $karma; + + return $this; + } + + /** + * @return int + */ + public function getKarma() + { + return $this->karma; + } + + /** + * @param Comment $parent + * + * @return Comment + */ + public function setParent(Comment $parent) + { + $this->parent = $parent; + + return $this; + } + + /** + * @return Comment + */ + public function getParent() + { + return $this->parent; + } + + /** + * @param Post $post + * + * @return Comment + */ + public function setPost(Post $post) + { + $this->post = $post; + + return $this; + } + + /** + * @return Post + */ + public function getPost() + { + return $this->post; + } + + /** + * @param string $type + * + * @return Comment + */ + public function setType($type) + { + $this->type = $type; + + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param User $user + * + * @return Comment + */ + public function setUser(User $user) + { + $this->user = $user; + + return $this; + } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } +} \ No newline at end of file diff --git a/Model/CommentMeta.php b/Model/CommentMeta.php new file mode 100644 index 0000000..431ca27 --- /dev/null +++ b/Model/CommentMeta.php @@ -0,0 +1,110 @@ + + */ +abstract class CommentMeta implements WordpressEntityInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var Comment + */ + protected $comment; + + /** + * @var string + */ + protected $key; + + /** + * @var string + */ + protected $value; + + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param Comment $comment + * + * @return CommentMeta + */ + public function setComment(Comment $comment) + { + $this->comment = $comment; + + return $this; + } + + /** + * @return Comment + */ + public function getComment() + { + return $this->comment; + } + + /** + * @param string $key + * + * @return CommentMeta + */ + public function setKey($key) + { + $this->key = $key; + + return $this; + } + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @param string $value + * + * @return CommentMeta + */ + public function setValue($value) + { + $this->value = $value; + + return $this; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } +} \ No newline at end of file diff --git a/Model/Link.php b/Model/Link.php new file mode 100644 index 0000000..d532cb0 --- /dev/null +++ b/Model/Link.php @@ -0,0 +1,335 @@ + + */ +abstract class Link implements WordpressEntityInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var string + */ + protected $url; + + /** + * @var string + */ + protected $name; + + /** + * @var string + */ + protected $image; + + /** + * @var string + */ + protected $target; + + /** + * @var string + */ + protected $description; + + /** + * @var string + */ + protected $visible; + + /** + * @var integer + */ + protected $owner; + + /** + * @var integer + */ + protected $rating; + + /** + * @var \DateTime + */ + protected $updated; + + /** + * @var string + */ + protected $rel; + + /** + * @var string + */ + protected $notes; + + /** + * @var string + */ + protected $rss; + + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $description + * + * @return Link + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $image + * + * @return Link + */ + public function setImage($image) + { + $this->image = $image; + + return $this; + } + + /** + * @return string + */ + public function getImage() + { + return $this->image; + } + + /** + * @param string $name + * + * @return Link + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $notes + * + * @return Link + */ + public function setNotes($notes) + { + $this->notes = $notes; + + return $this; + } + + /** + * @return string + */ + public function getNotes() + { + return $this->notes; + } + + /** + * @param int $owner + * + * @return Link + */ + public function setOwner($owner) + { + $this->owner = $owner; + + return $this; + } + + /** + * @return int + */ + public function getOwner() + { + return $this->owner; + } + + /** + * @param int $rating + * + * @return Link + */ + public function setRating($rating) + { + $this->rating = $rating; + + return $this; + } + + /** + * @return int + */ + public function getRating() + { + return $this->rating; + } + + /** + * @param string $rel + * + * @return Link + */ + public function setRel($rel) + { + $this->rel = $rel; + + return $this; + } + + /** + * @return string + */ + public function getRel() + { + return $this->rel; + } + + /** + * @param string $rss + * + * @return Link + */ + public function setRss($rss) + { + $this->rss = $rss; + + return $this; + } + + /** + * @return string + */ + public function getRss() + { + return $this->rss; + } + + /** + * @param string $target + * + * @return Link + */ + public function setTarget($target) + { + $this->target = $target; + + return $this; + } + + /** + * @return string + */ + public function getTarget() + { + return $this->target; + } + + /** + * @param \DateTime $updated + * + * @return Link + */ + public function setUpdated($updated) + { + $this->updated = $updated; + + return $this; + } + + /** + * @return \DateTime + */ + public function getUpdated() + { + return $this->updated; + } + + /** + * @param string $url + * + * @return Link + */ + public function setUrl($url) + { + $this->url = $url; + + return $this; + } + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $visible + * + * @return Link + */ + public function setVisible($visible) + { + $this->visible = $visible; + + return $this; + } + + /** + * @return string + */ + public function getVisible() + { + return $this->visible; + } +} \ No newline at end of file diff --git a/Model/Option.php b/Model/Option.php new file mode 100644 index 0000000..99fe155 --- /dev/null +++ b/Model/Option.php @@ -0,0 +1,109 @@ + + */ +abstract class Option implements WordpressEntityInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var string + */ + protected $name; + + /** + * @var string + */ + protected $value; + + /** + * @var string + */ + protected $autoload; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $autoload + * + * @return Option + */ + public function setAutoload($autoload) + { + $this->autoload = $autoload; + + return $this; + } + + /** + * @return string + */ + public function getAutoload() + { + return $this->autoload; + } + + /** + * @param string $name + * + * @return Option + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $value + * + * @return Option + */ + public function setValue($value) + { + $this->value = $value; + + return $this; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } +} \ No newline at end of file diff --git a/Model/Post.php b/Model/Post.php new file mode 100644 index 0000000..f9fc44d --- /dev/null +++ b/Model/Post.php @@ -0,0 +1,822 @@ + + */ +abstract class Post implements WordpressEntityInterface, WordpressContentInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var User + */ + protected $author; + + /** + * @var \DateTime + */ + protected $date; + + /** + * @var \DateTime + */ + protected $dateGmt; + + /** + * @var string + */ + protected $content; + + /** + * @var string + */ + protected $title; + + /** + * @var string + */ + protected $excerpt; + + /** + * @var string + */ + protected $status; + + /** + * @var string + */ + protected $commentStatus; + + /** + * @var string + */ + protected $pingStatus; + + /** + * @var string + */ + protected $password; + + /** + * @var string + */ + protected $name; + + /** + * @var string + */ + protected $toPing; + + /** + * @var string + */ + protected $pinged; + + /** + * @var \DateTime + */ + protected $modified; + + /** + * @var \DateTime + */ + protected $modifiedGmt; + + /** + * @var string + */ + protected $contentFiltered; + + /** + * @var integer + */ + protected $parent = 0; + + /** + * @var string + */ + protected $guid; + + /** + * @var integer + */ + protected $menuOrder; + + /** + * @var string + */ + protected $type; + + /** + * @var string + */ + protected $mimeType; + + /** + * @var integer + */ + protected $commentCount; + + /** + * @var ArrayCollection + */ + protected $metas; + + /** + * @var ArrayCollection + */ + protected $comments; + + /** + * @var ArrayCollection + */ + protected $termRelationships; + + /** + * Constructor + */ + public function __construct() + { + $this->metas = new ArrayCollection(); + $this->comments = new ArrayCollection(); + $this->termRelationships = new ArrayCollection(); + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param User $author + * + * @return Post + */ + public function setAuthor(User $author) + { + $this->author = $author; + + return $this; + } + + /** + * @return User + */ + public function getAuthor() + { + return $this->author; + } + + /** + * @param int $commentCount + * + * @return Post + */ + public function setCommentCount($commentCount) + { + $this->commentCount = $commentCount; + + return $this; + } + + /** + * @return int + */ + public function getCommentCount() + { + return $this->commentCount; + } + + /** + * @param string $content + * + * @return Post + */ + public function setContent($content) + { + $this->content = $content; + + return $this; + } + + /** + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * @param string $contentFiltered + * + * @return Post + */ + public function setContentFiltered($contentFiltered) + { + $this->contentFiltered = $contentFiltered; + + return $this; + } + + /** + * @return string + */ + public function getContentFiltered() + { + return $this->contentFiltered; + } + + /** + * @param \DateTime $date + * + * @return Post + */ + public function setDate($date) + { + $this->date = $date; + + return $this; + } + + /** + * @return \DateTime + */ + public function getDate() + { + return $this->date; + } + + /** + * @param \DateTime $dateGmt + * + * @return Post + */ + public function setDateGmt($dateGmt) + { + $this->dateGmt = $dateGmt; + + return $this; + } + + /** + * @return \DateTime + */ + public function getDateGmt() + { + return $this->dateGmt; + } + + /** + * @param string $excerpt + * + * @return Post + */ + public function setExcerpt($excerpt) + { + $this->excerpt = $excerpt; + + return $this; + } + + /** + * @return string + */ + public function getExcerpt() + { + return $this->excerpt; + } + + /** + * @param string $guid + * + * @return Post + */ + public function setGuid($guid) + { + $this->guid = $guid; + + return $this; + } + + /** + * @return string + */ + public function getGuid() + { + return $this->guid; + } + + /** + * @param int $menuOrder + * + * @return Post + */ + public function setMenuOrder($menuOrder) + { + $this->menuOrder = $menuOrder; + + return $this; + } + + /** + * @return int + */ + public function getMenuOrder() + { + return $this->menuOrder; + } + + /** + * @param string $mimeType + * + * @return Post + */ + public function setMimeType($mimeType) + { + $this->mimeType = $mimeType; + + return $this; + } + + /** + * @return string + */ + public function getMimeType() + { + return $this->mimeType; + } + + /** + * @param \DateTime $modified + * + * @return Post + */ + public function setModified($modified) + { + $this->modified = $modified; + + return $this; + } + + /** + * @return \DateTime + */ + public function getModified() + { + return $this->modified; + } + + /** + * @param \DateTime $modifiedGmt + * + * @return Post + */ + public function setModifiedGmt($modifiedGmt) + { + $this->modifiedGmt = $modifiedGmt; + + return $this; + } + + /** + * @return \DateTime + */ + public function getModifiedGmt() + { + return $this->modifiedGmt; + } + + /** + * @param string $name + * + * @return Post + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param integer $parent + * + * @return Post + */ + public function setParent($parent) + { + $this->parent = $parent; + + return $this; + } + + /** + * @return integer + */ + public function getParent() + { + return $this->parent; + } + + /** + * @param string $password + * + * @return Post + */ + public function setPassword($password) + { + $this->password = $password; + + return $this; + } + + /** + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * @param string $status + * + * @return Post + */ + public function setStatus($status) + { + $this->status = $status; + + return $this; + } + + /** + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param string $commentStatus + * + * @return Post + */ + public function setCommentStatus($commentStatus) + { + $this->commentStatus = $commentStatus; + + return $this; + } + + /** + * @return string + */ + public function getCommentStatus() + { + return $this->commentStatus; + } + + /** + * @param string $pingStatus + * + * @return Post + */ + public function setPingStatus($pingStatus) + { + $this->pingStatus = $pingStatus; + + return $this; + } + + /** + * @return string + */ + public function getPingStatus() + { + return $this->pingStatus; + } + + /** + * @param string $pinged + * + * @return Post + */ + public function setPinged($pinged) + { + $this->pinged = $pinged; + + return $this; + } + + /** + * @return string + */ + public function getPinged() + { + return $this->pinged; + } + + /** + * @param string $title + * + * @return Post + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $toPing + * + * @return Post + */ + public function setToPing($toPing) + { + $this->toPing = $toPing; + + return $this; + } + + /** + * @return string + */ + public function getToPing() + { + return $this->toPing; + } + + /** + * @param string $type + * + * @return Post + */ + public function setType($type) + { + $this->type = $type; + + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param ArrayCollection $metas + * + * @return Post + */ + public function setMetas(ArrayCollection $metas) + { + $this->metas = $metas; + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getMetas() + { + return $this->metas; + } + + /** + * @param PostMeta $meta + * + * @return Post + */ + public function addMeta(PostMeta $meta) + { + $this->metas[] = $meta; + + return $this; + } + + /** + * @param PostMeta $meta + * + * @return Post + */ + public function removeMeta(PostMeta $meta) + { + if ($this->metas->contains($meta)) { + $this->metas->remove($meta); + } + + return $this; + } + + /** + * @param string $name + * + * @return \Doctrine\Common\Collections\Collection + */ + public function getMetaByKey($name) + { + $criteria = Criteria::create(); + $criteria->where(Criteria::expr()->eq('key', $name)); + + return $this->metas->matching($criteria); + } + + /** + * Returns user meta value from a meta key name + * + * @param string $name + * + * @return string|null + */ + public function getMetaValue($name) + { + /** @var PostMeta $meta */ + foreach ($this->getMetas() as $meta) { + if ($name == $meta->getKey()) { + return $meta->getValue(); + } + } + + return null; + } + + /** + * @return ArrayCollection + */ + public function getComments() + { + return $this->comments; + } + + /** + * @param Comment $comment + * + * @return Post + */ + public function addComment(Comment $comment) + { + if (!$this->comments->contains($comment)) { + $this->comments[] = $comment; + } + + return $this; + } + + /** + * @param Comment $comment + * + * @return Post + */ + public function removeComment(Comment $comment) + { + $this->comments->remove($comment); + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getTermRelationships() + { + return $this->termRelationships; + } + + /** + * @param TermRelationships $relationship + * + * @return Post + */ + public function addTermRelationship(TermRelationships $relationship) + { + $this->termRelationships[] = $relationship; + + return $this; + } + + /** + * @param TermRelationships $relationship + * + * @return Post + */ + public function removeTermRelationship(TermRelationships $relationship) + { + $this->termRelationships->remove($relationship); + + return $this; + } + + /** + * @param string $type + * + * @return ArrayCollection|null + */ + public function getTaxonomiesByType($type) + { + $taxonomies = new ArrayCollection(); + + /** @var TermRelationships $relationship */ + foreach ($this->getTermRelationships() as $relationship) { + if ($type === $relationship->getTaxonomy()->getTaxonomy()) { + $taxonomies[] = $relationship->getTaxonomy(); + } + } + + return ($taxonomies->count() == 0) ? null : $taxonomies; + } + + /** + * @param $type + * + * @return ArrayCollection|null + */ + public function getTermsByType($type) + { + $terms = new ArrayCollection(); + $taxonomies = $this->getTaxonomiesByType($type); + + /** @var TermTaxonomy $taxonomy */ + if ($taxonomies !== null) { + foreach ($taxonomies as $taxonomy) { + $terms[] = $taxonomy->getTerm(); + } + } + + return ($terms->count() == 0) ? null : $terms; + } + + /** + * @return ArrayCollection + */ + public function getTags() + { + return $this->getTermsByType('post_tag'); + } + + /** + * @return ArrayCollection + */ + public function getCategories() + { + return $this->getTaxonomiesByType('category'); + } + + /** + * @return Term + */ + public function getCategory() + { + $taxonomy = $this->getCategories() ? $this->getCategories()->first() : null; + + return $taxonomy ? $taxonomy->getTerm() : null; + } + +} diff --git a/Model/PostMeta.php b/Model/PostMeta.php new file mode 100644 index 0000000..a5d3552 --- /dev/null +++ b/Model/PostMeta.php @@ -0,0 +1,109 @@ + + */ +abstract class PostMeta implements WordpressEntityInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var Post + */ + protected $post; + + /** + * @var string + */ + protected $key; + + /** + * @var string + */ + protected $value; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $key + * + * @return PostMeta + */ + public function setKey($key) + { + $this->key = $key; + + return $this; + } + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @param Post $post + * + * @return PostMeta + */ + public function setPost(Post $post) + { + $this->post = $post; + + return $this; + } + + /** + * @return Post + */ + public function getPost() + { + return $this->post; + } + + /** + * @param string $value + * + * @return PostMeta + */ + public function setValue($value) + { + $this->value = $value; + + return $this; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } +} \ No newline at end of file diff --git a/Model/Term.php b/Model/Term.php new file mode 100644 index 0000000..8306d3f --- /dev/null +++ b/Model/Term.php @@ -0,0 +1,172 @@ + + */ +abstract class Term implements WordpressEntityInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var string + */ + protected $name; + + /** + * @var string + */ + protected $slug; + + /** + * @var integer + */ + protected $group; + + /** + * @var ArrayCollection + */ + protected $taxonomies; + + /** + * Constructor + */ + public function __construct() + { + $this->taxonomies = new ArrayCollection(); + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $group + * + * @return Term + */ + public function setGroup($group) + { + $this->group = $group; + + return $this; + } + + /** + * @return int + */ + public function getGroup() + { + return $this->group; + } + + /** + * @param string $slug + * + * @return Term + */ + public function setSlug($slug) + { + $this->slug = $slug; + + return $this; + } + + /** + * @return string + */ + public function getSlug() + { + return $this->slug; + } + + /** + * @param string $name + * + * @return Term + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param array $taxonomies + * + * @return Term + */ + public function setTaxonomies($taxonomies) + { + $this->taxonomies = $taxonomies; + + return $this; + } + + /** + * @return ArrayCollection + */ + public function getTaxonomies() + { + return $this->taxonomies; + } + + /** + * @param TermTaxonomy $taxonomy + * + * @return Term + */ + public function addTaxonomy(TermTaxonomy $taxonomy) + { + if (!$this->taxonomies->contains($taxonomy)) { + $this->taxonomies[] = $taxonomy; + } + + return $this; + } + + /** + * @param TermTaxonomy $taxonomy + * + * @return Term + */ + public function removeTaxonomy(TermTaxonomy $taxonomy) + { + if ($this->taxonomies->contains($taxonomy)) { + $this->taxonomies->remove($taxonomy); + } + + return $this; + } +} \ No newline at end of file diff --git a/Model/TermRelationships.php b/Model/TermRelationships.php new file mode 100644 index 0000000..dd84de3 --- /dev/null +++ b/Model/TermRelationships.php @@ -0,0 +1,96 @@ + + */ +abstract class TermRelationships implements WordpressEntityInterface +{ + /** + * @var TermTaxonomy + */ + protected $taxonomy; + + /** + * @var integer + */ + protected $termOrder; + + /** + * @var Post + */ + protected $post; + + /** + * @param Post $post + * + * @return TermRelationships + */ + public function setPost(Post $post) + { + $this->post = $post; + + return $this; + } + + /** + * @return Post + */ + public function getPost() + { + return $this->post; + } + + /** + * @param int $termOrder + * + * @return TermRelationships + */ + public function setTermOrder($termOrder) + { + $this->termOrder = $termOrder; + + return $this; + } + + /** + * @return int + */ + public function getTermOrder() + { + return $this->termOrder; + } + + /** + * @param TermTaxonomy $taxonomy + * + * @return TermRelationships + */ + public function setTaxonomy(TermTaxonomy $taxonomy) + { + $this->taxonomy = $taxonomy; + + return $this; + } + + /** + * @return TermTaxonomy + */ + public function getTaxonomy() + { + return $this->taxonomy; + } +} \ No newline at end of file diff --git a/Model/TermTaxonomy.php b/Model/TermTaxonomy.php new file mode 100644 index 0000000..1d53f3e --- /dev/null +++ b/Model/TermTaxonomy.php @@ -0,0 +1,211 @@ + + */ +abstract class TermTaxonomy implements WordpressEntityInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var Term + */ + protected $term; + + /** + * @var string + */ + protected $taxonomy; + + /** + * @var string + */ + protected $description; + + /** + * @var TermTaxonomy + */ + protected $parent; + + /** + * @var ArrayCollection + */ + protected $relationships; + + /** + * @var integer + */ + protected $count; + + /** + * Constructor + */ + public function __construct() + { + $this->relationships = new ArrayCollection(); + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $count + * + * @return TermTaxonomy + */ + public function setCount($count) + { + $this->count = $count; + + return $this; + } + + /** + * @return int + */ + public function getCount() + { + return $this->count; + } + + /** + * @param string $description + * + * @return TermTaxonomy + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param integer $parent + * + * @return TermTaxonomy + */ + public function setParent($parent) + { + $this->parent = $parent; + + return $this; + } + + /** + * @return integer + */ + public function getParent() + { + return $this->parent; + } + + /** + * @param string $taxonomy + * + * @return TermTaxonomy + */ + public function setTaxonomy($taxonomy) + { + $this->taxonomy = $taxonomy; + + return $this; + } + + /** + * @return string + */ + public function getTaxonomy() + { + return $this->taxonomy; + } + + /** + * @param Term $term + * + * @return TermTaxonomy + */ + public function setTerm(Term $term) + { + $this->term = $term; + + return $this; + } + + /** + * @return Term + */ + public function getTerm() + { + return $this->term; + } + + /** + * @return ArrayCollection + */ + public function getRelationships() + { + return $this->relationships; + } + + /** + * @param TermRelationships $relationship + * + * @return Term + */ + public function addRelationship(TermRelationships $relationship) + { + if (!$this->relationships->contains($relationship)) { + $this->relationships[] = $relationship; + } + + return $this; + } + + /** + * @param TermRelationships $relationship + * + * @return Term + */ + public function removeRelationship(TermRelationships $relationship) + { + if ($this->relationships->contains($relationship)) { + $this->relationships->remove($relationship); + } + + return $this; + } + +} \ No newline at end of file diff --git a/Model/User.php b/Model/User.php new file mode 100644 index 0000000..abf580f --- /dev/null +++ b/Model/User.php @@ -0,0 +1,397 @@ + + */ +abstract class User implements UserInterface, WordpressEntityInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var string + */ + protected $login; + + /** + * @var string + */ + protected $pass; + + /** + * @var string + */ + protected $nicename; + + /** + * @var string + */ + protected $email; + + /** + * @var string + */ + protected $url; + + /** + * @var \DateTime + */ + protected $registered; + + /** + * @var string + */ + protected $activationKey; + + /** + * @var integer + */ + protected $status; + + /** + * @var string + */ + protected $displayName; + + /** + * @var ArrayCollection + */ + protected $metas; + + /** + * @var array + */ + protected $roles; + + + /** + * Constructor + */ + public function __construct() + { + $this->metas = new ArrayCollection(); + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $activationKey + * + * @return User + */ + public function setActivationKey($activationKey) + { + $this->activationKey = $activationKey; + + return $this; + } + + /** + * @return string + */ + public function getActivationKey() + { + return $this->activationKey; + } + + /** + * @param string $displayName + * + * @return User + */ + public function setDisplayName($displayName) + { + $this->displayName = $displayName; + + return $this; + } + + /** + * @return string + */ + public function getDisplayName() + { + return $this->displayName; + } + + /** + * @param string $email + * + * @return User + */ + public function setEmail($email) + { + $this->email = $email; + + return $this; + } + + /** + * @return string + */ + public function getEmail() + { + return $this->email; + } + + /** + * @param string $login + * + * @return User + */ + public function setLogin($login) + { + $this->login = $login; + + return $this; + } + + /** + * @return string + */ + public function getLogin() + { + return $this->login; + } + + /** + * @param string $nicename + * + * @return User + */ + public function setNicename($nicename) + { + $this->nicename = $nicename; + + return $this; + } + + /** + * @return string + */ + public function getNicename() + { + return $this->nicename; + } + + /** + * @param string $pass + * + * @return User + */ + public function setPass($pass) + { + $this->pass = $pass; + + return $this; + } + + /** + * @return string + */ + public function getPass() + { + return $this->pass; + } + + /** + * @param \DateTime $registered + * + * @return User + */ + public function setRegistered($registered) + { + $this->registered = $registered; + + return $this; + } + + /** + * @return \DateTime + */ + public function getRegistered() + { + return $this->registered; + } + + /** + * @param int $status + * + * @return User + */ + public function setStatus($status) + { + $this->status = $status; + + return $this; + } + + /** + * @return int + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param string $url + * + * @return User + */ + public function setUrl($url) + { + $this->url = $url; + + return $this; + } + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param ArrayCollection $metas + * + * @return User + */ + public function setMetas(ArrayCollection $metas) + { + $this->metas = $metas; + + return $this; + } + + /** + * Returns user meta value from a meta key name + * + * @param string $name + * + * @return string|null + */ + public function getMetaValue($name) + { + foreach ($this->getMetas() as $meta) { + if ($name == $meta->getKey()) { + return $meta->getValue(); + } + } + + return null; + } + + /** + * @return ArrayCollection + */ + public function getMetas() + { + return $this->metas; + } + + /** + * Sets user roles + * + * @param array|string $roles + * + * @return User + */ + public function setRoles($roles) + { + if (!is_array($roles)) { + $roles = array($roles); + } + + $this->roles = $roles; + + return $this; + } + + /** + * Sets Wordpress user roles by prefixing them + * + * @param array $roles An array of roles + * @param string $prefix A role prefix + * + * @return User + */ + public function setWordpressRoles(array $roles, $prefix = 'ROLE_WP_') + { + foreach ($roles as $key => $role) { + $roles[$key] = $prefix . strtoupper($role); + } + + $this->setRoles($roles); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getRoles() + { + return $this->roles ? $this->roles : array(); + } + + /** + * {@inheritdoc} + */ + public function getPassword() + { + return $this->getPass(); + } + + /** + * {@inheritdoc} + */ + public function getSalt() + { + return null; + } + + /** + * {@inheritdoc} + */ + public function getUsername() + { + return $this->getLogin(); + } + + /** + * {@inheritdoc} + */ + public function eraseCredentials() + { + return $this; + } +} \ No newline at end of file diff --git a/Model/UserMeta.php b/Model/UserMeta.php new file mode 100644 index 0000000..95d8941 --- /dev/null +++ b/Model/UserMeta.php @@ -0,0 +1,109 @@ + + */ +abstract class UserMeta implements WordpressEntityInterface +{ + /** + * @var integer + */ + protected $id; + + /** + * @var User + */ + protected $user; + + /** + * @var string + */ + protected $key; + + /** + * @var string + */ + protected $value; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $key + * + * @return UserMeta + */ + public function setKey($key) + { + $this->key = $key; + + return $this; + } + + /** + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * @param User $user + * + * @return UserMeta + */ + public function setUser(User $user) + { + $this->user = $user; + + return $this; + } + + /** + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * @param string $value + * + * @return UserMeta + */ + public function setValue($value) + { + $this->value = $value; + + return $this; + } + + /** + * @return string + */ + public function getValue() + { + return $this->value; + } +} \ No newline at end of file diff --git a/Entity/WordpressContentInterface.php b/Model/WordpressContentInterface.php similarity index 80% rename from Entity/WordpressContentInterface.php rename to Model/WordpressContentInterface.php index 85749a8..986301e 100644 --- a/Entity/WordpressContentInterface.php +++ b/Model/WordpressContentInterface.php @@ -1,6 +1,6 @@ boot(); // Add Symfony container as a global variable to be used in Wordpress $sfContainer = $sfKernel->getContainer(); + +if (true === $sfContainer->getParameter('kernel.debug', false)) { + Debug::enable(); +} + $sfContainer->enterScope('request'); symfony($sfContainer); @@ -257,4 +261,4 @@ class LanguageController extends Controller return $this->container->getParameter('ekino.wordpress.i18n_cookie_name'); } } -``` \ No newline at end of file +``` diff --git a/Resources/config/doctrine/Comment.orm.xml b/Resources/config/doctrine/Comment.orm.xml index 0f4ff14..42fc90d 100644 --- a/Resources/config/doctrine/Comment.orm.xml +++ b/Resources/config/doctrine/Comment.orm.xml @@ -1,37 +1,21 @@ - + + + + + + - + + + + - - - - - - - - - - - - - - - - - + - - - - - diff --git a/Resources/config/doctrine/CommentMeta.orm.xml b/Resources/config/doctrine/CommentMeta.orm.xml index e049bb2..2bdab0c 100644 --- a/Resources/config/doctrine/CommentMeta.orm.xml +++ b/Resources/config/doctrine/CommentMeta.orm.xml @@ -5,15 +5,20 @@ repository-class="Ekino\WordpressBundle\Repository\CommentMetaRepository" change-tracking-policy="DEFERRED_IMPLICIT"> - + + + + + + + + + - - - - + diff --git a/Resources/config/doctrine/Link.orm.xml b/Resources/config/doctrine/Link.orm.xml index e3fac87..2b47f07 100644 --- a/Resources/config/doctrine/Link.orm.xml +++ b/Resources/config/doctrine/Link.orm.xml @@ -5,22 +5,20 @@ repository-class="Ekino\WordpressBundle\Repository\CommentMetaRepository" change-tracking-policy="DEFERRED_IMPLICIT"> - + + + + + + + + + - - - - - - - - - - - - - + + + diff --git a/Resources/config/doctrine/Option.orm.xml b/Resources/config/doctrine/Option.orm.xml index d6d07bd..de0333e 100644 --- a/Resources/config/doctrine/Option.orm.xml +++ b/Resources/config/doctrine/Option.orm.xml @@ -5,13 +5,11 @@ repository-class="Ekino\WordpressBundle\Repository\OptionRepository" change-tracking-policy="DEFERRED_IMPLICIT"> - + + + + - - - - - diff --git a/Resources/config/doctrine/Post.orm.xml b/Resources/config/doctrine/Post.orm.xml index 760c428..9fb50f7 100644 --- a/Resources/config/doctrine/Post.orm.xml +++ b/Resources/config/doctrine/Post.orm.xml @@ -5,41 +5,26 @@ repository-class="Ekino\WordpressBundle\Repository\PostRepository" change-tracking-policy="DEFERRED_IMPLICIT"> - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/Resources/config/doctrine/PostMeta.orm.xml b/Resources/config/doctrine/PostMeta.orm.xml index 7b8d196..9e6f457 100644 --- a/Resources/config/doctrine/PostMeta.orm.xml +++ b/Resources/config/doctrine/PostMeta.orm.xml @@ -5,15 +5,20 @@ repository-class="Ekino\WordpressBundle\Repository\PostMetaRepository" change-tracking-policy="DEFERRED_IMPLICIT"> - + + + + + + + + + - - - - + diff --git a/Resources/config/doctrine/Term.orm.xml b/Resources/config/doctrine/Term.orm.xml index 8b3f972..ea41a08 100644 --- a/Resources/config/doctrine/Term.orm.xml +++ b/Resources/config/doctrine/Term.orm.xml @@ -5,15 +5,18 @@ repository-class="Ekino\WordpressBundle\Repository\TermRepository" change-tracking-policy="DEFERRED_IMPLICIT"> - + + + + + + + + + - - - - - diff --git a/Resources/config/doctrine/TermRelationships.orm.xml b/Resources/config/doctrine/TermRelationships.orm.xml index 2cb5c84..42f93f9 100644 --- a/Resources/config/doctrine/TermRelationships.orm.xml +++ b/Resources/config/doctrine/TermRelationships.orm.xml @@ -8,8 +8,6 @@ - - diff --git a/Resources/config/doctrine/TermTaxonomy.orm.xml b/Resources/config/doctrine/TermTaxonomy.orm.xml index 0a697b7..252e3d0 100644 --- a/Resources/config/doctrine/TermTaxonomy.orm.xml +++ b/Resources/config/doctrine/TermTaxonomy.orm.xml @@ -5,21 +5,25 @@ repository-class="Ekino\WordpressBundle\Repository\TermTaxonomyRepository" change-tracking-policy="DEFERRED_IMPLICIT"> - + + + + + + + + + + + + - - - - + - + - - - diff --git a/Resources/config/doctrine/User.orm.xml b/Resources/config/doctrine/User.orm.xml index 19e7646..7b13753 100644 --- a/Resources/config/doctrine/User.orm.xml +++ b/Resources/config/doctrine/User.orm.xml @@ -5,20 +5,19 @@ repository-class="Ekino\WordpressBundle\Repository\UserRepository" change-tracking-policy="DEFERRED_IMPLICIT"> - + + + + + + + + + + - - - - - - - - - - diff --git a/Resources/config/doctrine/UserMeta.orm.xml b/Resources/config/doctrine/UserMeta.orm.xml index 8c7fefc..bcc1905 100644 --- a/Resources/config/doctrine/UserMeta.orm.xml +++ b/Resources/config/doctrine/UserMeta.orm.xml @@ -5,13 +5,18 @@ repository-class="Ekino\WordpressBundle\Repository\UserMetaRepository" change-tracking-policy="DEFERRED_IMPLICIT"> + + + + + + + + - - - diff --git a/Resources/config/doctrine/model/Comment.orm.xml b/Resources/config/doctrine/model/Comment.orm.xml new file mode 100644 index 0000000..c050799 --- /dev/null +++ b/Resources/config/doctrine/model/Comment.orm.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/config/doctrine/model/CommentMeta.orm.xml b/Resources/config/doctrine/model/CommentMeta.orm.xml new file mode 100644 index 0000000..3b122da --- /dev/null +++ b/Resources/config/doctrine/model/CommentMeta.orm.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Resources/config/doctrine/model/Link.orm.xml b/Resources/config/doctrine/model/Link.orm.xml new file mode 100644 index 0000000..22ad646 --- /dev/null +++ b/Resources/config/doctrine/model/Link.orm.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/config/doctrine/model/Option.orm.xml b/Resources/config/doctrine/model/Option.orm.xml new file mode 100644 index 0000000..7c01ccb --- /dev/null +++ b/Resources/config/doctrine/model/Option.orm.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/Resources/config/doctrine/model/Post.orm.xml b/Resources/config/doctrine/model/Post.orm.xml new file mode 100644 index 0000000..1499d44 --- /dev/null +++ b/Resources/config/doctrine/model/Post.orm.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/config/doctrine/model/PostMeta.orm.xml b/Resources/config/doctrine/model/PostMeta.orm.xml new file mode 100644 index 0000000..5cd5e97 --- /dev/null +++ b/Resources/config/doctrine/model/PostMeta.orm.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Resources/config/doctrine/model/Term.orm.xml b/Resources/config/doctrine/model/Term.orm.xml new file mode 100644 index 0000000..8c2b38c --- /dev/null +++ b/Resources/config/doctrine/model/Term.orm.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + diff --git a/Resources/config/doctrine/model/TermRelationships.orm.xml b/Resources/config/doctrine/model/TermRelationships.orm.xml new file mode 100644 index 0000000..fa93832 --- /dev/null +++ b/Resources/config/doctrine/model/TermRelationships.orm.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Resources/config/doctrine/model/TermTaxonomy.orm.xml b/Resources/config/doctrine/model/TermTaxonomy.orm.xml new file mode 100644 index 0000000..d720de4 --- /dev/null +++ b/Resources/config/doctrine/model/TermTaxonomy.orm.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/Resources/config/doctrine/model/User.orm.xml b/Resources/config/doctrine/model/User.orm.xml new file mode 100644 index 0000000..71c119e --- /dev/null +++ b/Resources/config/doctrine/model/User.orm.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Resources/config/doctrine/model/UserMeta.orm.xml b/Resources/config/doctrine/model/UserMeta.orm.xml new file mode 100644 index 0000000..7a65ae1 --- /dev/null +++ b/Resources/config/doctrine/model/UserMeta.orm.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/Resources/config/orm.xml b/Resources/config/orm.xml index 5fed096..0757f49 100644 --- a/Resources/config/orm.xml +++ b/Resources/config/orm.xml @@ -4,61 +4,86 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> + + Ekino\WordpressBundle\Entity\Comment + Ekino\WordpressBundle\Entity\CommentMeta + Ekino\WordpressBundle\Entity\Link + Ekino\WordpressBundle\Entity\Option + Ekino\WordpressBundle\Entity\Post + Ekino\WordpressBundle\Entity\PostMeta + Ekino\WordpressBundle\Entity\Term + Ekino\WordpressBundle\Entity\TermRelationships + Ekino\WordpressBundle\Entity\TermTaxonomy + Ekino\WordpressBundle\Entity\User + Ekino\WordpressBundle\Entity\UserMeta + + Ekino\WordpressBundle\Manager\CommentManager + Ekino\WordpressBundle\Manager\CommentMetaManager + Ekino\WordpressBundle\Manager\LinkManager + Ekino\WordpressBundle\Manager\OptionManager + Ekino\WordpressBundle\Manager\PostManager + Ekino\WordpressBundle\Manager\PostMetaManager + Ekino\WordpressBundle\Manager\TermManager + Ekino\WordpressBundle\Manager\TermRelationshipsManager + Ekino\WordpressBundle\Manager\TermTaxonomyManager + Ekino\WordpressBundle\Manager\UserManager + Ekino\WordpressBundle\Manager\UserMetaManager + - + - Ekino\WordpressBundle\Entity\Comment + %ekino.wordpress.entity.comment.class% - + - Ekino\WordpressBundle\Entity\CommentMeta + %ekino.wordpress.entity.comment_meta.class% - + - Ekino\WordpressBundle\Entity\Link + %ekino.wordpress.entity.link.class% - + - Ekino\WordpressBundle\Entity\Option + %ekino.wordpress.entity.option.class% - + - Ekino\WordpressBundle\Entity\Post + %ekino.wordpress.entity.post.class% - + - Ekino\WordpressBundle\Entity\PostMeta + %ekino.wordpress.entity.post_meta.class% - + - Ekino\WordpressBundle\Entity\Term + %ekino.wordpress.entity.term.class% - + - Ekino\WordpressBundle\Entity\TermRelationships + %ekino.wordpress.entity.term_relationships.class% - + - Ekino\WordpressBundle\Entity\TermTaxonomy + %ekino.wordpress.entity.term_taxonomy.class% - + - Ekino\WordpressBundle\Entity\User + %ekino.wordpress.entity.user.class% - + - Ekino\WordpressBundle\Entity\UserMeta + %ekino.wordpress.entity.user_meta.class% diff --git a/Subscriber/TablePrefixSubscriber.php b/Subscriber/TablePrefixSubscriber.php index 8211875..b164b03 100644 --- a/Subscriber/TablePrefixSubscriber.php +++ b/Subscriber/TablePrefixSubscriber.php @@ -63,7 +63,7 @@ public function loadClassMetadata(LoadClassMetadataEventArgs $args) return; } - if ($classMetadata->getReflectionClass()->implementsInterface('Ekino\\WordpressBundle\\Entity\\WordpressEntityInterface')) { + if ($classMetadata->getReflectionClass()->implementsInterface('Ekino\\WordpressBundle\\Model\\WordpressEntityInterface')) { $classMetadata->setPrimaryTable(array('name' => $this->prefix . $classMetadata->getTableName())); foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { diff --git a/Tests/DependencyInjection/Compiler/RegisterMappingsPassTest.php b/Tests/DependencyInjection/Compiler/RegisterMappingsPassTest.php new file mode 100644 index 0000000..4fd98ee --- /dev/null +++ b/Tests/DependencyInjection/Compiler/RegisterMappingsPassTest.php @@ -0,0 +1,197 @@ +driver = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->disableOriginalConstructor()->getMock(); + $this->driverPattern = 'doctrine.orm.%s_metadata_driver'; + $this->namespaces = array( + 'Resources/config/doctrine/model' => 'Ekino\WordpressBundle\Model', + ); + $this->enabledParameter = 'ekino_wordpress.backend_type_orm'; + $this->fallbackManagerParameter = 'doctrine.default_entity_manager'; + + + $this->compilerPass = new RegisterMappingsPass( + $this->driver, + $this->driverPattern, + $this->namespaces, + $this->enabledParameter, + $this->fallbackManagerParameter + ); + } + + public function testProcessNoParameter() + { + $containerBuilder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->disableOriginalConstructor()->getMock(); + + $containerBuilder->expects($this->once()) + ->method('hasParameter') + ->with($this->equalTo($this->enabledParameter)) + ->will($this->returnValue(false)); + + $containerBuilder->expects($this->never()) + ->method('getDefinition'); + + $this->compilerPass->process($containerBuilder); + } + + public function testProcessNoChainDriver() + { + $containerBuilder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->disableOriginalConstructor()->getMock(); + + + $containerBuilder->expects($this->exactly(3)) + ->method('hasParameter') + ->will($this->returnCallback(array($this, 'validateNoChainDriverServiceName'))); + + $containerBuilder->expects($this->never()) + ->method('getDefinition'); + + $this->setExpectedException('Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException'); + $this->compilerPass->process($containerBuilder); + } + + public function testProcessEkinoChainDriver() + { + $containerBuilder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->disableOriginalConstructor()->getMock(); + $driver = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->disableOriginalConstructor()->getMock(); + + $containerBuilder->expects($this->exactly(2)) + ->method('hasParameter') + ->will($this->returnCallback(array($this, 'validateNoChainDriverEkinoServiceName'))); + $driverTestName = 'test'; + $containerBuilder->expects($this->once()) + ->method('getParameter') + ->with($this->equalTo('ekino_wordpress.model_manager_name')) + ->will($this->returnValue($driverTestName)); + $containerBuilder->expects($this->once()) + ->method('getDefinition') + ->with($this->equalTo('doctrine.orm.test_metadata_driver')) + ->will($this->returnValue($driver)); + + $driver->expects($this->once()) + ->method('addMethodCall') + ->with($this->equalTo('addDriver'), $this->equalTo(array($this->driver, 'Ekino\WordpressBundle\Model'))); + + $containerBuilder->expects($this->once()) + ->method('getDefinition') + ->with($this->equalTo('doctrine.orm.test_metadata_driver')); + + $this->compilerPass->process($containerBuilder); + } + + public function testProcessDefaultChainDriver() + { + $containerBuilder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->disableOriginalConstructor()->getMock(); + $driver = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->disableOriginalConstructor()->getMock(); + + $containerBuilder->expects($this->exactly(3)) + ->method('hasParameter') + ->will($this->returnCallback(array($this, 'validateDefaultServiceName'))); + $driverTestName = 'test'; + $containerBuilder->expects($this->once()) + ->method('getParameter') + ->with($this->equalTo('doctrine.default_entity_manager')) + ->will($this->returnValue($driverTestName)); + $containerBuilder->expects($this->once()) + ->method('getDefinition') + ->with($this->equalTo('doctrine.orm.test_metadata_driver')) + ->will($this->returnValue($driver)); + + $driver->expects($this->once()) + ->method('addMethodCall') + ->with($this->equalTo('addDriver'), $this->equalTo(array($this->driver, 'Ekino\WordpressBundle\Model'))); + + $containerBuilder->expects($this->once()) + ->method('getDefinition') + ->with($this->equalTo('doctrine.orm.test_metadata_driver')); + + $this->compilerPass->process($containerBuilder); + } + + public function testcreateOrmMappingDriver() + { + $result = RegisterMappingsPass::createOrmMappingDriver($this->namespaces); + + $this->assertInstanceOf('Ekino\WordpressBundle\DependencyInjection\Compiler\RegisterMappingsPass', $result); + } + + /** + * @param string $parameterName + * + * @return bool + */ + public function validateNoChainDriverServiceName($parameterName) + { + if ($parameterName == $this->enabledParameter) { + return true; + } + + if ($parameterName == 'ekino_wordpress.model_manager_name') { + return false; + } + + if ($parameterName == $this->fallbackManagerParameter) { + return false; + } + + $this->fail(sprintf('Invalid parameter name : "%s"', $parameterName)); + } + + /** + * @param string $parameterName + * + * @return bool + */ + public function validateNoChainDriverEkinoServiceName($parameterName) + { + if ($parameterName == $this->enabledParameter) { + return true; + } + + if ($parameterName == 'ekino_wordpress.model_manager_name') { + return true; + } + + $this->fail(sprintf('Invalid parameter name : "%s"', $parameterName)); + } + + /** + * @param string $parameterName + * + * @return bool + */ + public function validateDefaultServiceName($parameterName) + { + if ($parameterName == $this->enabledParameter) { + return true; + } + + if ($parameterName == 'ekino_wordpress.model_manager_name') { + return false; + } + + if ($parameterName == $this->fallbackManagerParameter) { + return true; + } + + $this->fail(sprintf('Invalid parameter name : "%s"', $parameterName)); + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index cb886be..2f702a5 100755 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ ], "require": { "php": ">=5.3.2", - "symfony/framework-bundle": "~2.1", - "symfony/security-bundle": "~2.1", + "symfony/framework-bundle": "~2.2", + "symfony/security-bundle": "~2.2", "symfony/monolog-bundle": "~2.2", "doctrine/doctrine-bundle": "~1.0", "doctrine/orm": "~2.2"