Overview
  • Namespace
  • Class
  • Tree

Namespaces

  • PHP
  • Yiinitializr
    • Cli
    • Clio
    • Composer
    • Helpers

Classes

  • ArrayX
  • Config
  • Initializer
 1 <?php
 2 /**
 3  * Config class file.
 4  *
 5  * @author Antonio Ramirez <amigo.cobos@gmail.com>
 6  * @link http://www.ramirezcobos.com/
 7  * @link http://www.2amigos.us/
 8  * @copyright 2013 2amigOS! Consultation Group LLC
 9  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
10  */
11 namespace Yiinitializr\Helpers;
12 
13 use Yiinitializr\Helpers\ArrayX;
14 
15 /**
16  * Config provides easy access to Yiinitializr configuration file
17  *
18  * @author Antonio Ramirez <amigo.cobos@gmail.com>
19  * @package Yiinitializr.helpers
20  * @since 1.0
21  */
22 class Config
23 {
24     /**
25      * @var array the configuration settings
26      */
27     private static $_settings;
28 
29     private static $_config_dir_path;
30     private static $_envlock_file_path;
31 
32     /**
33      * Returns a value of the array
34      * @param $value
35      * @return mixed | null if no key is found
36      */
37     public static function value($value)
38     {
39         return ArrayX::get(self::settings(), $value);
40     }
41 
42     /**
43      * Reads the configuration settings from the file
44      * @return array|mixed
45      * @throws \Exception
46      */
47     public static function settings()
48     {
49         if (null === self::$_settings)
50         {
51             self::$_settings = file_exists(self::getConfigurationDirectoryPath() . '/settings.php')
52                 ? require_once(self::getConfigurationDirectoryPath() . '/settings.php')
53                 : array();
54 
55             self::$_settings['envlock'] = file_exists(self::getEnvironmentLockFilePath());
56 
57         }
58         if (empty(self::$_settings))
59             throw new \Exception('Unable to find Yiinitialzr settings file!');
60 
61         return self::$_settings;
62     }
63 
64     /**
65      * @param string $content
66      */
67     public static function createEnvironmentLockFile($content = '')
68     {
69         umask(0);
70         file_put_contents(self::getEnvironmentLockFilePath(), $content);
71         @chmod(self::getEnvironmentLockFilePath(), 0644);
72     }
73 
74     /**
75      * Returns the configuration directory path
76      * @return string
77      */
78     public static function getConfigurationDirectoryPath()
79     {
80         if (null === self::$_config_dir_path)
81             self::$_config_dir_path = dirname(__FILE__) . '/../config';
82         return self::$_config_dir_path;
83     }
84 
85     /**
86      * Returns the environment lock file path
87      * @return string
88      */
89     public static function getEnvironmentLockFilePath()
90     {
91         if (null === self::$_envlock_file_path)
92             self::$_envlock_file_path = self::getConfigurationDirectoryPath() . '/env.lock';
93         return self::$_envlock_file_path;
94     }
95 }
API documentation generated by ApiGen 2.8.0