getSuggestion() public static method

Finds the best suggestion.
public static getSuggestion ( array $items, $value ) : string | null
$items array
return string | null
Beispiel #1
0
 /**
  * Access to undeclared property.
  * @throws LogicException
  */
 public function __set($name, $value)
 {
     $rc = new \ReflectionClass($this);
     $items = array_diff($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC));
     $hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean \${$t}?" : '.';
     throw new LogicException("Attempt to write to undeclared property {$rc->getName()}::\${$name}{$hint}");
 }
 /**
  * Calls block.
  * @return void
  */
 public static function callBlock(\stdClass $context, $name, array $params)
 {
     if (empty($context->blocks[$name])) {
         $hint = isset($context->blocks) && ($t = Latte\Helpers::getSuggestion(array_keys($context->blocks), $name)) ? ", did you mean '{$t}'?" : '.';
         throw new RuntimeException("Cannot include undefined block '{$name}'{$hint}");
     }
     $block = reset($context->blocks[$name]);
     $block($context, $params);
 }
Beispiel #3
0
 /**
  * Renders block.
  * @param  string
  * @param  array
  * @param  string|\Closure content-type name or modifier closure
  * @return void
  * @internal
  */
 protected function renderBlock($name, array $params, $mod = NULL)
 {
     if (empty($this->blockQueue[$name])) {
         $hint = isset($this->blockQueue) && ($t = Latte\Helpers::getSuggestion(array_keys($this->blockQueue), $name)) ? ", did you mean '{$t}'?" : '.';
         throw new \RuntimeException("Cannot include undefined block '{$name}'{$hint}");
     }
     $block = reset($this->blockQueue[$name]);
     if ($mod && $mod !== ($blockType = $this->blockTypes[$name])) {
         if ($filter = is_string($mod) ? Filters::getConvertor($blockType, $mod) : $mod) {
             echo $filter($this->capture(function () use($block, $params) {
                 $block($params);
             }), $blockType);
             return;
         }
         trigger_error("Including block {$name} with content type " . strtoupper($blockType) . ' into incompatible type ' . strtoupper($mod) . '.', E_USER_WARNING);
     }
     $block($params);
 }
Beispiel #4
0
 /**
  * Calls filter with FilterInfo.
  * @return mixed
  */
 public function filterContent($name, FilterInfo $info, $arg)
 {
     $lname = strtolower($name);
     $args = func_get_args();
     array_shift($args);
     if (!isset($this->_static[$lname])) {
         $hint = ($t = Helpers::getSuggestion(array_keys($this->_static), $name)) ? ", did you mean '{$t}'?" : '.';
         throw new \LogicException("Filter |{$name} is not defined{$hint}");
     }
     list($callback, $aware) = $this->prepareFilter($lname);
     if ($aware) {
         // FilterInfo aware filter
         return call_user_func_array($callback, $args);
     } else {
         // classic filter
         array_shift($args);
         if ($info->contentType !== Engine::CONTENT_TEXT) {
             trigger_error("Filter |{$name} is called with incompatible content type " . strtoupper($info->contentType) . ($info->contentType === Engine::CONTENT_HTML ? ', try to prepend |stripHtml.' : '.'), E_USER_WARNING);
         }
         $res = call_user_func_array($this->{$name}, $args);
         if ($res instanceof IHtmlString) {
             trigger_error("Filter |{$name} should be changed to content-aware filter.");
             $info->contentType = Engine::CONTENT_HTML;
             $res = $res->__toString();
         }
         return $res;
     }
 }