-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #844 from sjinks/config-adapter-json
[NFR] Phalcon\Config\Adapter\Json
- Loading branch information
Showing
12 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
|
||
/* | ||
+------------------------------------------------------------------------+ | ||
| Phalcon Framework | | ||
+------------------------------------------------------------------------+ | ||
| Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | | ||
+------------------------------------------------------------------------+ | ||
| This source file is 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 we can send you a copy immediately. | | ||
+------------------------------------------------------------------------+ | ||
| Authors: Andres Gutierrez <andres@phalconphp.com> | | ||
| Eduar Carvajal <eduar@phalconphp.com> | | ||
| Vladimir Kolesnikov <vladimir@extrememember.com> | | ||
+------------------------------------------------------------------------+ | ||
*/ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include "php.h" | ||
#include "php_phalcon.h" | ||
#include "phalcon.h" | ||
|
||
#include "kernel/main.h" | ||
#include "kernel/memory.h" | ||
#include "kernel/file.h" | ||
#include "kernel/string.h" | ||
|
||
#include "config/adapter/json.h" | ||
|
||
/** | ||
* Phalcon\Config\Adapter\Json | ||
* | ||
* Reads JSON files and converts them to Phalcon\Config objects. | ||
* | ||
* Given the following configuration file: | ||
* | ||
*<code> | ||
*{"phalcon":{"baseuri":"\/phalcon\/"},"models":{"metadata":"memory"}} | ||
*</code> | ||
* | ||
* You can read it as follows: | ||
* | ||
*<code> | ||
* $config = new Phalcon\Config\Adapter\Json("path/config.json"); | ||
* echo $config->phalcon->baseuri; | ||
* echo $config->models->metadata; | ||
*</code> | ||
* | ||
*/ | ||
|
||
|
||
/** | ||
* Phalcon\Config\Adapter\Json initializer | ||
*/ | ||
PHALCON_INIT_CLASS(Phalcon_Config_Adapter_Json){ | ||
|
||
PHALCON_REGISTER_CLASS_EX(Phalcon\\Config\\Adapter, Json, config_adapter_json, "phalcon\\config", phalcon_config_adapter_json_method_entry, 0); | ||
|
||
return SUCCESS; | ||
} | ||
|
||
/** | ||
* Phalcon\Config\Adapter\Json constructor | ||
* | ||
* @param string $filePath | ||
*/ | ||
PHP_METHOD(Phalcon_Config_Adapter_Json, __construct){ | ||
|
||
zval *file_path, *contents, *array; | ||
|
||
phalcon_fetch_params(0, 1, 0, &file_path); | ||
|
||
ALLOC_INIT_ZVAL(contents); | ||
ALLOC_INIT_ZVAL(array); | ||
phalcon_file_get_contents(contents, file_path TSRMLS_CC); | ||
|
||
if (Z_TYPE_P(contents) == IS_STRING) { | ||
phalcon_json_decode(array, contents, 1 TSRMLS_CC); | ||
} | ||
|
||
zval_ptr_dtor(&contents); | ||
|
||
if (Z_TYPE_P(array) != IS_ARRAY) { | ||
zval_dtor(array); | ||
array_init_size(array, 0); | ||
} | ||
|
||
phalcon_config_construct_internal(getThis(), array TSRMLS_CC); | ||
zval_ptr_dtor(&array); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
/* | ||
+------------------------------------------------------------------------+ | ||
| Phalcon Framework | | ||
+------------------------------------------------------------------------+ | ||
| Copyright (c) 2011-2013 Phalcon Team (http://www.phalconphp.com) | | ||
+------------------------------------------------------------------------+ | ||
| This source file is 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 we can send you a copy immediately. | | ||
+------------------------------------------------------------------------+ | ||
| Authors: Andres Gutierrez <andres@phalconphp.com> | | ||
| Eduar Carvajal <eduar@phalconphp.com> | | ||
| Vladimir Kolesnikov <vladimir@extrememember.com> | | ||
+------------------------------------------------------------------------+ | ||
*/ | ||
|
||
#ifndef PHALCON_CONFIG_ADAPTER_JSON_H | ||
#define PHALCON_CONFIG_ADAPTER_JSON_H | ||
|
||
extern zend_class_entry *phalcon_config_adapter_json_ce; | ||
|
||
PHALCON_INIT_CLASS(Phalcon_Config_Adapter_Json); | ||
|
||
PHP_METHOD(Phalcon_Config_Adapter_Json, __construct); | ||
|
||
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_config_adapter_json___construct, 0, 0, 1) | ||
ZEND_ARG_INFO(0, filePath) | ||
ZEND_END_ARG_INFO() | ||
|
||
PHALCON_INIT_FUNCS(phalcon_config_adapter_json_method_entry){ | ||
PHP_ME(Phalcon_Config_Adapter_Json, __construct, arginfo_phalcon_config_adapter_json___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) | ||
PHP_FE_END | ||
}; | ||
|
||
#endif /* PHALCON_CONFIG_ADAPTER_JSON_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"phalcon":{"baseuri":"\/phalcon\/"},"models":{"metadata":"memory"},"database":{"adapter":"mysql","host":"localhost","username":"user","password":"passwd","name":"demo"},"test":{"parent":{"property2":"yeah"}}} |