Webiny\Component\Config\Drivers\AbstractDriver::__construct PHP Method

__construct() public method

Create config driver instance
public __construct ( null $resource = null )
$resource null Resource for driver
    public function __construct($resource = null)
    {
        $this->resource = $resource;
        if (self::isNull($this->resource) || !$this->resource) {
            throw new ConfigException('Config resource can not be NULL or FALSE! Please provide a valid file path, config string or PHP array.');
        }
        if ($this->isStdObject($resource)) {
            $this->resource = $resource->val();
        }
        if ($this->isArray($this->resource)) {
            return;
        }
        /**
         * Perform string checks
         */
        if ($this->str($this->resource)->trim()->length() == 0) {
            throw new ConfigException('Config resource string can not be empty! Please provide a valid file path, config string or PHP array.');
        }
        /**
         * If it's a file - get its contents
         */
        if ($this->isFilepath($this->resource)) {
            if (!$this->isFile($this->resource)) {
                throw new ConfigException('Invalid config file path given: ' . $this->resource);
            }
            $path = dirname($this->resource);
            $this->resource = file_get_contents($this->resource);
            $this->resource = str_replace('__DIR__', $path, $this->resource);
        }
    }

Usage Example

示例#1
0
 public function __construct($resource = null)
 {
     parent::__construct($resource);
     $this->yaml = Yaml::getInstance();
 }