http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 4 LOC: 99 Statements: 19

Source file Statements Methods Total coverage
Factory.php 94.7% 100.0% 95.7%
   
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * This source file is subject to the new BSD license that is bundled
6
 * with this package in the file LICENSE.txt.
7
 * It is also available through the world-wide-web at this URL:
8
 * http://www.opensource.org/licenses/bsd-license.php
9
 *
10
 * @category  Xyster
11
 * @package   Xyster_Orm
12
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
13
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
14
 * @version   $Id: Factory.php 202 2008-01-20 16:20:09Z doublecompile $
15
 */
16
/**
17
 * @see Xyster_Orm_Mapper_Factory_Abstract
18
 */
19 1
require_once 'Xyster/Orm/Mapper/Factory/Abstract.php';
20
/**
21
 * A simple factory for creating mappers
22
 *
23
 * @category  Xyster
24
 * @package   Xyster_Orm
25
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
26
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
27
 */
28
class Xyster_Orm_Mapper_Factory extends Xyster_Orm_Mapper_Factory_Abstract
29
{
30
    /**
31
     * Default cache for meta information provided by the backend
32
     *
33
     * @var Zend_Cache_Core
34
     */
35
    protected $_defaultMetadataCache;
36
37
    /**
38
     * Gets the mapper for a given class
39
     *
40
     * @param string $className The name of the entity class
41
     * @return Xyster_Orm_Mapper The mapper object
42
     */
43
    public function get( $className )
44
    {
45 89
        if ( !isset($this->_mappers[$className]) ) {
46
47 89
            $mapperName = Xyster_Orm_Loader::loadMapperClass($className);
48 89
            $this->_mappers[$className] = new $mapperName($this,
49 89
                $this->getDefaultMetadataCache());
50 89
            $this->_mappers[$className]->init();
51
52 89
        }
53
54 89
        return $this->_mappers[$className];
55
    }
56
57
    /**
58
     * Gets the default metadata cache for information returned by getFields()
59
     *
60
     * @return Zend_Cache_Core
61
     */
62
    public function getDefaultMetadataCache()
63
    {
64 92
        return $this->_defaultMetadataCache;
65
    }
66
67
    /**
68
     * Sets the default metadata cache for information returned by getFields()
69
     *
70
     * If $defaultMetadataCache is null, then no metadata cache is used by
71
     * default.
72
     *
73
     * @param  mixed $metadataCache Either a Cache object, or a string naming a Registry key
74
     */
75
    public function setDefaultMetadataCache($metadataCache = null)
76
    {
77 92
        $this->_defaultMetadataCache = $this->_setupMetadataCache($metadataCache);
78
    }
79
80
    /**
81
     * @param mixed $metadataCache Either a Cache object, or a string naming a Registry key
82
     * @return Zend_Cache_Core
83
     * @throws Xyster_Orm_Mapper_Exception
84
     */
85
    protected function _setupMetadataCache($metadataCache)
86
    {
87 92
        if (is_string($metadataCache)) {
88 89
            require_once 'Zend/Registry.php';
89 89
            $metadataCache = Zend_Registry::get($metadataCache);
90 88
        }
91
92 91
        if ($metadataCache === null || $metadataCache instanceof Zend_Cache_Core) {
93 90
            return $metadataCache;
94 0
        }
95
96 1
        require_once 'Xyster/Orm/Mapper/Exception.php';
97 1
        throw new Xyster_Orm_Mapper_Exception('Argument must be of type Zend_Cache_Core, or a Registry key where a Zend_Cache_Core object is stored');
98
    }
99
}


Report generated at 2008-03-05T18:27:43-05:00