Example #1
0
 /**
  * Allow dot syntax access to any data
  *
  * @param  mixed        $data
  * @param  string|array $where
  * @param  bool         $strict
  * @return mixed
  */
 public function getIn($data, $where, $strict = false)
 {
     if (is_object($data)) {
         $clone = clone $data;
         $data = \Foil\arraize($clone, $this->autoescape);
     } elseif (!is_array($data)) {
         return $this->autoescape ? $this->escaper->escape($data) : $data;
     }
     $where = is_string($where) ? explode('.', $where) : (array) $where;
     $get = igorw\get_in($data, $where);
     if (!$strict || !$this->strict || !is_null($get)) {
         return $get;
     }
     $name = implode('.', $where);
     if ($this->strict === 'notice') {
         return trigger_error("{$name} is not defined.");
     }
     throw new RuntimeException("{$name} is not defined.");
 }
Example #2
0
 /**
  * @param  array|\Traversable $var
  * @param  string             $format
  * @return string
  */
 public function walk($var, $format = '%s')
 {
     $out = '';
     $args = $this->args(func_get_args(), 2);
     $what = is_string($var) ? $this->command->run('raw', $var) : $var;
     foreach (\Foil\arraize($what, $this->options['autoescape'], [], true) as $value) {
         $replacement = is_array($value) ? $value : [$value];
         $out .= vsprintf($format, array_merge($replacement, $args));
     }
     return $out;
 }