Skip to content

Commit

Permalink
Merge pull request #855 from doctrine/internally-use-attributes
Browse files Browse the repository at this point in the history
convert provided documents to attributes instead of annotations
  • Loading branch information
dbu authored Dec 3, 2023
2 parents 4c4cb4d + fb19358 commit 552d4a3
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 106 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
1.x
===

1.8.1 (unreleased)
------------------

* Convert provided documents to use attributes instead of annotations.

1.8.0
-----

Expand Down
23 changes: 11 additions & 12 deletions lib/Doctrine/ODM/PHPCR/Document/AbstractFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,38 @@
namespace Doctrine\ODM\PHPCR\Document;

use Doctrine\ODM\PHPCR\HierarchyInterface;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as ODM;

/**
* This class represents an abstract "file"
*
* @PHPCRODM\MappedSuperclass(mixins="mix:created")
*/
#[ODM\MappedSuperclass(mixins: ['mix:created'])]
abstract class AbstractFile implements HierarchyInterface
{
/** @PHPCRODM\Id(strategy="parent") */
#[ODM\Id(strategy: 'parent')]
protected $id;

/** @PHPCRODM\Node */
#[ODM\Node]
protected $node;

/** @PHPCRODM\Nodename */
#[ODM\Nodename]
protected $nodename;

/** @PHPCRODM\ParentDocument */
#[ODM\ParentDocument]
protected $parent;

/** @PHPCRODM\Field(type="date", property="jcr:created") */
#[ODM\Field(property: 'jcr:created', type: 'date')]
protected $created;

/** @PHPCRODM\Field(type="string", property="jcr:createdBy") */
#[ODM\Field(property: 'jcr:createdBy', type: 'string')]
protected $createdBy;

/**
* Set the id (the PHPCR path).
*
* @param string $id of the node
*
* @return $this
* @return self
*/
public function setId($id)
{
Expand Down Expand Up @@ -86,7 +85,7 @@ public function getNodename()
*
* @param string $name the name of the file
*
* @return $this
* @return self
*/
public function setNodename($name)
{
Expand Down Expand Up @@ -121,7 +120,7 @@ public function getParent()
* @param object $parent Document that is the parent of this node. Could be
* a Folder or otherwise resolve to nt:folder
*
* @return $this
* @return self
*/
public function setParentDocument($parent)
{
Expand Down
19 changes: 9 additions & 10 deletions lib/Doctrine/ODM/PHPCR/Document/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@
namespace Doctrine\ODM\PHPCR\Document;

use Doctrine\ODM\PHPCR\Exception\RuntimeException;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as ODM;

/**
* This class represents a JCR file, aka nt:file.
*
* @see http://wiki.apache.org/jackrabbit/nt:file
*
* @PHPCRODM\Document(nodeType="nt:file", mixins={}, referenceable=true)
*/
#[ODM\Document(nodeType: 'nt:file', mixins: [], referenceable: true)]
class File extends AbstractFile
{
/**
* @var resource
* @PHPCRODM\Child(nodeName="jcr:content", cascade="all")
* @var Resource
*/
#[ODM\Child(nodeName: 'jcr:content', cascade: 'all')]
protected $content;

/**
Expand All @@ -45,7 +44,7 @@ class File extends AbstractFile
*
* @throws RuntimeException if the filename does not point to a file that can be read
*
* @return $this
* @return self
*/
public function setFileContentFromFilesystem($filename)
{
Expand Down Expand Up @@ -74,9 +73,9 @@ public function setFileContentFromFilesystem($filename)
/**
* Set the content for this file from the given Resource.
*
* @param resource $content
* @param Resource $content
*
* @return $this
* @return self
*/
public function setContent(Resource $content)
{
Expand Down Expand Up @@ -107,7 +106,7 @@ public function getContent()
*
* @param resource|string $content the content for the file
*
* @return $this
* @return self
*/
public function setFileContent($content)
{
Expand All @@ -129,7 +128,7 @@ public function setFileContent($content)
/**
* Get a stream for the content of this file.
*
* @return stream the content for the file
* @return resource the content for the file
*/
public function getFileContentAsStream()
{
Expand Down
13 changes: 6 additions & 7 deletions lib/Doctrine/ODM/PHPCR/Document/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\PHPCR\HierarchyInterface;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as ODM;

/**
* This class represents a Folder in the repository, aka nt:folder
Expand All @@ -31,21 +31,20 @@
*
* To add files or folders to a folder, create the new File/Folder and set
* this document as parent, then persist the new File/Folder.
*
* @PHPCRODM\Document(nodeType="nt:folder", mixins={})
*/
#[ODM\Document(nodeType: 'nt:folder', mixins: [])]
class Folder extends AbstractFile
{
/**
* @var ArrayCollection
* @PHPCRODM\Children(cascade="all")
*/
#[ODM\Children(cascade: 'all')]
protected $children;

/**
* @var AbstractFile
* @PHPCRODM\Child(cascade="all")
*/
#[ODM\Child(cascade: 'all')]
protected $child;

/**
Expand All @@ -63,7 +62,7 @@ public function getChildren()
*
* @param $children ArrayCollection
*
* @return $this
* @return self
*/
public function setChildren(ArrayCollection $children)
{
Expand All @@ -78,7 +77,7 @@ public function setChildren(ArrayCollection $children)
*
* @param $child HierarchyInterface
*
* @return $this
* @return self
*/
public function addChild(HierarchyInterface $child)
{
Expand Down
31 changes: 15 additions & 16 deletions lib/Doctrine/ODM/PHPCR/Document/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,46 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCRODM;
use Doctrine\ODM\PHPCR\Mapping\Attributes as ODM;
use PHPCR\NodeInterface;

/**
* This class represents an arbitrary node
*
* It is used as a default document, for example with the ParentDocument annotation.
* You can not use this to create nodes as it has no type annotation.
*
* @PHPCRODM\Document()
*/
#[ODM\Document]
class Generic
{
/** @PHPCRODM\Id(strategy="parent") */
#[ODM\Id(strategy: 'parent')]
protected $id;

/** @PHPCRODM\Node */
#[ODM\Node]
protected $node;

/** @PHPCRODM\Nodename */
#[ODM\Nodename]
protected $nodename;

/** @PHPCRODM\ParentDocument */
#[ODM\ParentDocument]
protected $parent;

/**
* @var Collection
* @PHPCRODM\Children
*/
#[ODM\Children]
protected $children;

/**
* @var Collection
* @PHPCRODM\MixedReferrers
*/
#[ODM\MixedReferrers]
protected $referrers;

/**
* Id (path) of this document
*
* @return string the id
* @return string
*/
public function getId()
{
Expand Down Expand Up @@ -93,7 +92,7 @@ public function getNodename()
*
* @param string $name the name of the document
*
* @return $this
* @return self
*/
public function setNodename($name)
{
Expand Down Expand Up @@ -127,7 +126,7 @@ public function getParent()
*
* @param object $parent Document that is the parent of this node..
*
* @return $this
* @return self
*/
public function setParentDocument($parent)
{
Expand Down Expand Up @@ -164,7 +163,7 @@ public function getChildren()
*
* @param $children ArrayCollection
*
* @return $this
* @return self
*/
public function setChildren(ArrayCollection $children)
{
Expand All @@ -178,7 +177,7 @@ public function setChildren(ArrayCollection $children)
*
* @param $child
*
* @return $this
* @return self
*/
public function addChild($child)
{
Expand Down Expand Up @@ -209,7 +208,7 @@ public function getReferrers()
*
* @param $referrers ArrayCollection
*
* @return $this;
* @return self;
*/
public function setReferrers(ArrayCollection $referrers)
{
Expand All @@ -223,7 +222,7 @@ public function setReferrers(ArrayCollection $referrers)
*
* @param $referrer
*
* @return $this;
* @return self;
*/
public function addReferrer($referrer)
{
Expand Down
Loading

0 comments on commit 552d4a3

Please sign in to comment.