Namespaces

  • Latte
    • Loaders
    • Macros
    • Runtime
  • Nette
    • Application
      • Responses
      • Routers
      • UI
    • Bridges
      • ApplicationDI
      • ApplicationLatte
      • ApplicationTracy
      • CacheDI
      • CacheLatte
      • DatabaseDI
      • DatabaseTracy
      • DITracy
      • FormsDI
      • FormsLatte
      • Framework
      • HttpDI
      • HttpTracy
      • MailDI
      • ReflectionDI
      • SecurityDI
      • SecurityTracy
    • Caching
      • Storages
    • ComponentModel
    • Database
      • Conventions
      • Drivers
      • Table
    • DI
      • Config
        • Adapters
      • Extensions
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Loaders
    • Localization
    • Mail
    • Neon
    • PhpGenerator
      • Traits
    • Reflection
    • Security
    • Tokenizer
    • Utils
  • Tracy
    • Bridges
      • Nette
  • none

Classes

  • Compiler
  • Engine
  • Helpers
  • HtmlNode
  • MacroNode
  • MacroTokens
  • Parser
  • PhpHelpers
  • PhpWriter
  • Token
  • TokenIterator
  • Tokenizer

Interfaces

  • ILoader
  • IMacro

Traits

  • Strict

Exceptions

  • CompileException
  • RegexpException
  • RuntimeException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Latte (https://latte.nette.org)
 5:  * Copyright (c) 2008 David Grudl (https://davidgrudl.com)
 6:  */
 7: 
 8: namespace Latte;
 9: 
10: 
11: /**
12:  * Latte helpers.
13:  * @internal
14:  */
15: class Helpers
16: {
17:     /** @var array  empty (void) HTML elements */
18:     public static $emptyElements = [
19:         'img' => 1, 'hr' => 1, 'br' => 1, 'input' => 1, 'meta' => 1, 'area' => 1, 'embed' => 1, 'keygen' => 1, 'source' => 1, 'base' => 1,
20:         'col' => 1, 'link' => 1, 'param' => 1, 'basefont' => 1, 'frame' => 1, 'isindex' => 1, 'wbr' => 1, 'command' => 1, 'track' => 1,
21:     ];
22: 
23: 
24:     /**
25:      * Checks callback.
26:      * @return callable
27:      */
28:     public static function checkCallback($callable)
29:     {
30:         if (!is_callable($callable, false, $text)) {
31:             throw new \InvalidArgumentException("Callback '$text' is not callable.");
32:         }
33:         return $callable;
34:     }
35: 
36: 
37:     /**
38:      * Finds the best suggestion.
39:      * @return string|null
40:      */
41:     public static function getSuggestion(array $items, $value)
42:     {
43:         $best = null;
44:         $min = (strlen($value) / 4 + 1) * 10 + .1;
45:         foreach (array_unique($items, SORT_REGULAR) as $item) {
46:             $item = is_object($item) ? $item->getName() : $item;
47:             if (($len = levenshtein($item, $value, 10, 11, 10)) > 0 && $len < $min) {
48:                 $min = $len;
49:                 $best = $item;
50:             }
51:         }
52:         return $best;
53:     }
54: 
55: 
56:     /**
57:      * @return bool
58:      */
59:     public static function removeFilter(&$modifier, $filter)
60:     {
61:         $modifier = preg_replace('#\|(' . $filter . ')\s?(?=\||\z)#i', '', $modifier, -1, $found);
62:         return (bool) $found;
63:     }
64: 
65: 
66:     /**
67:      * Starts the $haystack string with the prefix $needle?
68:      * @return bool
69:      */
70:     public static function startsWith($haystack, $needle)
71:     {
72:         return strncmp($haystack, $needle, strlen($needle)) === 0;
73:     }
74: }
75: 
Nette 2.4-20180918 API API documentation generated by ApiGen 2.8.0