From 3e458706d4c1115ebb85c282af4c4f39cc7fdef3 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Sat, 30 Jun 2012 00:32:39 +0400 Subject: [PATCH 1/4] [I18n] Translator processor --- src/Factory.php | 86 +++++++++++-------- src/Processor/Filter.php | 2 +- src/Processor/Queue.php | 2 +- src/Processor/Token.php | 2 +- src/Processor/Translator.php | 4 +- src/ReaderPluginManager.php | 66 ++++++++++++++ test/ProcessorTest.php | 37 ++++---- .../{messages.php => translations-de_DE.php} | 0 8 files changed, 138 insertions(+), 61 deletions(-) create mode 100644 src/ReaderPluginManager.php rename test/_files/{messages.php => translations-de_DE.php} (100%) diff --git a/src/Factory.php b/src/Factory.php index cf6a292..19714c8 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -19,24 +19,25 @@ class Factory { /** - * Readers used for config files. - * array key is extension, array value is reader instance or class name + * Plugin manager for loading readers * - * @var array + * @var null|ReaderPluginManager */ - protected static $readers = array( - 'ini' => 'Zend\Config\Reader\Ini', - 'json' => 'Zend\Config\Reader\Json', - 'xml' => 'Zend\Config\Reader\Xml', - 'yaml' => 'Zend\Config\Reader\Yaml', - ); + public static $readers = null; /** - * The reader manager + * Registered config file extensions. + * key is extension, value is reader instance or plugin name * - * @var null|ReaderPluginManager + * @var array */ - protected static $plugins = null; + protected static $extensions = array( + 'ini' => 'ini', + 'json' => 'json', + 'xml' => 'xml', + 'yaml' => 'yaml', + ); + /** * Read a config from a file. @@ -44,6 +45,7 @@ class Factory * @param string $filename * @param boolean $returnConfigObject * @return array|Config + * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException */ public static function fromFile($filename, $returnConfigObject = false) @@ -68,25 +70,11 @@ public static function fromFile($filename, $returnConfigObject = false) } $config = include $filename; - } elseif (isset(self::$readers[$extension])) { - $reader = self::$readers[$extension]; - if (is_string($reader)) { - if (!class_exists($reader)) { - throw new Exception\RuntimeException(sprintf( - 'Unable to locate reader class "%s"; class does not exist', - $reader - )); - } - - $reader = new $reader(); - } - + } elseif (isset(self::$extensions[$extension])) { + $reader = self::$extensions[$extension]; if (!$reader instanceof Reader\ReaderInterface) { - throw new Exception\RuntimeException(sprintf( - 'Reader should be an instance of %s\Reader\ReaderInterface; received "%s"', - __NAMESPACE__, - (is_object($reader) ? get_class($reader) : gettype($reader)) - )); + $reader = self::getReaderPluginManager()->get($reader); + self::$extensions[$extension] = $reader; } /** @var Reader\ReaderInterface $reader */ @@ -119,11 +107,34 @@ public static function fromFiles(array $files, $returnConfigObject = false) return ($returnConfigObject) ? new Config($config) : $config; } + /** + * Set reader plugin manager + * + * @param ReaderPluginManager $readers + */ + public static function setReaderPluginManager(ReaderPluginManager $readers) + { + self::$readers = $readers; + } + + /** + * Get the reader plugin manager + * + * @return ReaderPluginManager + */ + public static function getReaderPluginManager() + { + if (static::$readers === null) { + static::$readers = new ReaderPluginManager(); + } + return static::$readers; + } + /** * Set config reader for file extension * - * @param string $extension - * @param string|Reader\ReaderInterface $reader + * @param string $extension + * @param string|Reader\ReaderInterface $reader * @throws Exception\InvalidArgumentException */ public static function registerReader($extension, $reader) @@ -131,11 +142,14 @@ public static function registerReader($extension, $reader) $extension = strtolower($extension); if (!is_string($reader) && !$reader instanceof Reader\ReaderInterface) { - throw new Exception\InvalidArgumentException( - 'Reader should be class name or instance of Zend\Config\Reader\ReaderInterface' - ); + throw new Exception\InvalidArgumentException(sprintf( + 'Reader should be plugin name, class name or ' . + 'instance of %s\Reader\ReaderInterface; recieved "%s"', + __NAMESPACE__, + (is_object($reader) ? get_class($reader) : gettype($reader)) + )); } - self::$readers[$extension] = $reader; + self::$extensions[$extension] = $reader; } } diff --git a/src/Processor/Filter.php b/src/Processor/Filter.php index 3dbe6f5..9dc2b89 100644 --- a/src/Processor/Filter.php +++ b/src/Processor/Filter.php @@ -66,7 +66,7 @@ public function getFilter() public function process(Config $config) { if ($config->isReadOnly()) { - throw new Exception\InvalidArgumentException('Cannot parse config because it is read-only'); + throw new Exception\InvalidArgumentException('Cannot process config because it is read-only'); } /** diff --git a/src/Processor/Queue.php b/src/Processor/Queue.php index 6f894c0..e369149 100644 --- a/src/Processor/Queue.php +++ b/src/Processor/Queue.php @@ -31,7 +31,7 @@ class Queue extends PriorityQueue implements ProcessorInterface public function process(Config $config) { if ($config->isReadOnly()) { - throw new Exception\InvalidArgumentException('Cannot parse config because it is read-only'); + throw new Exception\InvalidArgumentException('Cannot process config because it is read-only'); } foreach ($this as $parser) { diff --git a/src/Processor/Token.php b/src/Processor/Token.php index 2e4f0a5..0a64174 100644 --- a/src/Processor/Token.php +++ b/src/Processor/Token.php @@ -206,7 +206,7 @@ protected function buildMap() public function process(Config $config) { if ($config->isReadOnly()) { - throw new Exception\InvalidArgumentException('Cannot parse config because it is read-only'); + throw new Exception\InvalidArgumentException('Cannot process config because it is read-only'); } if ($this->map === null) { diff --git a/src/Processor/Translator.php b/src/Processor/Translator.php index 1768c1d..e260537 100644 --- a/src/Processor/Translator.php +++ b/src/Processor/Translator.php @@ -118,7 +118,7 @@ public function getTextDomain() public function process(Config $config) { if ($config->isReadOnly()) { - throw new Exception\InvalidArgumentException('Cannot parse config because it is read-only'); + throw new Exception\InvalidArgumentException('Cannot process config because it is read-only'); } /** @@ -128,7 +128,7 @@ public function process(Config $config) if ($val instanceof Config) { $this->process($val); } else { - $config->$key = $this->translator->translate($val, $this->textDomain, $this->locale); + $config->{$key} = $this->translator->translate($val, $this->textDomain, $this->locale); } } diff --git a/src/ReaderPluginManager.php b/src/ReaderPluginManager.php new file mode 100644 index 0000000..008bd0d --- /dev/null +++ b/src/ReaderPluginManager.php @@ -0,0 +1,66 @@ + 'Zend\Config\Reader\Ini', + 'json' => 'Zend\Config\Reader\Json', + 'xml' => 'Zend\Config\Reader\Xml', + 'yaml' => 'Zend\Config\Reader\Yaml', + ); + + /** + * Validate the plugin + * Checks that the reader loaded is an instance of Reader\ReaderInterface. + * + * @param Reader\ReaderInterface $plugin + * @return void + * @throws Exception\InvalidArgumentException if invalid + */ + public function validatePlugin($plugin) + { + if ($plugin instanceof Reader\ReaderInterface) { + // we're okay + return; + } + + throw new Exception\InvalidArgumentException(sprintf( + 'Plugin of type %s is invalid; must implement %s\Reader\ReaderInterface', + (is_object($plugin) ? get_class($plugin) : gettype($plugin)), + __NAMESPACE__ + )); + } +} diff --git a/test/ProcessorTest.php b/test/ProcessorTest.php index 9aff44d..196ed07 100644 --- a/test/ProcessorTest.php +++ b/test/ProcessorTest.php @@ -45,7 +45,7 @@ class ProcessorTest extends \PHPUnit_Framework_TestCase { protected $nested; protected $tokenBare, $tokenPrefix, $tokenSuffix, $tokenSurround, $tokenSurroundMixed; - protected $translatorData, $translatorStrings; + protected $translatorData, $translatorFile; protected $userConstants, $phpConstants; protected $filter; @@ -131,10 +131,7 @@ public function setUp() ) ); - $this->translatorStrings = array( - 'one dog' => 'ein Hund', - 'two dogs' => 'zwei Hunde' - ); + $this->translatorFile = realpath(__DIR__ . '/_files/translations-de_DE.php'); $this->filter = array( 'simple' => 'some MixedCase VALue', @@ -214,7 +211,7 @@ public function testTokenReadOnly() $processor->addToken('BARETOKEN', 'some replaced value'); $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', - 'Cannot parse config because it is read-only'); + 'Cannot process config because it is read-only'); $processor->process($config); } @@ -351,37 +348,37 @@ public function testTranslator() { $config = new Config($this->translatorData, true); $translator = new Translator(); - $translator->addTranslationFile('phpArray', realpath(__DIR__ . '/_files/messages.php')); - $processor = new TranslatorProcessor($translator, 'default', 'de_DE'); + $translator->addTranslationFile('phparray', $this->translatorFile); + $processor = new TranslatorProcessor($translator); $processor->process($config); $this->assertEquals('oneDog', $config->pages[0]->id); $this->assertEquals('ein Hund', $config->pages[0]->label); - $this->assertEquals('twoDogs', $config->pages[1]->id); $this->assertEquals('zwei Hunde', $config->pages[1]->label); } - /* public function testTranslatorReadOnly() { - $config = new Config($this->translator, false); + $config = new Config($this->translatorData, false); $translator = new Translator(); - $processor = new TranslatorProcessor($translator, 'default', 'de_DE'); + $processor = new TranslatorProcessor($translator); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', - 'Cannot parse config because it is read-only'); + 'Cannot process config because it is read-only'); $processor->process($config); } public function testTranslatorSingleValue() { - $translator = new Translator(Translator::AN_ARRAY, $this->translatorStrings, 'de_DE'); - $processor = new TranslatorProcessor($translator); - $word = 'one dog'; - $this->assertEquals('ein Hund', $processor->processValue($word)); + $translator = new Translator(); + $translator->addTranslationFile('phparray', $this->translatorFile); + $processor = new TranslatorProcessor($translator); + + $this->assertEquals('ein Hund', $processor->processValue('one dog')); } - */ + public function testFilter() { $config = new Config($this->filter, true); @@ -402,7 +399,7 @@ public function testFilterReadOnly() $processor = new FilterProcessor($filter); $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', - 'Cannot parse config because it is read-only'); + 'Cannot process config because it is read-only'); $processor->process($config); } @@ -451,7 +448,7 @@ public function testQueueReadOnly() $queue->insert($lowerProcessor); $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', - 'Cannot parse config because it is read-only'); + 'Cannot process config because it is read-only'); $queue->process($config); } diff --git a/test/_files/messages.php b/test/_files/translations-de_DE.php similarity index 100% rename from test/_files/messages.php rename to test/_files/translations-de_DE.php From ccbdbdc2e0a4b1af96ca3c91602018f63df8dc0e Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Sat, 30 Jun 2012 01:25:10 +0400 Subject: [PATCH 2/4] fixed missing file exceptions --- src/Config.php | 15 ++++++++++----- src/Exception/InvalidArgumentException.php | 3 ++- src/Factory.php | 2 +- src/Reader/Ini.php | 2 +- src/Reader/Json.php | 2 +- src/Reader/Xml.php | 2 +- src/Reader/Yaml.php | 6 ++++-- test/FactoryTest.php | 20 ++++++++++++++++---- test/Reader/AbstractReaderTestCase.php | 3 ++- 9 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/Config.php b/src/Config.php index c6d6bfd..70fa03a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -16,6 +16,13 @@ use Zend\Stdlib\ArrayUtils; /** + * Provides a property based interface to an array. + * The data are read-only unless $allowModifications is set to true + * on construction. + * + * Implements Countable, Iterator and ArrayAccess + * to facilitate easy access to the data. + * * @category Zend * @package Zend_Config */ @@ -51,12 +58,10 @@ class Config implements Countable, Iterator, ArrayAccess protected $skipNextIteration; /** - * Zend\Config provides a property based interface to - * an array. The data are read-only unless $allowModifications - * is set to true on construction. + * Constructor. * - * Zend\Config also implements Countable, Iterator and ArrayAccess to - * facilitate easy access to the data. + * Data is read-only unless $allowModifications is set to true + * on construction. * * @param array $array * @param boolean $allowModifications diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 9738cb0..55773a6 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -15,5 +15,6 @@ * @package Zend_Config * @subpackage Exception */ -class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface +class InvalidArgumentException extends \InvalidArgumentException implements + ExceptionInterface {} diff --git a/src/Factory.php b/src/Factory.php index 19714c8..e18b2d1 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -53,7 +53,7 @@ public static function fromFile($filename, $returnConfigObject = false) $pathinfo = pathinfo($filename); if (!isset($pathinfo['extension'])) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( 'Filename "%s" is missing an extension and cannot be auto-detected', $filename )); diff --git a/src/Reader/Ini.php b/src/Reader/Ini.php index 209e36f..b02df3b 100644 --- a/src/Reader/Ini.php +++ b/src/Reader/Ini.php @@ -68,7 +68,7 @@ public function getNestSeparator() public function fromFile($filename) { if (!is_file($filename) || !is_readable($filename)) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( "File '%s' doesn't exist or not readable", $filename )); diff --git a/src/Reader/Json.php b/src/Reader/Json.php index 2f5b59a..01a5f9e 100644 --- a/src/Reader/Json.php +++ b/src/Reader/Json.php @@ -41,7 +41,7 @@ class Json implements ReaderInterface public function fromFile($filename) { if (!is_file($filename) || !is_readable($filename)) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( "File '%s' doesn't exist or not readable", $filename )); diff --git a/src/Reader/Xml.php b/src/Reader/Xml.php index 5fa2147..ed6ebe8 100644 --- a/src/Reader/Xml.php +++ b/src/Reader/Xml.php @@ -59,7 +59,7 @@ class Xml implements ReaderInterface public function fromFile($filename) { if (!is_file($filename) || !is_readable($filename)) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( "File '%s' doesn't exist or not readable", $filename )); diff --git a/src/Reader/Yaml.php b/src/Reader/Yaml.php index 7b70ee6..5c638cc 100644 --- a/src/Reader/Yaml.php +++ b/src/Reader/Yaml.php @@ -61,7 +61,9 @@ public function __construct($yamlDecoder = null) public function setYamlDecoder($yamlDecoder) { if (!is_callable($yamlDecoder)) { - throw new Exception\InvalidArgumentException('Invalid parameter to setYamlDecoder() - must be callable'); + throw new Exception\RuntimeException( + 'Invalid parameter to setYamlDecoder() - must be callable' + ); } $this->yamlDecoder = $yamlDecoder; return $this; @@ -88,7 +90,7 @@ public function getYamlDecoder() public function fromFile($filename) { if (!is_file($filename) || !is_readable($filename)) { - throw new Exception\InvalidArgumentException(sprintf( + throw new Exception\RuntimeException(sprintf( "File '%s' doesn't exist or not readable", $filename )); diff --git a/test/FactoryTest.php b/test/FactoryTest.php index fd0c3b8..29f91f9 100644 --- a/test/FactoryTest.php +++ b/test/FactoryTest.php @@ -122,13 +122,13 @@ public function testNonExistentFileThrowsRuntimeException() $config = Factory::fromFile('foo.bar'); } - public function testInvalidFileExtensionThrowsInvalidArgumentException() + public function testUnsupportedFileExtensionThrowsRuntimeException() { $this->setExpectedException('RuntimeException'); $config = Factory::fromFile(__DIR__ . '/TestAssets/bad.ext'); } - public function testFactoryCanRegisterCustomReaders() + public function testFactoryCanRegisterCustomReaderInstance() { Factory::registerReader('dum', new Reader\TestAssets\DummyReader()); @@ -136,9 +136,21 @@ public function testFactoryCanRegisterCustomReaders() $this->assertInstanceOf('Zend\Config\Config', $configObject); $this->assertEquals($configObject['one'], 1); - $this->assertEquals($configObject['two'], 2); - $this->assertEquals($configObject['three'], 3); } + public function testFactoryCanRegisterCustomReaderPlugn() + { + $dummyReader = new Reader\TestAssets\DummyReader(); + Factory::getReaderPluginManager()->setService('DummyReader',$dummyReader); + + Factory::registerReader('dum', 'DummyReader'); + + $configObject = Factory::fromFile(__DIR__ . '/TestAssets/dummy.dum', true); + $this->assertInstanceOf('Zend\Config\Config', $configObject); + + $this->assertEquals($configObject['one'], 1); + } + + } diff --git a/test/Reader/AbstractReaderTestCase.php b/test/Reader/AbstractReaderTestCase.php index 190aa3a..3b8b4b0 100644 --- a/test/Reader/AbstractReaderTestCase.php +++ b/test/Reader/AbstractReaderTestCase.php @@ -43,6 +43,7 @@ abstract class AbstractReaderTestCase extends TestCase /** * Get test asset name for current test case. * + * @param string $name * @return string */ abstract protected function getTestAssetPath($name); @@ -50,7 +51,7 @@ abstract protected function getTestAssetPath($name); public function testMissingFile() { $filename = $this->getTestAssetPath('no-file'); - $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', "doesn't exist or not readable"); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', "doesn't exist or not readable"); $config = $this->reader->fromFile($filename); } From d33369558f2036eec8f77dca074b6380be7233e8 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Mon, 2 Jul 2012 02:38:20 +0400 Subject: [PATCH 3/4] fix use statements --- src/Processor/Constant.php | 5 ----- src/Processor/Filter.php | 2 -- src/Processor/Token.php | 1 - src/Processor/Translator.php | 4 ++-- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/Processor/Constant.php b/src/Processor/Constant.php index 4fc1604..9fbae8d 100644 --- a/src/Processor/Constant.php +++ b/src/Processor/Constant.php @@ -10,11 +10,6 @@ namespace Zend\Config\Processor; -use Zend\Config\Config; -use Zend\Config\Exception\InvalidArgumentException; -use Traversable; -use ArrayObject; - /** * @category Zend * @package Zend_Config diff --git a/src/Processor/Filter.php b/src/Processor/Filter.php index 9dc2b89..e8154da 100644 --- a/src/Processor/Filter.php +++ b/src/Processor/Filter.php @@ -13,8 +13,6 @@ use Zend\Config\Config; use Zend\Config\Exception; use Zend\Filter\FilterInterface as ZendFilter; -use Traversable; -use ArrayObject; /** * @category Zend diff --git a/src/Processor/Token.php b/src/Processor/Token.php index 0a64174..1b653ae 100644 --- a/src/Processor/Token.php +++ b/src/Processor/Token.php @@ -13,7 +13,6 @@ use Zend\Config\Config; use Zend\Config\Exception; use Traversable; -use ArrayObject; /** * @category Zend diff --git a/src/Processor/Translator.php b/src/Processor/Translator.php index e260537..8794a73 100644 --- a/src/Processor/Translator.php +++ b/src/Processor/Translator.php @@ -30,7 +30,7 @@ class Translator implements ProcessorInterface protected $translator; /** - * @var Locale|string|null + * @var string|null */ protected $locale = null; @@ -45,7 +45,7 @@ class Translator implements ProcessorInterface * * @param ZendTranslator $translator * @param string $textDomain - * @param Locale|string|null $locale + * @param string|null $locale */ public function __construct(ZendTranslator $translator, $textDomain = 'default', $locale = null) { From 6c552f596ba7077ca9e78cb88a4b3876fc65e868 Mon Sep 17 00:00:00 2001 From: Denis Portnov Date: Mon, 2 Jul 2012 02:58:53 +0400 Subject: [PATCH 4/4] CS updates --- src/Exception/InvalidArgumentException.php | 3 +- src/Processor/Token.php | 8 +-- src/Processor/Translator.php | 5 +- src/Writer/AbstractWriter.php | 9 ---- test/ConfigTest.php | 2 +- test/Reader/AbstractReaderTestCase.php | 6 +-- test/Reader/IniTest.php | 2 +- test/Reader/JsonTest.php | 2 +- test/Reader/XmlTest.php | 2 +- test/Reader/YamlTest.php | 2 +- test/Writer/AbstractWriterTestCase.php | 8 +-- test/Writer/IniTest.php | 12 ++--- test/Writer/JsonTest.php | 11 ++-- test/Writer/PhpArrayTest.php | 6 +-- test/Writer/TestAssets/PhpReader.php | 11 ++++ test/Writer/XmlTest.php | 8 +-- test/Writer/YamlTest.php | 9 ++-- test/Writer/{files => _files}/allsections.ini | 52 +++++++++---------- .../Writer/{files => _files}/allsections.json | 0 test/Writer/{files => _files}/allsections.xml | 0 .../Writer/{files => _files}/allsections.yaml | 0 test/Writer/files/PhpReader.php | 9 ---- 22 files changed, 74 insertions(+), 93 deletions(-) create mode 100644 test/Writer/TestAssets/PhpReader.php rename test/Writer/{files => _files}/allsections.ini (93%) rename test/Writer/{files => _files}/allsections.json (100%) rename test/Writer/{files => _files}/allsections.xml (100%) rename test/Writer/{files => _files}/allsections.yaml (100%) delete mode 100644 test/Writer/files/PhpReader.php diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index 55773a6..9738cb0 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -15,6 +15,5 @@ * @package Zend_Config * @subpackage Exception */ -class InvalidArgumentException extends \InvalidArgumentException implements - ExceptionInterface +class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface {} diff --git a/src/Processor/Token.php b/src/Processor/Token.php index 1b653ae..cf725ba 100644 --- a/src/Processor/Token.php +++ b/src/Processor/Token.php @@ -53,8 +53,8 @@ class Token implements ProcessorInterface * Token Processor walks through a Config structure and replaces all * occurences of tokens with supplied values. * - * @param array|Config|ArrayObject|Traversable $tokens Associative array of TOKEN => value - * to replace it with + * @param array|Config|Traversable $tokens Associative array of TOKEN => value + * to replace it with * @param string $prefix * @param string $suffix * @internal param array $options @@ -111,8 +111,8 @@ public function getSuffix() /** * Set token registry. * - * @param array|Config|Traversable $tokens Associative array of TOKEN => value - * to replace it with + * @param array|Config|Traversable $tokens Associative array of TOKEN => value + * to replace it with * @return Token * @throws Exception\InvalidArgumentException */ diff --git a/src/Processor/Translator.php b/src/Processor/Translator.php index 8794a73..bb2c623 100644 --- a/src/Processor/Translator.php +++ b/src/Processor/Translator.php @@ -13,9 +13,6 @@ use Zend\Config\Config; use Zend\Config\Exception; use Zend\I18n\Translator\Translator as ZendTranslator; -use Locale; -use Traversable; -use ArrayObject; /** * @category Zend @@ -83,7 +80,7 @@ public function setLocale($locale) } /** - * @return Locale|string|null + * @return string|null */ public function getLocale() { diff --git a/src/Writer/AbstractWriter.php b/src/Writer/AbstractWriter.php index 4d993ef..1d6df80 100644 --- a/src/Writer/AbstractWriter.php +++ b/src/Writer/AbstractWriter.php @@ -30,13 +30,8 @@ abstract class AbstractWriter implements WriterInterface * @param mixed $config * @param boolean $exclusiveLock * @return void -<<<<<<< HEAD * @throws Exception\InvalidArgumentException * @throws Exception\RuntimeException -======= - * @throws Exception\RuntimeException - * @throws Exception\InvalidArgumentException ->>>>>>> initial commit, remove Broker */ public function toFile($filename, $config, $exclusiveLock = true) { @@ -66,11 +61,7 @@ function($error, $message = '', $file = '', $line = 0) use ($filename) { * * @see WriterInterface::toString() * @param mixed $config -<<<<<<< HEAD - * @return void -======= * @return string ->>>>>>> initial commit, remove Broker * @throws Exception\InvalidArgumentException */ public function toString($config) diff --git a/test/ConfigTest.php b/test/ConfigTest.php index c67efc2..b1fe550 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config; -use \Zend\Config\Config; +use Zend\Config\Config; /** * @category Zend diff --git a/test/Reader/AbstractReaderTestCase.php b/test/Reader/AbstractReaderTestCase.php index 3b8b4b0..55644b8 100644 --- a/test/Reader/AbstractReaderTestCase.php +++ b/test/Reader/AbstractReaderTestCase.php @@ -21,9 +21,9 @@ namespace ZendTest\Config\Reader; -use \PHPUnit_Framework_TestCase as TestCase, - \Zend\Config\Reader\ReaderInterface, - \ReflectionClass; +use PHPUnit_Framework_TestCase as TestCase; +use Zend\Config\Reader\ReaderInterface; +use ReflectionClass; /** * @category Zend diff --git a/test/Reader/IniTest.php b/test/Reader/IniTest.php index 82b101e..f0d5edb 100644 --- a/test/Reader/IniTest.php +++ b/test/Reader/IniTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config\Reader; -use \Zend\Config\Reader\Ini; +use Zend\Config\Reader\Ini; /** * @category Zend diff --git a/test/Reader/JsonTest.php b/test/Reader/JsonTest.php index b52bb2d..522cdb7 100644 --- a/test/Reader/JsonTest.php +++ b/test/Reader/JsonTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config\Reader; -use \Zend\Config\Reader\Json; +use Zend\Config\Reader\Json; /** * @category Zend diff --git a/test/Reader/XmlTest.php b/test/Reader/XmlTest.php index eb25359..556ba6f 100644 --- a/test/Reader/XmlTest.php +++ b/test/Reader/XmlTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config\Reader; -use \Zend\Config\Reader\Xml; +use Zend\Config\Reader\Xml; /** * @category Zend diff --git a/test/Reader/YamlTest.php b/test/Reader/YamlTest.php index 33bd200..0e08d0b 100644 --- a/test/Reader/YamlTest.php +++ b/test/Reader/YamlTest.php @@ -21,7 +21,7 @@ namespace ZendTest\Config\Reader; -use \Zend\Config\Reader\Yaml as YamlReader; +use Zend\Config\Reader\Yaml as YamlReader; /** * @category Zend diff --git a/test/Writer/AbstractWriterTestCase.php b/test/Writer/AbstractWriterTestCase.php index 3c1e91c..2039b9c 100644 --- a/test/Writer/AbstractWriterTestCase.php +++ b/test/Writer/AbstractWriterTestCase.php @@ -21,8 +21,8 @@ namespace ZendTest\Config\Writer; -use \PHPUnit_Framework_TestCase as TestCase, - \Zend\Config\Config; +use PHPUnit_Framework_TestCase as TestCase; +use Zend\Config\Config; /** * @category Zend @@ -35,13 +35,13 @@ abstract class AbstractWriterTestCase extends TestCase { /** - * @var ReaderInterface + * @var \Zend\Config\Reader\ReaderInterface */ protected $reader; /** * - * @var WriterInterface + * @var \Zend\Config\Writer\WriterInterface */ protected $writer; diff --git a/test/Writer/IniTest.php b/test/Writer/IniTest.php index e9c1b25..94a0401 100644 --- a/test/Writer/IniTest.php +++ b/test/Writer/IniTest.php @@ -21,9 +21,9 @@ namespace ZendTest\Config\Writer; -use \Zend\Config\Writer\Ini as IniWriter; -use \Zend\Config\Config; -use \Zend\Config\Reader\Ini as IniReader; +use Zend\Config\Writer\Ini as IniWriter; +use Zend\Config\Config; +use Zend\Config\Reader\Ini as IniReader; /** * @category Zend @@ -35,15 +35,12 @@ */ class IniTest extends AbstractWriterTestCase { - public function setUp() { $this->reader = new IniReader(); $this->writer = new IniWriter(); } - - public function testNoSection() { $config = new Config(array('test' => 'foo', 'test2' => array('test3' => 'bar'))); @@ -58,13 +55,12 @@ public function testNoSection() public function testWriteAndReadOriginalFile() { - $config = $this->reader->fromFile(__DIR__ . '/files/allsections.ini'); + $config = $this->reader->fromFile(__DIR__ . '/_files/allsections.ini'); $this->writer->toFile($this->getTestAssetFileName(), $config); $config = $this->reader->fromFile($this->getTestAssetFileName()); $this->assertEquals('multi', $config['all']['one']['two']['three']); - } } diff --git a/test/Writer/JsonTest.php b/test/Writer/JsonTest.php index 51a57a7..44656bc 100644 --- a/test/Writer/JsonTest.php +++ b/test/Writer/JsonTest.php @@ -21,9 +21,9 @@ namespace ZendTest\Config\Writer; -use \Zend\Config\Writer\Json as JsonWriter; -use \Zend\Config\Config; -use \Zend\Config\Reader\Json as JsonReader; +use Zend\Config\Writer\Json as JsonWriter; +use Zend\Config\Config; +use Zend\Config\Reader\Json as JsonReader; /** * @category Zend @@ -35,15 +35,12 @@ */ class JsonTest extends AbstractWriterTestCase { - public function setUp() { $this->reader = new JsonReader(); $this->writer = new JsonWriter(); } - - public function testNoSection() { $config = new Config(array('test' => 'foo', 'test2' => array('test3' => 'bar'))); @@ -58,7 +55,7 @@ public function testNoSection() public function testWriteAndReadOriginalFile() { - $config = $this->reader->fromFile(__DIR__ . '/files/allsections.json'); + $config = $this->reader->fromFile(__DIR__ . '/_files/allsections.json'); $this->writer->toFile($this->getTestAssetFileName(), $config); diff --git a/test/Writer/PhpArrayTest.php b/test/Writer/PhpArrayTest.php index 5077a5e..8caf8e3 100644 --- a/test/Writer/PhpArrayTest.php +++ b/test/Writer/PhpArrayTest.php @@ -21,9 +21,9 @@ namespace ZendTest\Config\Writer; -use \Zend\Config\Writer\PhpArray; -use \Zend\Config\Config; -use ZendTest\Config\Writer\files\PhpReader; +use Zend\Config\Writer\PhpArray; +use Zend\Config\Config; +use ZendTest\Config\Writer\TestAssets\PhpReader; /** * @category Zend diff --git a/test/Writer/TestAssets/PhpReader.php b/test/Writer/TestAssets/PhpReader.php new file mode 100644 index 0000000..ba7a527 --- /dev/null +++ b/test/Writer/TestAssets/PhpReader.php @@ -0,0 +1,11 @@ +reader->fromFile(__DIR__ . '/files/allsections.yaml'); + $config = $this->reader->fromFile(__DIR__ . '/_files/allsections.yaml'); $this->writer->toFile($this->getTestAssetFileName(), $config); diff --git a/test/Writer/files/allsections.ini b/test/Writer/_files/allsections.ini similarity index 93% rename from test/Writer/files/allsections.ini rename to test/Writer/_files/allsections.ini index d4eef2d..4eaa75b 100644 --- a/test/Writer/files/allsections.ini +++ b/test/Writer/_files/allsections.ini @@ -1,26 +1,26 @@ -[all] -hostname = all -name = thisname -db.host = 127.0.0.1 -db.user = username -db.pass = password -db.name = live -one.two.three = multi - -[staging] -hostname = staging -db.name = dbstaging -debug = false - -[debug] -hostname = debug -debug = true -values.changed = yes -db.name = dbdebug -special.no = no -special.null = null -special.false = false - -[other_staging] -only_in = otherStaging -db.pass = anotherpwd +[all] +hostname = all +name = thisname +db.host = 127.0.0.1 +db.user = username +db.pass = password +db.name = live +one.two.three = multi + +[staging] +hostname = staging +db.name = dbstaging +debug = false + +[debug] +hostname = debug +debug = true +values.changed = yes +db.name = dbdebug +special.no = no +special.null = null +special.false = false + +[other_staging] +only_in = otherStaging +db.pass = anotherpwd diff --git a/test/Writer/files/allsections.json b/test/Writer/_files/allsections.json similarity index 100% rename from test/Writer/files/allsections.json rename to test/Writer/_files/allsections.json diff --git a/test/Writer/files/allsections.xml b/test/Writer/_files/allsections.xml similarity index 100% rename from test/Writer/files/allsections.xml rename to test/Writer/_files/allsections.xml diff --git a/test/Writer/files/allsections.yaml b/test/Writer/_files/allsections.yaml similarity index 100% rename from test/Writer/files/allsections.yaml rename to test/Writer/_files/allsections.yaml diff --git a/test/Writer/files/PhpReader.php b/test/Writer/files/PhpReader.php deleted file mode 100644 index d7e91fe..0000000 --- a/test/Writer/files/PhpReader.php +++ /dev/null @@ -1,9 +0,0 @@ -