当前位置: 首页>>代码示例>>PHP>>正文


PHP Config::__construct方法代码示例

本文整理汇总了PHP中Zend\Config\Config::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Config::__construct方法的具体用法?PHP Config::__construct怎么用?PHP Config::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Config\Config的用法示例。


在下文中一共展示了Config::__construct方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * @throws InvalidArgumentException from sfYaml::load
  * @throws Zend_Config_Exception
  * @param string $filename
  * @param boolean $allowModifications
  */
 public function __construct($filename, $allowModifications = false)
 {
     $this->filename = $filename;
     $this->checkIfFilenameIsFile();
     $content = SymfonyYaml::load($this->filename);
     if (is_null($content)) {
         $content = array();
     }
     parent::__construct($content, $allowModifications);
 }
开发者ID:NilsLangner,项目名称:LiveTest,代码行数:16,代码来源:Yaml.php

示例2: __construct

 /**
  * @param array $array
  * @param string $modelName
  */
 public function __construct(array $array, $modelName = 'HealthCheck\\Model\\Service', $useRealPath = false)
 {
     $this->modelName = (string) $modelName;
     if (!class_exists($modelName)) {
         throw new Exception\BadModelCallException(sprintf('Model class "%s"', $modelName));
     }
     $data = array();
     foreach ($array as $serviceFilename) {
         /**
          * TODO Caching
          */
         $model = new $this->modelName($serviceFilename, $useRealPath);
         if (is_object($model) && method_exists($model, 'getName')) {
             $data[$model->getName()] = $model;
         } else {
             throw new Exception\BadModelCallException('Model class requires method "getName"');
         }
     }
     parent::__construct($data);
     if ($this->count() === 0) {
         throw new Exception\UnexpectedValueException(sprintf('Could not create any instance of "%s"', $this->modelName));
     }
 }
开发者ID:sullenboom,项目名称:sla-healthcheck,代码行数:27,代码来源:ModelList.php

示例3: __construct

 /**
  * Constructor
  *
  * @param bool $allowModifications readonly flag
  */
 public function __construct($allowModifications = false)
 {
     $home = self::getHomeDir();
     $cache = self::getCacheDir($home);
     parent::__construct(['home' => $home, 'cache-dir' => $cache], $allowModifications);
 }
开发者ID:mvanduijker,项目名称:joomla-cli,代码行数:11,代码来源:Config.php

示例4: __construct

    /**
     * Loads the section $section from the config file encoded as JSON
     *
     * Sections are defined as properties of the main object
     *
     * In order to extend another section, a section defines the "_extends"
     * property having a value of the section name from which the extending
     * section inherits values.
     *
     * Note that the keys in $section will override any keys of the same
     * name in the sections that have been included via "_extends".
     *
     * @param  string  $json     JSON file or string to process
     * @param  mixed   $section Section to process
     * @param  boolean $options Whether modifiacations are allowed at runtime
     * @throws Exception\InvalidArgumentException When JSON text is not set or cannot be loaded
     * @throws Exception\RuntimeException When section $sectionName cannot be found in $json
     */
    public function __construct($json, $section = null, $options = false)
    {
        if (empty($json)) {
            throw new Exception\InvalidArgumentException('Filename is not set');
        }

        $allowModifications = false;
        if (is_bool($options)) {
            $allowModifications = $options;
        } elseif (is_array($options)) {
            foreach ($options as $key => $value) {
                switch (strtolower($key)) {
                    case 'allow_modifications':
                    case 'allowmodifications':
                        $allowModifications = (bool) $value;
                        break;
                    case 'skip_extends':
                    case 'skipextends':
                        $this->_skipExtends = (bool) $value;
                        break;
                    case 'ignore_constants':
                    case 'ignoreconstants':
                        $this->_ignoreConstants = (bool) $value;
                        break;
                    default:
                        break;
                }
            }
        }

        if ($json[0] != '{') {
            // read json file
            $this->_setErrorHandler();
            $content = file_get_contents($json, true);
            $errorMessages = $this->_restoreErrorHandler();
            if ($content === false) {
                $e = null;
                foreach ($errorMessages as $errMsg) {
                    $e = new Exception\RuntimeException($errMsg, 0, $e);
                }
                $e = new Exception\RuntimeException("Can't read file '{$json}'", 0, $e);
                throw $e;
            }
            $json = $content;
        }

        // Replace constants
        if (!$this->_ignoreConstants) {
            $json = $this->_replaceConstants($json);
        }

        // Parse/decode
        $config = JsonUtil::decode($json);

        if (null === $config) {
            // decode failed
            throw new Exception\RuntimeException("Error parsing JSON data");
        }

        // Flatten object structure into array
        $config = $this->flattenObjects($config);

        if ($section === null) {
            $dataArray = array();
            foreach ($config as $sectionName => $sectionData) {
                $dataArray[$sectionName] = $this->_processExtends($config, $sectionName);
            }

            parent::__construct($dataArray, $allowModifications);
        } elseif (is_array($section)) {
            $dataArray = array();
            foreach ($section as $sectionName) {
                if (!isset($config[$sectionName])) {
                    throw new Exception\RuntimeException(sprintf('Section "%s" cannot be found', $sectionName));
                }

                $dataArray = array_merge($this->_processExtends($config, $sectionName), $dataArray);
            }

            parent::__construct($dataArray, $allowModifications);
        } else {
            if (!isset($config[$section])) {
//.........这里部分代码省略.........
开发者ID:ruflin,项目名称:zf2,代码行数:101,代码来源:Json.php

示例5: __construct

 public function __construct(array $data)
 {
     parent::__construct($data);
 }
开发者ID:godentarek,项目名称:whathood,代码行数:4,代码来源:Config.php

示例6: __construct

 public function __construct($params = [])
 {
     parent::__construct($params);
 }
开发者ID:arbi,项目名称:MyCode,代码行数:4,代码来源:Settings.php


注:本文中的Zend\Config\Config::__construct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。