Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 128 lines (110 sloc) 2.525 kb
1d6da61 Paul Dragoonis Adding the new namespaced version of PPI
dragoonis authored
1 <?php
2 namespace PPI;
3
4 use PPI\Registry\Exception\EntryNotFound;
5
6 class Core {
7
8 /**
9 * Get the data source object from the registry
10 *
11 * @static
12 * @throws Registry\Exception\EntryNotFound
13 * @return mixed
14 */
15 static function getDataSource() {
16
17 if(!Registry::exists('DataSource')) {
18 throw new EntryNotFound('Entry DataSource Not Found In The Registry.');
19 }
20 return Registry::get('DataSource');
21 }
22
23 /**
24 * Get a data source connection
25 *
26 * @static
27 * @param string $key
28 * @return object
29 */
30 static function getDataSourceConnection($key) {
31 return self::getDataSource()->getConnection($key);
32 }
33
34 /**
35 * Get the session object
36 *
37 * @static
38 * @param null $options
39 * @return mixed
40 */
41 static function getSession($options = null) {
42
43 if ($options !== null && !is_array($options)) {
44 $config = Registry::get('PPI_Config');
45 $options = isset($config->session) ? $config->session->toArray() : array();
46 $options = $options;
47 }
48 $session = Registry::get('PPI_Session');
49 if(is_array($options)) {
50 $session->defaults($options);
51 }
52 return $session;
53 }
54
55 /**
56 * Get the cache object
57 *
58 * @static
59 * @param null $options
60 * @return Cache
61 */
62 static function getCache($options = null) {
63
64 if (!is_array($options)) {
65 $config = Registry::get('PPI_Config');
66 $options = isset($config->cache) ? $config->cache->toArray() : array();
67 if (is_string($options) && $options !== '') {
68 $options['handler'] = $options;
69 }
70 $options = $options;
71 }
72 return new Cache($options);
73 }
74
75 /**
76 * Get the config object from the registry
77 *
78 * @static
79 * @throws Registry\Exception\EntryNotFound
80 * @return object
81 */
82 static function getConfig() {
83
84 if(!Registry::exists('PPI_Config')) {
85 throw new EntryNotFound('Entry PPI_Config Not Found In The Registry.');
86 }
87 return Registry::get('PPI_Config');
88 }
89
90 /**
91 * Get an object from the registry if it exists, if it does not then we set it for next time.
92 *
93 * @static
94 * @param $class
95 * @return mixed
96 */
97 static function getObjectFromRegistry($class) {
98
99 if(!Registry::exists($class)) {
100 $oClass = new $class();
101 Registry::set($class, $oClass);
102 return $oClass;
103 }
104 return Registry::get($class);
105 }
106
107
108 /**
109 * Get the dispatcher object
110 *
111 * @return object
112 */
113 static function getDispatcher() {
114 return Registry::get('PPI_Dispatch');
115 }
116
117 /**
118 * Get the router object.
119 *
120 * @static
121 * @return mixed
122 */
123 static function getRouter() {
124 return Registry::get('PPI_Router');
125 }
126
127 }
Something went wrong with that request. Please try again.