Skip to content

Loading…

cleanup image and file documents #265

Merged
merged 1 commit into from

2 participants

@dbu
Doctrine member

clean up the documents so we can better use them

@dbu dbu commented on the diff
lib/Doctrine/ODM/PHPCR/Document/File.php
@@ -67,6 +67,23 @@ public function setContent(Resource $content)
$this->content = $content;
}
+ /*
+ * Get the resource representing the data of this file.
+ *
+ * Ensures the content object is created
+ *
+ * @return Resource
+ */
+ public function getContent()
@dbu Doctrine member
dbu added a note

@uwej711 not sure why we made this method private originally, but to access mime type or last modified date, its quite handy to access the Resource document.

@uwej711
uwej711 added a note

No reason to not access the resource. It was probably just not needed at that moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@dbu
Doctrine member

it seems we only used the Image document as a child until now, there was not even a setter for the path / id.

@dbu dbu merged commit 77de4b1 into master

1 check passed

Details default The Travis build passed
@dbu dbu deleted the cleanup-image-file-documents branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 12, 2013
  1. @dbu

    cleanup image and file documents

    dbu committed
Showing with 92 additions and 19 deletions.
  1. +17 −16 lib/Doctrine/ODM/PHPCR/Document/File.php
  2. +75 −3 lib/Doctrine/ODM/PHPCR/Document/Image.php
View
33 lib/Doctrine/ODM/PHPCR/Document/File.php
@@ -67,6 +67,23 @@ public function setContent(Resource $content)
$this->content = $content;
}
+ /*
+ * Get the resource representing the data of this file.
+ *
+ * Ensures the content object is created
+ *
+ * @return Resource
+ */
+ public function getContent()
@dbu Doctrine member
dbu added a note

@uwej711 not sure why we made this method private originally, but to access mime type or last modified date, its quite handy to access the Resource document.

@uwej711
uwej711 added a note

No reason to not access the resource. It was probably just not needed at that moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ {
+ if ($this->content === null) {
+ $this->content = new Resource();
+ $this->content->setLastModified(new \DateTime());
+ }
+
+ return $this->content;
+ }
+
/**
* Set the content for this file from the given resource or string.
*
@@ -108,20 +125,4 @@ public function getFileContent()
return $content !== false ? $content : '';
}
-
- /*
- * Ensure content object is created
- *
- * @return Resource
- */
- private function getContent()
- {
- if ($this->content === null) {
- $this->content = new Resource();
- $this->content->setLastModified(new \DateTime());
- }
-
- return $this->content;
- }
-
}
View
78 lib/Doctrine/ODM/PHPCR/Document/Image.php
@@ -9,19 +9,91 @@
*/
class Image
{
+ /**
+ * The PHPCR path
+ *
+ * @PHPCRODM\Id(strategy="parent")
+ */
+ protected $id;
+
+ /**
+ * @PHPCRODM\ParentDocument
+ */
+ protected $parent;
/**
- * @PHPCRODM\Id
+ * @PHPCRODM\Nodename
*/
- protected $path;
+ protected $nodename;
/**
* Image file child
*
* @PHPCRODM\Child(name="file", cascade="persist")
+ *
+ * @var File
*/
protected $file;
+ /**
+ * Set the id (PHPCR path) of this image document
+ *
+ * Only makes sense before persisting a new document. Note that the
+ * preferred way to define the id is by setting the parent and the node
+ * name rather than the absolute id.
+ *
+ * @param string $id
+ */
+ public function setId($id)
+ {
+ $this->id = $id;
+ }
+
+ /**
+ * Get the id (PHPCR path) of this image document
+ *
+ * @return string
+ */
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * @param object $parent
+ */
+ public function setParent($parent)
+ {
+ $this->parent = $parent;
+ }
+
+ /**
+ * @return object
+ */
+ public function getParent()
+ {
+ return $this->parent;
+ }
+
+ /**
+ * Set the node name for this image
+ *
+ * @param string $nodename
+ */
+ public function setNodename($nodename)
+ {
+ $this->nodename = $nodename;
+ }
+
+ /**
+ * Get the node name of this image
+ *
+ * @return string
+ */
+ public function getNodename()
+ {
+ return $this->nodename;
+ }
/**
* @param $file File
@@ -68,7 +140,7 @@ public function getContent()
*/
public function __toString()
{
- return $this->path;
+ return $this->id ?: '';
}
}
Something went wrong with that request. Please try again.