Exemple #1
0
 /**
  * Gets a dot-notated key from an array, with a default value if it does
  * not exist.
  *
  * @param array  $array   The search array
  * @param string $key     The dot-notated key or array of keys
  * @param string $default The default value
  *
  * @return mixed
  *
  * @since              0.1.0
  * @codeCoverageIgnore
  */
 public static function get(array $array, $key, $default = null)
 {
     if (!is_array($array) && !$array instanceof ArrayAccess) {
         throw new InvalidArgumentException('First parameter must be an array or ArrayAccess object.');
     }
     if (is_null($key)) {
         return $array;
     }
     if (is_array($key)) {
         $return = [];
         foreach ($key as $k) {
             $return[$k] = self::get($array, $k, $default);
         }
         return $return;
     }
     foreach (explode('.', $key) as $key_part) {
         if (($array instanceof ArrayAccess && isset($array[$key_part])) === false) {
             if (!is_array($array) || !array_key_exists($key_part, $array)) {
                 return Utils::checkValue($default);
             }
         }
         $array = $array[$key_part];
     }
     return $array;
 }
Exemple #2
0
 /**
  * Loads in the given file and parses it.
  *
  * @param string $file File to load
  *
  * @return string|array|stdClass The parsed file data
  *
  * @since              0.2.4
  * @codeCoverageIgnore
  */
 protected function loadFile($file = null)
 {
     $this->file = $file;
     $contents = $this->parseVars(Utils::getContent($file));
     if (extension_loaded('yaml')) {
         return yaml_parse($contents);
     }
     return YamlParser::parse($contents);
 }
Exemple #3
0
 /**
  * Loads in the given file and parses it.
  *
  * @param string|bool|null $file File to load
  *
  * @return array The parsed file data
  *
  * @since              0.2.4
  * @codeCoverageIgnore
  */
 protected function loadFile($file = null)
 {
     $this->file = is_file($file) ? $file : false;
     $contents = $this->parseVars(Utils::getContent($this->file));
     if ($this->file && !is_null($file)) {
         $this->parsedFile = $this->parseProperties($contents);
     }
 }
Exemple #4
0
 /**
  * Loads in the given file and parses it.
  *
  * @param string $file File to load
  *
  * @return array The parsed file data
  *
  * @since              0.2.4
  * @codeCoverageIgnore
  */
 protected function loadFile($file = null)
 {
     $this->file = $file;
     $contents = $this->parseVars(Utils::getContent($file));
     return NeonParser::decode($contents);
 }
Exemple #5
0
 /**
  * Loads in the given file and parses it.
  *
  * @param string $file File to load
  *
  * @return array The parsed file data
  *
  * @since              0.2.4
  * @codeCoverageIgnore
  */
 protected function loadFile($file = null)
 {
     $this->file = $file;
     $contents = $this->parseVars(Utils::getContent($file));
     return json_decode($contents, true);
 }
Exemple #6
0
 /**
  * Loads in the given file and parses it.
  *
  * @param string $file File to load
  *
  * @return array|SimpleXMLElement The parsed file data
  *
  * @since              0.2.4
  * @codeCoverageIgnore
  */
 protected function loadFile($file = null)
 {
     $this->file = $file;
     $contents = $this->parseVars(Utils::getContent($file));
     return simplexml_load_string($contents, 'SimpleXMLElement', LIBXML_NOWARNING | LIBXML_NOERROR);
 }
Exemple #7
0
 /**
  * Loads in the given file and parses it.
  *
  * @param string $file File to load
  *
  * @return array The parsed file data
  *
  * @since              0.2.4
  * @codeCoverageIgnore
  */
 protected function loadFile($file = null)
 {
     $this->file = $file;
     $contents = $this->parseVars(Utils::getContent($file));
     return TomlLib::Parse($contents);
 }
Exemple #8
0
 /**
  * Loads in the given file and parses it.
  *
  * @param string $file File to load
  *
  * @return array The parsed file data
  *
  * @since              0.2.4
  * @codeCoverageIgnore
  */
 protected function loadFile($file = null)
 {
     $this->file = $file;
     $contents = $this->parseVars(Utils::getContent($file));
     return @parse_ini_string($contents, true);
 }