Webiny\Component\Config\ConfigObject::get PHP Method

get() public method

You can also access deeper values by using dotted key notation: level1.level2.level3.key
public get ( string $name, mixed $default = null, boolean $toArray = false ) : mixed | ConfigObject
$name string
$default mixed
$toArray boolean
return mixed | ConfigObject Config value or default value
    public function get($name, $default = null, $toArray = false)
    {
        if ($this->str($name)->contains('.')) {
            $keys = $this->str($name)->trim('.')->explode('.', 2);
            if (!$this->data->keyExists($keys[0])) {
                return $default;
            }
            return $this->data->key($keys[0])->get($keys[1], $default, $toArray);
        }
        if ($this->data->keyExists($name)) {
            $result = $this->data->key($name);
            if ($toArray && $result instanceof $this) {
                $result = $result->toArray();
            }
            return $result;
        }
        return $default;
    }

Usage Example

示例#1
0
 /**
  * Builds a Route instance based on the given route config.
  *
  * @param ConfigObject $routeConfig A config object containing route parameters.
  *
  * @return Route
  */
 public function processRoute(ConfigObject $routeConfig)
 {
     // base route
     $callback = $this->isString($routeConfig->Callback) ? $routeConfig->Callback : $routeConfig->Callback->toArray();
     $route = new Route($routeConfig->Path, $callback);
     // route options
     if (($options = $routeConfig->get('Options', false)) !== false) {
         $route->setOptions($options->toArray());
     }
     // host
     if (($host = $routeConfig->get('Host', false)) !== false) {
         $route->setHost($host);
     }
     // schemes
     if (($schemes = $routeConfig->get('Schemes', false)) !== false) {
         $route->setSchemes($schemes);
     }
     // methods
     if (($methods = $routeConfig->get('Methods', false)) !== false) {
         $route->setMethods($methods->toArray());
     }
     // tags
     if (($tags = $routeConfig->get('Tags', false)) !== false) {
         $route->setTags($tags->toArray());
     }
     return $route;
 }
All Usage Examples Of Webiny\Component\Config\ConfigObject::get