Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2 into cach…
Browse files Browse the repository at this point in the history
…e_filesystemSpeedup
  • Loading branch information
Show file tree
Hide file tree
Showing 26 changed files with 866 additions and 38 deletions.
3 changes: 0 additions & 3 deletions src/Processor.php
Expand Up @@ -18,9 +18,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Config;

/**
Expand Down
3 changes: 0 additions & 3 deletions src/Processor/Constant.php
Expand Up @@ -18,9 +18,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Config\Processor;

use Zend\Config\Config,
Expand Down
3 changes: 0 additions & 3 deletions src/Processor/Filter.php
Expand Up @@ -18,9 +18,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Config\Processor;

use Zend\Config\Config,
Expand Down
3 changes: 0 additions & 3 deletions src/Processor/Queue.php
Expand Up @@ -18,9 +18,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Config\Processor;

use Zend\Config\Config,
Expand Down
9 changes: 3 additions & 6 deletions src/Processor/Token.php
Expand Up @@ -18,9 +18,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Config\Processor;

use Zend\Config\Config,
Expand Down Expand Up @@ -200,7 +197,7 @@ protected function buildMap()
foreach ($this->tokens as $token => $value) {
$this->map[$this->prefix . $token . $this->suffix] = $value;
}
}
}
}

/**
Expand Down Expand Up @@ -228,7 +225,7 @@ public function process(Config $config)
if ($val instanceof Config) {
$this->process($val);
} else {
$config->$key = str_replace($keys,$values,$val);
$config->$key = str_replace($keys, $values, $val);
}
}

Expand All @@ -248,6 +245,6 @@ public function processValue($value)
}
$keys = array_keys($this->map);
$values = array_values($this->map);
return str_replace($keys,$values,$value);
return str_replace($keys, $values, $value);
}
}
25 changes: 11 additions & 14 deletions src/Processor/Translator.php
Expand Up @@ -18,9 +18,6 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

/**
* @namespace
*/
namespace Zend\Config\Processor;

use Zend\Config\Config,
Expand Down Expand Up @@ -108,22 +105,22 @@ public function process(Config $config)
if ($val instanceof Config) {
$this->process($val);
} else {
$config->$key = $this->translator->translate($val,$this->locale);
$config->$key = $this->translator->translate($val, $this->locale);
}
}

return $config;
}

/**
* Process a single value
*
* @param $value
* @return mixed
*/
public function processValue($value)
{
return $this->translator->translate($value,$this->locale);
}
/**
* Process a single value
*
* @param $value
* @return mixed
*/
public function processValue($value)
{
return $this->translator->translate($value, $this->locale);
}

}
2 changes: 1 addition & 1 deletion src/Reader/Ini.php
Expand Up @@ -141,7 +141,7 @@ protected function process(array $data)
if (is_array($value)) {
$config[$section] = $this->processSection($value);
} else {
$config[$section] = $value;
$this->processKey($section, $value, $config);
}
}

Expand Down
113 changes: 113 additions & 0 deletions src/Reader/Json.php
@@ -0,0 +1,113 @@
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Config
* @subpackage Reader
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Config\Reader;

use Zend\Config\Reader,
Zend\Config\Exception,
Zend\Json\Json as JsonFormat;

/**
* Json config reader.
*
* @category Zend
* @package Zend_Config
* @subpackage Reader
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Json implements Reader
{
/**
* Directory of the JSON file
*
* @var string
*/
protected $directory;
/**
* fromFile(): defined by Reader interface.
*
* @see Reader::fromFile()
* @param string $filename
* @return array
*/
public function fromFile($filename)
{
if (!file_exists($filename)) {
throw new Exception\RuntimeException("The file $filename doesn't exists.");
}

$this->directory = dirname($filename);

try {
$config = JsonFormat::decode(file_get_contents($filename), JsonFormat::TYPE_ARRAY);
} catch (\Zend\Json\Exception\RuntimeException $e) {
throw new Exception\RuntimeException($e->getMessage());
}

return $this->process($config);
}

/**
* fromString(): defined by Reader interface.
*
* @see Reader::fromString()
* @param string $string
* @return array
*/
public function fromString($string)
{
if (empty($string)) {
return array();
}
$this->directory = null;

try {
$config = JsonFormat::decode($string, JsonFormat::TYPE_ARRAY);
} catch (\Zend\Json\Exception\RuntimeException $e) {
throw new Exception\RuntimeException($e->getMessage());
}

return $this->process($config);
}
/**
* Process the array for @include
*
* @param array $data
* @return array
*/
protected function process(array $data) {
foreach ($data as $key => $value) {
if (is_array($value)) {
$data[$key] = $this->process($value);
}
if (trim($key)==='@include') {
if ($this->directory === null) {
throw new Exception\RuntimeException('Cannot process @include statement for a json string');
}
$reader = clone $this;
unset($data[$key]);
$data = array_replace_recursive($data, $reader->fromFile($this->directory . '/' . $value));
}
}
return $data;
}
}

0 comments on commit 717175b

Please sign in to comment.