New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Child annotation and file handling #4
Changes from 7 commits
09c5591
3a97568
9846982
a4b46b5
5730595
9e75f54
89dcc11
141a411
a69b25b
9a22a08
912d27d
611f83a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
|
||
namespace Doctrine\ODM\PHPCR\Document; | ||
|
||
/** | ||
* This class represents a JCR file, aka nt:file. | ||
* @see http://wiki.apache.org/jackrabbit/nt:file | ||
* | ||
* @phpcr:Document(alias="file", nodeType="nt:file") | ||
*/ | ||
class File | ||
{ | ||
/** @phpcr:Id */ | ||
protected $id; | ||
|
||
/** @phpcr:Node */ | ||
protected $node; | ||
|
||
/** @phpcr:Date(name="jcr:created") */ | ||
protected $created; | ||
|
||
/** @phpcr:String(name="jcr:createdBy") */ | ||
protected $createdBy; | ||
|
||
/** @phpcr:Child(name="jcr:content") */ | ||
protected $content; | ||
|
||
/** | ||
* setter for id | ||
* | ||
* @param string $id of the node | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* getter for id | ||
* | ||
* @return string id of the node | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* getter for created | ||
* The created date is assigned by the content repository | ||
* | ||
* @return DateTime created date of the file | ||
*/ | ||
public function getCreated() | ||
{ | ||
return $this->created; | ||
} | ||
|
||
/** | ||
* getter for createdBy | ||
* The createdBy is assigned by the content repository | ||
* This is the name of the (jcr) user that created the node | ||
* | ||
* @return string name of the (jcr) user who created the file | ||
*/ | ||
public function getCreatedBy() | ||
{ | ||
return $this->createdBy; | ||
} | ||
|
||
/** | ||
* Set the content for this file from the given filename. | ||
* Calls file_get_contents with the given filename | ||
* | ||
* @param string $filename name of the file which contents should be used | ||
*/ | ||
public function setFileContentFromFilesystem($filename) | ||
{ | ||
$this->getContent(); | ||
$this->content->setData(file_get_contents($filename)); | ||
} | ||
|
||
/** | ||
* Set the content for this file from the given string. | ||
* | ||
* @param string $content the content for the file | ||
*/ | ||
public function setFileContent($content) | ||
{ | ||
$this->getContent(); | ||
$this->content->setData($content); | ||
} | ||
|
||
/* | ||
* Ensure content object is created | ||
*/ | ||
private function getContent() | ||
{ | ||
if ($this->content === null) | ||
{ | ||
$this->content = new Resource(); | ||
} | ||
return $this->content; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Doctrine\ODM\PHPCR\Document; | ||
|
||
/** | ||
* This class represents a Folder in the repository, aka nt:folder | ||
* @see http://wiki.apache.org/jackrabbit/nt:folder | ||
* | ||
* @phpcr:Document(alias="folder", nodeType="nt:folder") | ||
*/ | ||
class Folder | ||
{ | ||
/** @phpcr:Id */ | ||
protected $id; | ||
|
||
/** @phpcr:Node */ | ||
protected $node; | ||
|
||
/** @phpcr:Date(name="jcr:created") */ | ||
protected $created; | ||
|
||
/** @phpcr:String(name="jcr:createdBy") */ | ||
protected $createdBy; | ||
|
||
/** | ||
* setter for id | ||
* | ||
* @param string $id of the node | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* getter for id | ||
* | ||
* @return string id of the node | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* getter for created | ||
* The created date is assigned by the content repository | ||
* | ||
* @return DateTime created date of the file | ||
*/ | ||
public function getCreated() | ||
{ | ||
return $this->created; | ||
} | ||
|
||
/** | ||
* getter for createdBy | ||
* The createdBy is assigned by the content repository | ||
* This is the name of the (jcr) user that created the node | ||
* | ||
* @return string name of the (jcr) user who created the file | ||
*/ | ||
public function getCreatedBy() | ||
{ | ||
return $this->createdBy; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
<?php | ||
|
||
namespace Doctrine\ODM\PHPCR\Document; | ||
|
||
/** | ||
* This class represents a jcr nt:resource and is used by the File document | ||
* @see http://wiki.apache.org/jackrabbit/nt:resource | ||
* | ||
* @phpcr:Document(alias="resource", nodeType="nt:resource") | ||
*/ | ||
class Resource | ||
{ | ||
/** @phpcr:Id */ | ||
protected $id; | ||
|
||
/** @phpcr:Node */ | ||
protected $node; | ||
|
||
/** @phpcr:Binary(name="jcr:data") */ | ||
protected $data; | ||
|
||
/** @phpcr:String(name="jcr:mimeType") */ | ||
protected $mimeType; | ||
|
||
/** @phpcr:String(name="jcr:encoding") */ | ||
protected $encoding; | ||
|
||
/** @phpcr:Date(name="jcr:lastModified") */ | ||
protected $lastModified; | ||
|
||
/** @phpcr:String(name="jcr:lastModifiedBy") */ | ||
protected $lastModifiedBy; | ||
|
||
/** | ||
* setter for the data property | ||
* This property stores the content of this resource | ||
* | ||
* @param string $data the contents of this resource | ||
*/ | ||
public function setData($data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
/** | ||
* getter for the data property | ||
* This returns the content of this resource | ||
* | ||
* @param string | ||
*/ | ||
public function getData() | ||
{ | ||
return $this->data; | ||
} | ||
|
||
/** | ||
* setter for the mimeType property | ||
* This property stores the mimeType of this resource | ||
* | ||
* @param string $mimeType | ||
*/ | ||
public function setMimeType($mimeType) | ||
{ | ||
$this->mimeType = $mimeType; | ||
} | ||
|
||
/** | ||
* getter for the mimeType property | ||
* This returns the mimeType of this resource | ||
* | ||
* @return string | ||
*/ | ||
public function getMimeType() | ||
{ | ||
return $this->mimeType; | ||
} | ||
|
||
/** | ||
* setter for the encoding property | ||
* This property stores the encoding of this resource | ||
* | ||
* @param string $encoding | ||
*/ | ||
public function setEncoding($encoding) | ||
{ | ||
$this->encoding = $encoding; | ||
} | ||
|
||
/** | ||
* getter for the encoding property | ||
* This returns the encoding of this resource | ||
* | ||
* @return string | ||
*/ | ||
public function getEncoding() | ||
{ | ||
return $this->encoding; | ||
} | ||
|
||
/** | ||
* setter for the lastModified property | ||
* This property stores the lastModified date of this resource | ||
* If not set, this might be set by PHPCR | ||
* | ||
* @param DateTime $lastModified | ||
*/ | ||
public function setLastModified($lastModified) | ||
{ | ||
$this->lastModified = $lastModified; | ||
} | ||
|
||
/** | ||
* getter for the lastModified property | ||
* This returns the lastModified date of this resource | ||
* | ||
* @return DateTime | ||
*/ | ||
public function getLastModified() | ||
{ | ||
return $this->lastModified; | ||
} | ||
|
||
/** | ||
* setter for the lastModifiedBy property | ||
* name of the jcr user that last modified this resource | ||
* | ||
* @param string $lastModifiedBy | ||
*/ | ||
public function setLastModifiedBy($lastModifiedBy) | ||
{ | ||
$this->lastModifiedBy = $lastModifiedBy; | ||
} | ||
|
||
/** | ||
* getter for the lastModifiedBy property | ||
* This returns name of the jcr user that last modified this resource | ||
* | ||
* @return string | ||
*/ | ||
public function getLastModifiedBy() | ||
{ | ||
return $this->lastModifiedBy; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,6 +180,12 @@ class ClassMetadataInfo implements ClassMetadata | |
|
||
public $associationsMappings = array(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: In general i want to see the ClassMetadataInfo implementations of MongoDB, CouchDB and PHPCR ODM come together a bit more. Right now I prefer the way MongoDB does reference/embed the most. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't look at those but at JCR ... therefore it's named Child now ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imho in jackalope we should follow JCR/Jackrabbit naming, but in PHPCR ODM we should follow the naming of the other ODM's as much as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But what do we do if the concepts behind are different? A child in JCR is just a full-feature repository node as every other - it is visible from outside. Ther e is no notion of containment or anything else ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO we should focus PHPCR ODM on the things that are the same or similar. This is also why I am advocating with the renaming of path to id. The main point from my POV is to make it possible to share knowledge and code with the other ODM's. For most PHPCR specific stuff imho developers can fallback to Jackalope. However we can also of course add some connivence features to PHOCR ODM that are PHPCR specific. So I guess the gist is that we should always carefully review if there are similar concepts on the other ODM's and if we can sensibly adopt the naming form there. Of course this is just my POV. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Three last comments here (this should be part of my feedback on the list):
|
||
|
||
|
||
/** | ||
* Mapping of child doucments that are child nodes in the repository | ||
*/ | ||
public $childMappings = array(); | ||
|
||
/** | ||
* PHPCR documents are always versioned, this flag determines if this version is exposed to the userland. | ||
* | ||
|
@@ -478,13 +484,34 @@ public function mapField(array $mapping) | |
$this->fieldMappings[$mapping['fieldName']] = $mapping; | ||
} | ||
|
||
public function mapId(array $mapping) | ||
{ | ||
if (isset($mapping['id']) && $mapping['id'] === true) { | ||
$mapping['type'] = 'string'; | ||
$this->setIdentifier($mapping['fieldName']); | ||
if (isset($mapping['strategy'])) { | ||
$this->idGenerator = constant('Doctrine\ODM\PHPCR\Mapping\ClassMetadata::GENERATOR_TYPE_' . strtoupper($mapping['strategy'])); | ||
} | ||
} | ||
$this->validateAndCompleteFieldMapping($mapping, false); | ||
} | ||
|
||
public function mapNode(array $mapping) | ||
{ | ||
$this->validateAndCompleteFieldMapping($mapping, false); | ||
|
||
$this->node = $mapping['fieldName']; | ||
} | ||
|
||
public function mapChild(array $mapping) | ||
{ | ||
$mapping = $this->validateAndCompleteFieldMapping($mapping, false); | ||
if (!isset($mapping['name'])) { | ||
$mapping['name'] = $mapping['fieldName']; | ||
} | ||
$this->childMappings[$mapping['fieldName']] = $mapping; | ||
} | ||
|
||
protected function validateAndCompleteFieldMapping($mapping, $isField = true) | ||
{ | ||
if (!isset($mapping['fieldName'])) { | ||
|
@@ -493,7 +520,7 @@ protected function validateAndCompleteFieldMapping($mapping, $isField = true) | |
if ($isField && !isset($mapping['name'])) { | ||
$mapping['name'] = $mapping['fieldName']; | ||
} | ||
if (isset($this->fieldMappings[$mapping['fieldName']]) || isset($this->associationsMappings[$mapping['fieldName']])) { | ||
if (isset($this->fieldMappings[$mapping['fieldName']]) || isset($this->associationsMappings[$mapping['fieldName']]) || isset($this->childMappings[$mapping['fieldName']])) { | ||
throw MappingException::duplicateFieldMapping($this->name, $mapping['fieldName']); | ||
} | ||
if ($isField && !isset($mapping['type'])) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this { should be on the previous line