From 6d5eed667b20302c5377f26a2655bebe07c5f9a2 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Wed, 2 Sep 2020 21:48:57 +0100 Subject: [PATCH] #911 - Remove Config Component files --- Library/Phalcon/Config/Adapter/Xml.php | 105 ----------- Library/Phalcon/Config/Loader.php | 78 -------- tests/unit/Config/Adapter/XmlTest.php | 73 -------- tests/unit/Config/LoaderTest.php | 239 ------------------------- 4 files changed, 495 deletions(-) delete mode 100644 Library/Phalcon/Config/Adapter/Xml.php delete mode 100644 Library/Phalcon/Config/Loader.php delete mode 100644 tests/unit/Config/Adapter/XmlTest.php delete mode 100644 tests/unit/Config/LoaderTest.php diff --git a/Library/Phalcon/Config/Adapter/Xml.php b/Library/Phalcon/Config/Adapter/Xml.php deleted file mode 100644 index 43425ee5c..000000000 --- a/Library/Phalcon/Config/Adapter/Xml.php +++ /dev/null @@ -1,105 +0,0 @@ - | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Config\Adapter; - -use Phalcon\Config; -use Phalcon\Config\Exception; - -/** - * Phalcon\Config\Adapter\Xml - * - * Reads xml files and converts them to Phalcon\Config objects. - * - * Given the next configuration file: - * - * - * - * - * - * /phalcon/ - * - * - * memory - * - * - * - * here - * - * - * - * - * - * You can read it as follows: - * - * - * use Phalcon\Config\Adapter\Xml; - * $config = new Xml("path/config.xml"); - * echo $config->phalcon->baseuri; - * echo $config->nested->config->parameter; - * - * - * @package Phalcon\Config\Adapter - */ -class Xml extends Config -{ - /** - * Phalcon\Config\Adapter\Xml constructor - * - * @param string $filePath - * @throws Exception - */ - public function __construct($filePath) - { - if (!extension_loaded('SimpleXML')) { - throw new Exception("SimpleXML extension not loaded"); - } - - libxml_use_internal_errors(true); - - $data = simplexml_load_file( - $filePath, - 'SimpleXMLElement', - LIBXML_NOCDATA - ); - - foreach (libxml_get_errors() as $error) { - /** @var \LibXMLError $error */ - switch ($error->code) { - case LIBXML_ERR_WARNING: - trigger_error($error->message, E_USER_WARNING); - break; - - default: - throw new Exception($error->message); - } - } - - libxml_use_internal_errors(false); - - parent::__construct( - json_decode( - json_encode( - (array) $data - ), - true - ) - ); - } -} diff --git a/Library/Phalcon/Config/Loader.php b/Library/Phalcon/Config/Loader.php deleted file mode 100644 index 1d69e5035..000000000 --- a/Library/Phalcon/Config/Loader.php +++ /dev/null @@ -1,78 +0,0 @@ - | - +------------------------------------------------------------------------+ -*/ - -namespace Phalcon\Config; - -use Phalcon\Config\Adapter\Ini; -use Phalcon\Config\Adapter\Json; -use Phalcon\Config\Adapter\Php; -use Phalcon\Config\Adapter\Yaml; -use Phalcon\Config; - -/** - * Phalcon config loader - * - * @package Phalcon\Config - */ -class Loader -{ - /** - * Load config from file extension dynamical - * - * @param string $filePath - * - * @return Config - * @throws Exception - */ - public static function load($filePath) - { - if (!is_file($filePath)) { - throw new Exception('Config file not found'); - } - - $extension = strtolower( - pathinfo( - $filePath, - PATHINFO_EXTENSION - ) - ); - - switch ($extension) { - case 'ini': - return new Ini($filePath); - - case 'json': - return new Json($filePath); - - case 'php': - case 'php5': - case 'inc': - return new Php($filePath); - - case 'yml': - case 'yaml': - return new Yaml($filePath); - - default: - throw new Exception( - 'Config adapter for .' . $extension . ' files is not support' - ); - } - } -} diff --git a/tests/unit/Config/Adapter/XmlTest.php b/tests/unit/Config/Adapter/XmlTest.php deleted file mode 100644 index c3786af07..000000000 --- a/tests/unit/Config/Adapter/XmlTest.php +++ /dev/null @@ -1,73 +0,0 @@ - - * @package Phalcon\Test\Config\Adapter - * @group config - * - * The contents of this file are subject to the New BSD License that is - * bundled with this package in the file docs/LICENSE.txt - * - * 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@phalconphp.com - * so that we can send you a copy immediately. - */ -class XmlTest extends Test -{ - use Specify; - - /** - * executed before each test - */ - protected function _before() - { - if (!extension_loaded('SimpleXML')) { - $this->markTestSkipped("SimpleXML extension not loaded"); - } - } - - /** - * Tests toArray method - * - * @author Serghei Iakovlev - * @since 2016-03-04 - */ - public function testConfigToArray() - { - $this->specify( - "Transform Config to the array does not returns the expected result", - function () { - $expected = [ - 'phalcon' => [ - 'baseuri' => '/phalcon/' - ], - 'models' => [ - 'metadata' => 'memory', - ], - 'nested' => [ - 'config' => [ - 'parameter' => 'here', - ], - ], - ]; - - $config = new Xml( - PATH_DATA . 'config/config.xml' - ); - - expect($config->toArray())->equals($expected); - } - ); - } -} diff --git a/tests/unit/Config/LoaderTest.php b/tests/unit/Config/LoaderTest.php deleted file mode 100644 index 24618a5c2..000000000 --- a/tests/unit/Config/LoaderTest.php +++ /dev/null @@ -1,239 +0,0 @@ - - * @package Phalcon\Test\Config - * @group config - * - * The contents of this file are subject to the New BSD License that is - * bundled with this package in the file docs/LICENSE.txt - * - * 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@phalconphp.com - * so that we can send you a copy immediately. - */ -class LoaderTest extends Test -{ - public function testLoadPhpFileConfig() - { - $file = INCUBATOR_FIXTURES . 'Config/config.php'; - - $config = ConfigLoader::load($file); - - $this->assertTrue( - is_object($config) - ); - - $this->assertInstanceOf( - 'Phalcon\Config\Adapter\Php', - $config - ); - - $this->assertInstanceOf( - 'Phalcon\Config', - $config - ); - - $this->assertEquals( - 'bar', - $config->phalcon->foo - ); - } - - public function testLoadPhp5FileConfig() - { - $file = INCUBATOR_FIXTURES . 'Config/config.php5'; - - $config = ConfigLoader::load($file); - - $this->assertTrue( - is_object($config) - ); - - $this->assertInstanceOf( - \Phalcon\Config\Adapter\Php::class, - $config - ); - - $this->assertInstanceOf( - \Phalcon\Config::class, - $config - ); - - $this->assertEquals( - 'bar', - $config->phalcon->foo - ); - } - - public function testLoadIncFileConfig() - { - $file = INCUBATOR_FIXTURES . 'Config/config.inc'; - - $config = ConfigLoader::load($file); - - $this->assertTrue( - is_object($config) - ); - - $this->assertInstanceOf( - \Phalcon\Config\Adapter\Php::class, - $config - ); - - $this->assertInstanceOf( - \Phalcon\Config::class, - $config - ); - - $this->assertEquals( - 'bar', - $config->phalcon->foo - ); - } - - public function testLoadIniFileConfig() - { - $file = INCUBATOR_FIXTURES . 'Config/config.ini'; - - $config = ConfigLoader::load($file); - - $this->assertTrue( - is_object($config) - ); - - $this->assertInstanceOf( - \Phalcon\Config\Adapter\Ini::class, - $config - ); - - $this->assertInstanceOf( - \Phalcon\Config::class, - $config - ); - - $this->assertEquals( - 'bar', - $config->phalcon->foo - ); - } - - /** - * @requires extension json - */ - public function testLoadJsonFileConfig() - { - $file = INCUBATOR_FIXTURES . 'Config/config.json'; - - $config = ConfigLoader::load($file); - - $this->assertTrue( - is_object($config) - ); - - $this->assertInstanceOf( - \Phalcon\Config\Adapter\Json::class, - $config - ); - - $this->assertInstanceOf( - \Phalcon\Config::class, - $config - ); - - $this->assertEquals( - 'bar', - $config->phalcon->foo - ); - } - - /** - * @requires extension yaml - */ - public function testLoadYamlFileConfig() - { - $file = INCUBATOR_FIXTURES . 'Config/config.yaml'; - - $config = ConfigLoader::load($file); - - $this->assertTrue( - is_object($config) - ); - - $this->assertInstanceOf( - \Phalcon\Config\Adapter\Yaml::class, - $config - ); - - $this->assertInstanceOf( - \Phalcon\Config::class, - $config - ); - - $this->assertEquals( - 'bar', - $config->phalcon->foo - ); - } - - /** - * @requires extension yaml - */ - public function testLoadYmlFileConfig() - { - $file = INCUBATOR_FIXTURES . 'Config/config.yml'; - - $config = ConfigLoader::load($file); - - $this->assertTrue( - is_object($config) - ); - - $this->assertInstanceOf( - \Phalcon\Config\Adapter\Yaml::class, - $config - ); - - $this->assertInstanceOf( - \Phalcon\Config::class, - $config - ); - - $this->assertEquals( - 'bar', - $config->phalcon->foo - ); - } - - /** - * @expectedException \Phalcon\Config\Exception - * @expectedExceptionMessage Config file not found - */ - public function testLoadWrongFilePath() - { - $file = INCUBATOR_FIXTURES . 'Config/config.jason'; - - ConfigLoader::load($file); - } - - /** - * @expectedException \Phalcon\Config\Exception - * @expectedExceptionMessage Config adapter for .txt files is not support - */ - public function testLoadUnsupportedConfigFile() - { - $file = INCUBATOR_FIXTURES . 'Config/config.txt'; - - ConfigLoader::load($file); - } -}