source: pro-violet-viettel/sourcecode/application/libraries/Doctrine/ORM/Mapping/Driver/DriverChain.php @ 345

Last change on this file since 345 was 345, checked in by quyenla, 11 years ago

collaborator page

File size: 3.9 KB
Line 
1<?php
2/*
3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14 *
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the LGPL. For more information, see
17 * <http://www.doctrine-project.org>.
18 */
19
20namespace Doctrine\ORM\Mapping\Driver;
21
22use Doctrine\ORM\Mapping\Driver\Driver,
23    Doctrine\ORM\Mapping\ClassMetadataInfo,
24    Doctrine\ORM\Mapping\MappingException;
25
26/**
27 * The DriverChain allows you to add multiple other mapping drivers for
28 * certain namespaces
29 *
30 * @since 2.0
31 * @author Benjamin Eberlei <kontakt@beberlei.de>
32 * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
33 * @author Jonathan H. Wage <jonwage@gmail.com>
34 * @author Roman Borschel <roman@code-factory.org>
35 * @todo Rename: MappingDriverChain or MetadataDriverChain
36 */
37class DriverChain implements Driver
38{
39    /**
40     * @var array
41     */
42    private $_drivers = array();
43
44    /**
45     * Add a nested driver.
46     *
47     * @param Driver $nestedDriver
48     * @param string $namespace
49     */
50    public function addDriver(Driver $nestedDriver, $namespace)
51    {
52        $this->_drivers[$namespace] = $nestedDriver;
53    }
54
55    /**
56     * Get the array of nested drivers.
57     *
58     * @return array $drivers
59     */
60    public function getDrivers()
61    {
62        return $this->_drivers;
63    }
64
65    /**
66     * Loads the metadata for the specified class into the provided container.
67     *
68     * @param string $className
69     * @param ClassMetadataInfo $metadata
70     */
71    public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
72    {
73        foreach ($this->_drivers as $namespace => $driver) {
74            if (strpos($className, $namespace) === 0) {
75                $driver->loadMetadataForClass($className, $metadata);
76                return;
77            }
78        }
79
80        throw MappingException::classIsNotAValidEntityOrMappedSuperClass($className);
81    }
82
83    /**
84     * Gets the names of all mapped classes known to this driver.
85     *
86     * @return array The names of all mapped classes known to this driver.
87     */
88    public function getAllClassNames()
89    {
90        $classNames = array();
91        $driverClasses = array();
92        foreach ($this->_drivers AS $namespace => $driver) {
93            $oid = spl_object_hash($driver);
94            if (!isset($driverClasses[$oid])) {
95                $driverClasses[$oid] = $driver->getAllClassNames();
96            }
97
98            foreach ($driverClasses[$oid] AS $className) {
99                if (strpos($className, $namespace) === 0) {
100                    $classNames[$className] = true;
101                }
102            }
103        }
104        return array_keys($classNames);
105    }
106
107    /**
108     * Whether the class with the specified name should have its metadata loaded.
109     *
110     * This is only the case for non-transient classes either mapped as an Entity or MappedSuperclass.
111     *
112     * @param string $className
113     * @return boolean
114     */
115    public function isTransient($className)
116    {
117        foreach ($this->_drivers AS $namespace => $driver) {
118            if (strpos($className, $namespace) === 0) {
119                return $driver->isTransient($className);
120            }
121        }
122
123        // class isTransient, i.e. not an entity or mapped superclass
124        return true;
125    }
126}
Note: See TracBrowser for help on using the repository browser.