Failed Conditions
Push — master ( 6744b4...2b8acb )
by Marco
60:45 queued 60:36
created

lib/Doctrine/ORM/Tools/Setup.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ORM\Tools;
21
22
use Doctrine\Common\ClassLoader;
23
use Doctrine\Common\Cache\Cache;
24
use Doctrine\Common\Cache\CacheProvider;
25
use Doctrine\Common\Cache\ArrayCache;
26
use Doctrine\ORM\Configuration;
27
use Doctrine\ORM\Mapping\Driver\XmlDriver;
28
use Doctrine\ORM\Mapping\Driver\YamlDriver;
29
30
/**
31
 * Convenience class for setting up Doctrine from different installations and configurations.
32
 *
33
 * @author Benjamin Eberlei <[email protected]>
34
 */
35
class Setup
36
{
37
    /**
38
     * Use this method to register all autoloads for a downloaded Doctrine library.
39
     * Pick the directory the library was uncompressed into.
40
     *
41
     * @param string $directory
42
     *
43
     * @return void
44
     */
45 1
    public static function registerAutoloadDirectory($directory)
46
    {
47 1
        if (!class_exists('Doctrine\Common\ClassLoader', false)) {
48
            require_once $directory . "/Doctrine/Common/ClassLoader.php";
49
        }
50
51 1
        $loader = new ClassLoader("Doctrine", $directory);
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\Common\ClassLoader has been deprecated with message: the ClassLoader is deprecated and will be removed in version 3.0 of doctrine/common.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
52 1
        $loader->register();
53
54 1
        $loader = new ClassLoader("Symfony\Component", $directory . "/Doctrine");
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\Common\ClassLoader has been deprecated with message: the ClassLoader is deprecated and will be removed in version 3.0 of doctrine/common.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
55 1
        $loader->register();
56 1
    }
57
58
    /**
59
     * Creates a configuration with an annotation metadata driver.
60
     *
61
     * @param array   $paths
62
     * @param boolean $isDevMode
63
     * @param string  $proxyDir
64
     * @param Cache   $cache
65
     * @param bool    $useSimpleAnnotationReader
66
     *
67
     * @return Configuration
68
     */
69 3 View Code Duplication
    public static function createAnnotationMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null, $useSimpleAnnotationReader = true)
70
    {
71 3
        $config = self::createConfiguration($isDevMode, $proxyDir, $cache);
72 3
        $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver($paths, $useSimpleAnnotationReader));
73
74 3
        return $config;
75
    }
76
77
    /**
78
     * Creates a configuration with a xml metadata driver.
79
     *
80
     * @param array   $paths
81
     * @param boolean $isDevMode
82
     * @param string  $proxyDir
83
     * @param Cache   $cache
84
     *
85
     * @return Configuration
86
     */
87 1 View Code Duplication
    public static function createXMLMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null)
88
    {
89 1
        $config = self::createConfiguration($isDevMode, $proxyDir, $cache);
90 1
        $config->setMetadataDriverImpl(new XmlDriver($paths));
91
92 1
        return $config;
93
    }
94
95
    /**
96
     * Creates a configuration with a yaml metadata driver.
97
     *
98
     * @param array   $paths
99
     * @param boolean $isDevMode
100
     * @param string  $proxyDir
101
     * @param Cache   $cache
102
     *
103
     * @return Configuration
104
     */
105 1 View Code Duplication
    public static function createYAMLMetadataConfiguration(array $paths, $isDevMode = false, $proxyDir = null, Cache $cache = null)
106
    {
107 1
        $config = self::createConfiguration($isDevMode, $proxyDir, $cache);
108 1
        $config->setMetadataDriverImpl(new YamlDriver($paths));
109
110 1
        return $config;
111
    }
112
113
    /**
114
     * Creates a configuration without a metadata driver.
115
     *
116
     * @param bool   $isDevMode
117
     * @param string $proxyDir
118
     * @param Cache  $cache
119
     *
120
     * @return Configuration
121
     */
122 6
    public static function createConfiguration($isDevMode = false, $proxyDir = null, Cache $cache = null)
123
    {
124 6
        $proxyDir = $proxyDir ?: sys_get_temp_dir();
125
126 6
        if ($isDevMode === false && $cache === null) {
127
            if (extension_loaded('apc')) {
128
                $cache = new \Doctrine\Common\Cache\ApcCache();
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\Common\Cache\ApcCache has been deprecated with message: since version 1.6, use ApcuCache instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
129
            } elseif (ini_get('xcache.cacher')) {
130
                $cache = new \Doctrine\Common\Cache\XcacheCache();
131
            } elseif (extension_loaded('memcache')) {
132
                $memcache = new \Memcache();
133
                $memcache->connect('127.0.0.1');
134
                $cache = new \Doctrine\Common\Cache\MemcacheCache();
135
                $cache->setMemcache($memcache);
136
            } elseif (extension_loaded('redis')) {
137
                $redis = new \Redis();
138
                $redis->connect('127.0.0.1');
139
                $cache = new \Doctrine\Common\Cache\RedisCache();
140
                $cache->setRedis($redis);
141
            } else {
142
                $cache = new ArrayCache();
143
            }
144 6
        } elseif ($cache === null) {
145 4
            $cache = new ArrayCache();
146
        }
147
148 6
        if ($cache instanceof CacheProvider) {
149 5
            $cache->setNamespace("dc2_" . md5($proxyDir) . "_"); // to avoid collisions
150
        }
151
152 6
        $config = new Configuration();
153 6
        $config->setMetadataCacheImpl($cache);
154 6
        $config->setQueryCacheImpl($cache);
155 6
        $config->setResultCacheImpl($cache);
156 6
        $config->setProxyDir($proxyDir);
157 6
        $config->setProxyNamespace('DoctrineProxies');
158 6
        $config->setAutoGenerateProxyClasses($isDevMode);
159
160 6
        return $config;
161
    }
162
}
163