From 6dfd5d507d9863f987b30b0a5ab4268aea2ed875 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Thu, 2 Aug 2012 11:09:40 +0000 Subject: J'étais parti sur un download pourri de Cake. Les gars on abusé sur GitHub. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///var/svn/2012-php-weave/trunk@7 d972a294-176a-4cf9-8ea1-fcd5b0c30f5c --- .../lib/Cake/Configure/ConfigReaderInterface.php | 33 ++++ .../lib/Cake/Configure/IniReader.php | 184 +++++++++++++++++++++ .../lib/Cake/Configure/PhpReader.php | 103 ++++++++++++ 3 files changed, 320 insertions(+) create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure/ConfigReaderInterface.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure/IniReader.php create mode 100644 poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure/PhpReader.php (limited to 'poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure') diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure/ConfigReaderInterface.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure/ConfigReaderInterface.php new file mode 100644 index 0000000..f137355 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure/ConfigReaderInterface.php @@ -0,0 +1,33 @@ + array('password' => 'secret'))` + * + * You can nest properties as deeply as needed using `.`'s. In addition to using `.` you + * can use standard ini section notation to create nested structures: + * + * {{{ + * [section] + * key = value + * }}} + * + * Once loaded into Configure, the above would be accessed using: + * + * `Configure::read('section.key'); + * + * You can combine `.` separated values with sections to create more deeply + * nested structures. + * + * IniReader also manipulates how the special ini values of + * 'yes', 'no', 'on', 'off', 'null' are handled. These values will be + * converted to their boolean equivalents. + * + * @package Cake.Configure + * @see http://php.net/parse_ini_file + */ +class IniReader implements ConfigReaderInterface { + +/** + * The path to read ini files from. + * + * @var array + */ + protected $_path; + +/** + * The section to read, if null all sections will be read. + * + * @var string + */ + protected $_section; + +/** + * Build and construct a new ini file parser. The parser can be used to read + * ini files that are on the filesystem. + * + * @param string $path Path to load ini config files from. + * @param string $section Only get one section, leave null to parse and fetch + * all sections in the ini file. + */ + public function __construct($path, $section = null) { + $this->_path = $path; + $this->_section = $section; + } + +/** + * Read an ini file and return the results as an array. + * + * @param string $file Name of the file to read. The chosen file + * must be on the reader's path. + * @return array + * @throws ConfigureException + */ + public function read($file) { + $filename = $this->_path . $file; + if (!file_exists($filename)) { + $filename .= '.ini'; + if (!file_exists($filename)) { + throw new ConfigureException(__d('cake_dev', 'Could not load configuration files: %s or %s', substr($filename, 0, -4), $filename)); + } + } + $contents = parse_ini_file($filename, true); + if (!empty($this->_section) && isset($contents[$this->_section])) { + $values = $this->_parseNestedValues($contents[$this->_section]); + } else { + $values = array(); + foreach ($contents as $section => $attribs) { + if (is_array($attribs)) { + $values[$section] = $this->_parseNestedValues($attribs); + } else { + $parse = $this->_parseNestedValues(array($attribs)); + $values[$section] = array_shift($parse); + } + } + } + return $values; + } + +/** + * parses nested values out of keys. + * + * @param array $values Values to be exploded. + * @return array Array of values exploded + */ + protected function _parseNestedValues($values) { + foreach ($values as $key => $value) { + if ($value === '1') { + $value = true; + } + if ($value === '') { + $value = false; + } + unset($values[$key]); + if (strpos($key, '.') !== false) { + $values = Hash::insert($values, $key, $value); + } else { + $values[$key] = $value; + } + } + return $values; + } + +/** + * Dumps the state of Configure data into an ini formatted string. + * + * @param string $filename The filename on $this->_path to save into. + * @param array $data The data to convert to ini file. + * @return int Bytes saved. + */ + public function dump($filename, $data) { + $result = array(); + foreach ($data as $key => $value) { + if ($key[0] != '[') { + $result[] = "[$key]"; + } + if (is_array($value)) { + $keyValues = Hash::flatten($value, '.'); + foreach ($keyValues as $k => $v) { + $result[] = "$k = " . $this->_value($v); + } + } + } + $contents = join("\n", $result); + return file_put_contents($this->_path . $filename, $contents); + } + +/** + * Converts a value into the ini equivalent + * + * @param mixed $value to export. + * @return string String value for ini file. + */ + protected function _value($val) { + if ($val === null) { + return 'null'; + } + if ($val === true) { + return 'true'; + } + if ($val === false) { + return 'false'; + } + return (string)$val; + } + +} diff --git a/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure/PhpReader.php b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure/PhpReader.php new file mode 100644 index 0000000..f5d9619 --- /dev/null +++ b/poc/poc02-compiling-cake/src/vendor/cakephp-2.2.1-0-gcc44130/lib/Cake/Configure/PhpReader.php @@ -0,0 +1,103 @@ +_path = $path; + } + +/** + * Read a config file and return its contents. + * + * Files with `.` in the name will be treated as values in plugins. Instead of reading from + * the initialized path, plugin keys will be located using App::pluginPath(). + * + * @param string $key The identifier to read from. If the key has a . it will be treated + * as a plugin prefix. + * @return array Parsed configuration values. + * @throws ConfigureException when files don't exist or they don't contain `$config`. + * Or when files contain '..' as this could lead to abusive reads. + */ + public function read($key) { + if (strpos($key, '..') !== false) { + throw new ConfigureException(__d('cake_dev', 'Cannot load configuration files with ../ in them.')); + } + if (substr($key, -4) === '.php') { + $key = substr($key, 0, -4); + } + list($plugin, $key) = pluginSplit($key); + + if ($plugin) { + $file = App::pluginPath($plugin) . 'Config' . DS . $key; + } else { + $file = $this->_path . $key; + } + $file .= '.php'; + if (!is_file($file)) { + if (!is_file(substr($file, 0, -4))) { + throw new ConfigureException(__d('cake_dev', 'Could not load configuration files: %s or %s', $file, substr($file, 0, -4))); + } + } + include $file; + if (!isset($config)) { + throw new ConfigureException( + sprintf(__d('cake_dev', 'No variable $config found in %s.php'), $file) + ); + } + return $config; + } + +/** + * Converts the provided $data into a string of PHP code that can + * be used saved into a file and loaded later. + * + * @param string $filename The filename to create on $this->_path. + * @param array $data Data to dump. + * @return int Bytes saved. + */ + public function dump($filename, $data) { + $contents = '_path . $filename, $contents); + } + +} -- cgit v1.2.3