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
Browse files Browse the repository at this point in the history
Fixed files permissions
  • Loading branch information
Grzegorz Drozd committed Feb 28, 2013
148 parents 9eb2954 + 82cff31 + 186a39c + 39a35fe + b0c8193 + 1a7e426 + 09ea754 + 8317963 + 950705c + bd78289 + 25f3e05 + 1c0577b + 6bcfccb + 0b2a1a9 + 7974490 + f3ba45e + 4357e80 + 7d43d02 + 421a0f4 + e7aa329 + 6d05bfe + f27c5e2 + 6cb3b21 + 1ecb5ed + b66b0e2 + 0b91e40 + 6bda391 + b932fa5 + a431b75 + 9ce83ec + a35dff6 + 60e4965 + 0f071e9 + 3fe17b4 + 196ca18 + 17cbc64 + 8f4a51f + 88ec12d + 31ab35e + 59c83c4 + d50da4c + 01af50b + 6a46af5 + 4308adc + 1c3d629 + 18a268d + 1987408 + abc72db + 175f7ab + 8a85704 + 7706019 + cc5d38c + fbaa5aa + 0555415 + 20ae04b + 0680687 + e65301c + 424e30a + d36a7f1 + 64bb794 + c74649b + b14bb6b + 4e73e4e + 0ee93d0 + e887bfd + f66ad20 + 66c5ff2 + f5b2841 + 717175b + 52c5e49 + 8f39d69 + 2003fce + 1ccb3fd + 315a9ac + f3cba00 + e470732 + ae8cd95 + a4f21b6 + f36ff90 + 5344247 + 5cdfa08 + 4925e55 + fb107e5 + 98634df + 8d23ab7 + 19e17a6 + 98ac67f + 0a2d51c + 86db540 + efbb513 + 24c143c + 307427e + 4c7a822 + 25d3bd7 + 40bfe7f + 70ca2ff + 76fd684 + 2b82c0f + 1565409 + fd7399e + cb27129 + 62ca6c9 + 7b73995 + 18f93e0 + 72fe59b + 9f5b116 + 28a04a3 + b56ee4d + 9287e61 + 1a420ec + 6a43cc1 + ad11b96 + cf95523 + 25ef603 + 894f762 + c00c005 + 69fb7fc + 57cb4a0 + e25b09c + 17a7c5c + c526cd4 + 518ca6f + 57fa76c + 853c28f + 520cebc + dc5f609 + ccf1c7e + 251b79e + 78fbb55 + fcc04e7 + 9bf2948 + 9561532 + b614ad3 + 954a3b1 + dacc257 + 07a262d + 59c02c3 + 7064caa + 6f75739 + 747b7ed + eb24d30 + 8ff8298 + 97c61d8 + da4af46 + 11c9caf + cc11df8 + cd54577 + 298afbb commit dc32703
Show file tree
Hide file tree
Showing 28 changed files with 272 additions and 140 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
"dev-develop": "2.5-dev"
"dev-master": "2.1-dev",
"dev-develop": "2.2-dev"
}
},
"autoload-dev": {
Expand Down
4 changes: 0 additions & 4 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config;
Expand All @@ -21,9 +20,6 @@
*
* Implements Countable, Iterator and ArrayAccess
* to facilitate easy access to the data.
*
* @category Zend
* @package Zend_Config
*/
class Config implements Countable, Iterator, ArrayAccess
{
Expand Down
6 changes: 0 additions & 6 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config\Exception;

/**
* @category Zend
* @package Zend_Config
* @subpackage Exception
*/
interface ExceptionInterface
{}
6 changes: 0 additions & 6 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config\Exception;

/**
* @category Zend
* @package Zend_Config
* @subpackage Exception
*/
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{}
6 changes: 0 additions & 6 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config\Exception;

/**
* @category Zend
* @package Zend_Config
* @subpackage Exception
*/
class RuntimeException extends \RuntimeException implements ExceptionInterface
{}
132 changes: 127 additions & 5 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config;

use Zend\Stdlib\ArrayUtils;

/**
* @category Zend
* @package Zend_Config
*/
class Factory
{
/**
Expand All @@ -25,6 +20,13 @@ class Factory
*/
public static $readers = null;

/**
* Plugin manager for loading writers
*
* @var null|WriterPluginManager
*/
public static $writers = null;

/**
* Registered config file extensions.
* key is extension, value is reader instance or plugin name
Expand All @@ -38,6 +40,19 @@ class Factory
'yaml' => 'yaml',
);

/**
* Register config file extensions for writing
* key is extension, value is writer instance or plugin name
*
* @var array
*/
protected static $writerExtensions = array(
'php' => 'php',
'ini' => 'ini',
'json' => 'json',
'xml' => 'xml',
'yaml' => 'yaml',
);

/**
* Read a config from a file.
Expand Down Expand Up @@ -107,10 +122,67 @@ public static function fromFiles(array $files, $returnConfigObject = false)
return ($returnConfigObject) ? new Config($config) : $config;
}

/**
* Writes a config to a file
*
* @param string $filename
* @param array|Config $config
* @return boolean TRUE on success | FALSE on failure
* @throws Exception\RuntimeException
* @throws Exception\InvalidArgumentException
*/
public static function toFile($filename, $config)
{
if (
(is_object($config) && !($config instanceOf Config)) ||
(!is_object($config) && !is_array($config))
) {
throw new Exception\InvalidArgumentException(
__METHOD__." \$config should be an array or instance of Zend\\Config\\Config"
);
}

$extension = substr(strrchr($filename, '.'), 1);
$directory = dirname($filename);

if (!is_dir($directory)) {
throw new Exception\RuntimeException(
"Directory '{$directory}' does not exists!"
);
}

if (!is_writable($directory)) {
throw new Exception\RuntimeException(
"Cannot write in directory '{$directory}'"
);
}

if (!isset(self::$writerExtensions[$extension])) {
throw new Exception\RuntimeException(
"Unsupported config file extension: '.{$extension}' for writing."
);
}

$writer = self::$writerExtensions[$extension];
if (($writer instanceOf Writer\AbstractWriter) === false) {
$writer = self::getWriterPluginManager()->get($writer);
self::$writerExtensions[$extension] = $writer;
}

if (is_object($config)) {
$config = $config->toArray();
}

$content = $writer->processConfig($config);

return (bool) (file_put_contents($filename, $content) !== false);
}

/**
* Set reader plugin manager
*
* @param ReaderPluginManager $readers
* @return void
*/
public static function setReaderPluginManager(ReaderPluginManager $readers)
{
Expand All @@ -130,12 +202,38 @@ public static function getReaderPluginManager()
return static::$readers;
}

/**
* Set writer plugin manager
*
* @param WriterPluginManager $writers
* @return void
*/
public static function setWriterPluginManager(WriterPluginManager $writers)
{
self::$writers = $writers;
}

/**
* Get the writer plugin manager
*
* @return WriterPluginManager
*/
public static function getWriterPluginManager()
{
if (static::$writers === null) {
static::$writers = new WriterPluginManager();
}

return static::$writers;
}

/**
* Set config reader for file extension
*
* @param string $extension
* @param string|Reader\ReaderInterface $reader
* @throws Exception\InvalidArgumentException
* @return void
*/
public static function registerReader($extension, $reader)
{
Expand All @@ -152,4 +250,28 @@ public static function registerReader($extension, $reader)

static::$extensions[$extension] = $reader;
}

/**
* Set config writer for file extension
*
* @param string $extension
* @param string|Writer\AbstractWriter $writer
* @throw Exception\InvalidArgumentException
* @return void
*/
public static function registerWriter($extension, $writer)
{
$extension = strtolower($extension);

if (!is_string($writer) && !$writer instanceof Writer\AbstractWriter) {
throw new Exception\InvalidArgumentException(sprintf(
'Writer should be plugin name, class name or ' .
'instance of %s\Writer\AbstractWriter; received "%s"',
__NAMESPACE__,
(is_object($writer) ? get_class($writer) : gettype($writer))
));
}

self::$writerExtensions[$extension] = $writer;
}
}
6 changes: 0 additions & 6 deletions src/Processor/Constant.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config\Processor;

/**
* @category Zend
* @package Zend_Config
* @subpackage Processor
*/
class Constant extends Token implements ProcessorInterface
{
/**
Expand Down
6 changes: 0 additions & 6 deletions src/Processor/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config\Processor;
Expand All @@ -14,11 +13,6 @@
use Zend\Config\Exception;
use Zend\Filter\FilterInterface as ZendFilter;

/**
* @category Zend
* @package Zend_Config
* @subpackage Processor
*/
class Filter implements ProcessorInterface
{
/**
Expand Down
6 changes: 0 additions & 6 deletions src/Processor/ProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config\Processor;

use Zend\Config\Config;

/**
* @category Zend
* @package Zend_Config
* @subpackage Processor
*/
interface ProcessorInterface
{
/**
Expand Down
6 changes: 0 additions & 6 deletions src/Processor/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config\Processor;
Expand All @@ -14,11 +13,6 @@
use Zend\Config\Exception;
use Zend\Stdlib\PriorityQueue;

/**
* @category Zend
* @package Zend_Config
* @subpackage Processor
*/
class Queue extends PriorityQueue implements ProcessorInterface
{
/**
Expand Down
6 changes: 0 additions & 6 deletions src/Processor/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config\Processor;
Expand All @@ -14,11 +13,6 @@
use Zend\Config\Config;
use Zend\Config\Exception;

/**
* @category Zend
* @package Zend_Config
* @subpackage Processor
*/
class Token implements ProcessorInterface
{
/**
Expand Down
6 changes: 0 additions & 6 deletions src/Processor/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Config
*/

namespace Zend\Config\Processor;
Expand All @@ -14,11 +13,6 @@
use Zend\Config\Exception;
use Zend\I18n\Translator\Translator as ZendTranslator;

/**
* @category Zend
* @package Zend_Config
* @subpackage Processor
*/
class Translator implements ProcessorInterface
{
/**
Expand Down
Loading

0 comments on commit dc32703

Please sign in to comment.