Asf_Config


Introduction

配置内容管理类

支持配置文件内容常驻内存 (详细说明)

在开启命名空间情况下(asf.use_namespace=1)类名为 Asf\Config

Class synopsis

<?php
final class Asf_Config implements Countable, Iterator, ArrayAccess
{
    public static function get([string $name = '' [, mixed $default = '']])
}

Examples

Example #1

<?php
$configs = array(
    'asf' => array(
        'root_path'  => realpath(dirname(__FILE__)),
    )
);

class IndexService
{
    public function indexAction()
    {
        echo '------long method: get config value-------', PHP_EOL;
        var_dump(Asf_Application::getInstance()->getConfig()->toArray());
        var_dump(Asf_Application::getInstance()->getConfig()->asf->root_path);
        var_dump(Asf_Application::getInstance()->getConfig()->get('asf')->get('root_path'));

        echo '------short method: get config value-------', PHP_EOL;
        var_dump(Asf_Config::get()->toArray());
        var_dump(Asf_Config::get('asf')->root_path);
        var_dump(Asf_Config::get('asf')->get('root_path'));
        var_dump(Asf_Config::get('asf1', "default_value"));
    }
}

$handle = new Asf_Application($configs);
$handle->run();