Skip to content
This repository
Browse code

[DCOM-28] Initial entry of Doctrine Persistence API interfaces.

  • Loading branch information...
commit 59e6b8c6edcb271622923035b687a063c2b47ce8 1 parent 602de4d
Jonathan H. Wage authored February 15, 2011
88  lib/Doctrine/Common/Persistence/Mapping/ClassMetadata.php
... ...
@@ -0,0 +1,88 @@
  1
+<?php
  2
+/*
  3
+ *  $Id$
  4
+ *
  5
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16
+ *
  17
+ * This software consists of voluntary contributions made by many individuals
  18
+ * and is licensed under the LGPL. For more information, see
  19
+ * <http://www.doctrine-project.org>.
  20
+ */
  21
+
  22
+namespace Doctrine\Common\Persistence\Mapping;
  23
+
  24
+/**
  25
+ * Contract for a Doctrine persistence layer ClassMetadata class to implement.
  26
+ *
  27
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  28
+ * @link    www.doctrine-project.org
  29
+ * @since   2.1
  30
+ * @author  Benjamin Eberlei <kontakt@beberlei.de>
  31
+ * @author  Jonathan Wage <jonwage@gmail.com>
  32
+ */
  33
+interface ClassMetadata
  34
+{
  35
+    /**
  36
+     * Gets the mapped identifier field name.
  37
+     *
  38
+     * @return mixed
  39
+     */
  40
+    public function getIdentifier();
  41
+
  42
+    /**
  43
+     * Gets the ReflectionClass instance for this mapped class.
  44
+     *
  45
+     * @return ReflectionClass
  46
+     */
  47
+    public function getReflectionClass();
  48
+
  49
+    /**
  50
+     * Checks if the given field name is a mapped identifier for this class.
  51
+     *
  52
+     * @param string $fieldName
  53
+     * @return boolean
  54
+     */
  55
+    public function isIdentifier($fieldName);
  56
+
  57
+    /**
  58
+     * Checks if the given field is a mapped property for this class.
  59
+     *
  60
+     * @param string $fieldName 
  61
+     * @return boolean
  62
+     */
  63
+    public function hasField($fieldName);
  64
+
  65
+    /**
  66
+     * Checks if the given field is a mapped association for this class.
  67
+     *
  68
+     * @param string $fieldName
  69
+     * @return boolean
  70
+     */
  71
+    public function hasAssociation($fieldName);
  72
+
  73
+    /**
  74
+     * Checks if the given field is a mapped single valued association for this class.
  75
+     *
  76
+     * @param string $fieldName
  77
+     * @return boolean
  78
+     */
  79
+    public function isSingleValuedAssociation($fieldName);
  80
+
  81
+    /**
  82
+     * Checks if the given field is a mapped collection valued association for this class.
  83
+     *
  84
+     * @param string $fieldName
  85
+     * @return boolean
  86
+     */
  87
+    public function isCollectionValuedAssociation($fieldName);
  88
+}
120  lib/Doctrine/Common/Persistence/ObjectManager.php
... ...
@@ -0,0 +1,120 @@
  1
+<?php
  2
+/*
  3
+ *  $Id$
  4
+ *
  5
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16
+ *
  17
+ * This software consists of voluntary contributions made by many individuals
  18
+ * and is licensed under the LGPL. For more information, see
  19
+ * <http://www.doctrine-project.org>.
  20
+ */
  21
+
  22
+namespace Doctrine\Common\Persistence;
  23
+
  24
+/**
  25
+ * Contract for a Doctrine persistence layer ObjectManager class to implement.
  26
+ *
  27
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  28
+ * @link    www.doctrine-project.org
  29
+ * @since   2.1
  30
+ * @author  Benjamin Eberlei <kontakt@beberlei.de>
  31
+ * @author  Jonathan Wage <jonwage@gmail.com>
  32
+ */
  33
+interface ObjectManager
  34
+{
  35
+    /**
  36
+     * Finds a object by its identifier.
  37
+     *
  38
+     * This is just a convenient shortcut for getRepository($className)->find($id).
  39
+     *
  40
+     * @param string
  41
+     * @param mixed
  42
+     * @return object
  43
+     */
  44
+    public function find($className, $id);
  45
+
  46
+    /**
  47
+     * Tells the ObjectManager to make an instance managed and persistent.
  48
+     *
  49
+     * The object will be entered into the database as a result of the flush operation.
  50
+     * 
  51
+     * NOTE: The persist operation always considers objects that are not yet known to
  52
+     * this ObjectManager as NEW. Do not pass detached objects to the persist operation.
  53
+     *
  54
+     * @param object $object The instance to make managed and persistent.
  55
+     */
  56
+    public function persist($object);
  57
+
  58
+    /**
  59
+     * Removes an object instance.
  60
+     *
  61
+     * A removed object will be removed from the database as a result of the flush operation.
  62
+     *
  63
+     * @param object $object The object instance to remove.
  64
+     */
  65
+    public function remove($object);
  66
+
  67
+    /**
  68
+     * Merges the state of a detached object into the persistence context
  69
+     * of this ObjectManager and returns the managed copy of the object.
  70
+     * The object passed to merge will not become associated/managed with this ObjectManager.
  71
+     *
  72
+     * @param object $object
  73
+     */
  74
+    public function merge($object);
  75
+
  76
+    /**
  77
+     * Detaches an object from the ObjectManager, causing a managed object to
  78
+     * become detached. Unflushed changes made to the object if any
  79
+     * (including removal of the object), will not be synchronized to the database.
  80
+     * Objects which previously referenced the detached object will continue to
  81
+     * reference it.
  82
+     *
  83
+     * @param object $object The object to detach.
  84
+     */
  85
+    public function detach($object);
  86
+
  87
+    /**
  88
+     * Refreshes the persistent state of an object from the database,
  89
+     * overriding any local changes that have not yet been persisted.
  90
+     *
  91
+     * @param object $object The object to refresh.
  92
+     */
  93
+    public function refresh($object);
  94
+
  95
+    /**
  96
+     * Flushes all changes to objects that have been queued up to now to the database.
  97
+     * This effectively synchronizes the in-memory state of managed objects with the
  98
+     * database.
  99
+     */
  100
+    public function flush();
  101
+
  102
+    /**
  103
+     * Gets the repository for an entity class.
  104
+     *
  105
+     * @param string $className
  106
+     * @return \Doctrine\Common\Persistence\ObjectRepository
  107
+     */
  108
+    public function getRepository($className);
  109
+
  110
+    /**
  111
+     * Returns the ClassMetadata descriptor for a class.
  112
+     *
  113
+     * The class name must be the fully-qualified class name without a leading backslash
  114
+     * (as it is returned by get_class($obj)).
  115
+     *
  116
+     * @param string $className
  117
+     * @return \Doctrine\Common\Persistence\Mapping\ClassMetadata
  118
+     */
  119
+    public function getClassMetadata($className);
  120
+}
65  lib/Doctrine/Common/Persistence/ObjectRepository.php
... ...
@@ -0,0 +1,65 @@
  1
+<?php
  2
+/*
  3
+ *  $Id$
  4
+ *
  5
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16
+ *
  17
+ * This software consists of voluntary contributions made by many individuals
  18
+ * and is licensed under the LGPL. For more information, see
  19
+ * <http://www.doctrine-project.org>.
  20
+ */
  21
+
  22
+namespace Doctrine\Common\Persistence;
  23
+
  24
+/**
  25
+ * Contract for a Doctrine persistence layer ObjectRepository class to implement.
  26
+ *
  27
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  28
+ * @link    www.doctrine-project.org
  29
+ * @since   2.1
  30
+ * @author  Benjamin Eberlei <kontakt@beberlei.de>
  31
+ * @author  Jonathan Wage <jonwage@gmail.com>
  32
+ */
  33
+interface ObjectRepository
  34
+{
  35
+    /**
  36
+     * Finds an object by its primary key / identifier.
  37
+     *
  38
+     * @param $id The identifier.
  39
+     * @return object The object.
  40
+     */
  41
+    public function find($id);
  42
+
  43
+    /**
  44
+     * Finds all objects in the repository.
  45
+     *
  46
+     * @return mixed The objects.
  47
+     */
  48
+    public function findAll();
  49
+
  50
+    /**
  51
+     * Finds objects by a set of criteria.
  52
+     *
  53
+     * @param array $criteria
  54
+     * @return mixed The objects.
  55
+     */
  56
+    public function findBy(array $criteria);
  57
+
  58
+    /**
  59
+     * Finds a single object by a set of criteria.
  60
+     *
  61
+     * @param array $criteria
  62
+     * @return object The object.
  63
+     */
  64
+    public function findOneBy(array $criteria);
  65
+}

2 notes on commit 59e6b8c

Benjamin Eberlei
Owner

Can we call it ObjectMetadata instead of ClassMetadata? I hate the use foo as bar; renaming.

Benjamin Eberlei
Owner

The $Id$ in the head can be removed also, its SVN legacy.

Please sign in to comment.
Something went wrong with that request. Please try again.