/**
  * Filter: removes unnecessary whitespace and shortens value to control's max length.
  *
  * @return string
  */
 public function sanitize($value)
 {
     if ($this->control->maxlength && Nette\Utils\Strings::length($value) > $this->control->maxlength) {
         $value = Nette\Utils\Strings::substring($value, 0, $this->control->maxlength);
     }
     return Nette\Utils\Strings::trim(strtr($value, "\r\n", '  '));
 }
Esempio n. 2
0
 public static function formatRecordString($record, $formatString)
 {
     return Strings::replace($formatString, '#%[^%]*%#u', function ($m) use($record) {
         $m = Strings::trim($m[0], '%');
         return $m != '' ? $record[$m] : "%";
     });
 }
Esempio n. 3
0
 private function parse($link)
 {
     $data = $this->toUtf8(file_get_contents(str_replace("&", "&", $this->url . $link)));
     if (preg_match_all("/<div class=\"wrn2\">.*<\\/div>/", $data, $match) !== 0) {
         return FALSE;
     }
     preg_match_all("/<td align=\"left\" valign=\"top\" width=\"20%\"> <span class=\"tl\">Obchodné meno:&nbsp;<\\/span><\\/td>\\s*<td align=\"left\" width=\"80%\"><table width=\"100%\" border=\"0\">\\s*<tr>\\s*<td width=\"67%\"> <span class='ra'>(?<name>[^<]*)<\\/span><br><\\/td>\\s*<td width=\"33%\" valign='top'>&nbsp; <span class='ra'>\\(od: \\d{2}\\.\\d{2}\\.\\d{4}\\)<\\/span><\\/td>\\s*<\\/tr>\\s*<\\/table><\\/td>\\s*<\\/tr>\\s*<\\/table>\\s*<table width=\"100%\" border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"0\" bgcolor='#ffffff'>\\s*<tr>\\s*<td align=\"left\" valign=\"top\" width=\"20%\"> <span class=\"tl\">Sídlo:&nbsp;<\\/span><\\/td>\\s*<td align=\"left\" width=\"80%\"><table width=\"100%\" border=\"0\">\\s*<tr>\\s*<td width=\"67%\"> <span class='ra'>(?<street>[^<]*)<\\/span> <span class='ra'>(?<number>[^<]*)<\\/span><br> <span class='ra'>(?<city>[^<]*)<\\/span> <span class='ra'>(?<zip>[^<]*)<\\/span><br><\\/td>\\s*<td width=\"33%\" valign='top'>&nbsp; <span class='ra'>\\(od: \\d{2}\\.\\d{2}\\.\\d{4}\\)<\\/span><\\/td>\\s*<\\/tr>\\s*<\\/table><\\/td>\\s*<\\/tr>\\s*<\\/table>\\s*<table width=\"100%\" border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"0\" bgcolor='#ffffff'>\\s*<tr>\\s*<td align=\"left\" valign=\"top\" width=\"20%\"> <span class=\"tl\">IČO:&nbsp;<\\/span><\\/td>\\s*<td align=\"left\" width=\"80%\"><table width=\"100%\" border=\"0\">\\s*<tr>\\s*<td width=\"67%\"> <span class='ra'>(?<id>[^<]*)<\\/span><br><\\/td>/i", $data, $tmp);
     return ['name' => Strings::trim(html_entity_decode(@$tmp['name'][0])), 'address' => ['street' => Strings::trim(@$tmp['street'][0]), 'number' => Strings::trim(@$tmp['number'][0]), 'city' => Strings::trim(@$tmp['city'][0]), 'zip' => Strings::trim(str_replace(' ', '', @$tmp['zip'][0]))], 'id' => Strings::trim(str_replace(' ', '', @$tmp['id'][0]))];
 }
Esempio n. 4
0
 /**
  * Get mapper
  * @param string $contentType in format mimeType[; charset=utf8]
  * @return IMapper
  *
  * @throws InvalidStateException
  */
 public function getMapper($contentType)
 {
     $contentType = explode(';', $contentType);
     $contentType = Strings::trim($contentType[0]);
     if (!isset($this->services[$contentType])) {
         throw new InvalidStateException('There is no mapper for Content-Type: ' . $contentType);
     }
     return $this->services[$contentType];
 }
Esempio n. 5
0
 public function getControl()
 {
     $el = parent::getControl();
     if ($this->emptyValue !== '') {
         $el->attrs['data-nette-empty-value'] = Strings::trim($this->translate($this->emptyValue));
     }
     if (isset($el->placeholder)) {
         $el->placeholder = $this->translate($el->placeholder);
     }
     return $el;
 }
Esempio n. 6
0
 private static function sanitize($type, $value)
 {
     if ($type === Form::DATA_TEXT) {
         return is_scalar($value) ? Strings::normalizeNewLines($value) : NULL;
     } elseif ($type === Form::DATA_LINE) {
         return is_scalar($value) ? Strings::trim(strtr($value, "\r\n", '  ')) : NULL;
     } elseif ($type === Form::DATA_FILE) {
         return $value instanceof Nette\Http\FileUpload ? $value : NULL;
     } else {
         throw new Nette\InvalidArgumentException('Unknown data type');
     }
 }
Esempio n. 7
0
 public function extractTags($input)
 {
     $matches = Strings::match($input, '/^\\s*(?<tag_list>\\[\\s*[\\pL\\d._-]+\\s*\\](?:\\s*(?&tag_list))?)/u');
     if ($matches) {
         $tags = Strings::trim($matches['tag_list'], '[] ');
         $tags = Strings::split($tags, '/\\]\\s*\\[/');
         $tags = array(array_map('Nette\\Utils\\Strings::webalize', $tags), $tags);
     } else {
         $tags = array();
     }
     return $tags;
 }
 /**
  * @param string $rawValue
  * @return string[]
  * @throws DateTimeParseException
  */
 private function parseDateTimeStringFromRawValue($rawValue)
 {
     $parts = explode($this->delimiter, Strings::trim($rawValue));
     $partsSize = count($parts);
     if ($partsSize % 2 !== 0) {
         throw new DateTimeParseException('Error in parsing interval. Mishmash in delimiters.');
     }
     $sliceSize = count($parts) / 2;
     $leftValue = implode($this->delimiter, array_slice($parts, 0, $sliceSize));
     $rightValue = implode($this->delimiter, array_slice($parts, $sliceSize, $partsSize));
     return [$leftValue, $rightValue];
 }
Esempio n. 9
0
 public function renderResults($query, $page = NULL, $filter = NULL)
 {
     if (!Strings::trim($query)) {
         $this->redirect('Homepage:default');
     }
     $this['searchResultsForm-form-query']->setDefaultValue($query);
     $this->template->query = $query;
     $this->template->filter = $filter;
     list($limit, $offset) = $this->getLinearLimitOffset($page ?: 1);
     $this->template->search = $results = $this->search->query($query, $limit, $offset, $filter);
     $this->payload->results = $results->count();
     $this->redrawControl('results');
 }
Esempio n. 10
0
 /**
  * Parses allowed time ranges for cron task. If annotation is invalid
  * throws exception.
  *
  * @param string $annotation
  * @return string[][]|null
  * @throws \stekycz\Cronner\InvalidParameterException
  */
 public static function parseTimes($annotation)
 {
     $times = NULL;
     static::checkAnnotation($annotation);
     $annotation = Strings::trim($annotation);
     if (Strings::length($annotation)) {
         if ($values = static::splitMultipleValues($annotation)) {
             $times = array();
             foreach ($values as $time) {
                 $times = array_merge($times, static::parseOneTime($time));
             }
             usort($times, function ($a, $b) {
                 return $a < $b ? -1 : ($a > $b ? 1 : 0);
             });
         }
     }
     return $times ?: NULL;
 }
 /**
  * Parse search query.
  *
  * @param  string
  * @return array associative array with keys 'query' and 'tags'
  */
 public function parseQuery($input)
 {
     // normalize input
     $input = Strings::lower(Strings::trim($input));
     $input = Strings::replace($input, '/\\s+/', ' ');
     // extract tags
     $matches = Strings::matchAll($input, '/(?<=^|\\s)tag:\\s*(?<tag_list>[\\pL\\d_-]+(?:\\s*,\\s*(?&tag_list))?)/u');
     $tags = array();
     $query = $input;
     foreach ($matches as $m) {
         $tmp = Strings::split($m['tag_list'], '/\\s*,\\s*/');
         $tmp = array_map('Nette\\Utils\\Strings::webalize', $tmp);
         $tmp = array_unique($tmp);
         $tags = array_merge($tags, $tmp);
         $query = str_replace($m[0], '', $query);
     }
     $query = Strings::trim($query) ?: null;
     return array('query' => $query, 'tags' => $tags);
 }
Esempio n. 12
0
 public function handleEdit($pk, $value)
 {
     $value = Strings::trim($value);
     if (!$value) {
         $this->sendJson(['status' => 'error', 'message' => 'Název stavu nesmí být prázdný']);
     }
     $state = $this->states->findOneBy(['label' => $value]);
     if ($state) {
         $this->sendJson(['status' => 'error', 'message' => 'Již existuje stav s popiskem ' . $value]);
     }
     /** @var State $state */
     $state = $this->states->find($pk);
     if (!$state) {
         $this->sendJson(['status' => 'error', 'message' => 'Nebyl nalezen upravovaný stav']);
     }
     $state->label = $value;
     $this->states->save($state);
     $this->sendJson(['status' => 'success', 'pk' => $pk, 'new label' => $value]);
 }
Esempio n. 13
0
File: Hi.php Progetto: ondrs/hi
 /**
  * @param string $name
  * @param NULL|string $gender
  * @return bool|string
  */
 public function to($name, $gender = NULL)
 {
     $name = Strings::fixEncoding($name);
     $name = Strings::trim($name);
     $name = Strings::lower($name);
     $url = self::API_URL . '?name=' . urlencode($name);
     if ($this->type !== NULL) {
         $url .= '&type=' . urlencode($this->type);
     }
     if ($gender !== NULL) {
         $url .= '&gender=' . urlencode($gender);
     }
     return $this->cache->load($url, function ($dependencies) use($url) {
         $data = $this->simpleCurl->get($url);
         $json = self::parseJson($data);
         $result = $json->success ? $json->results[0] : FALSE;
         $this->cache->save($url, $result, $dependencies);
         return $result;
     });
 }
Esempio n. 14
0
 public function renderDefault($search)
 {
     //FIXME tagy ::: 'publish_date <=' => new \DateTime()
     $string = Strings::lower(Strings::normalize($search));
     $string = Strings::replace($string, '/[^\\d\\w]/u', ' ');
     $words = Strings::split(Strings::trim($string), '/\\s+/u');
     $words = array_unique(array_filter($words, function ($word) {
         return Strings::length($word) > 1;
     }));
     $words = array_map(function ($word) {
         return Strings::toAscii($word);
     }, $words);
     $string = implode(' ', $words);
     $this->template->tag = $this->tags->findOneBy(['name' => $string]);
     $result = $this->posts->fulltextSearch($string);
     if (count($result) == 0) {
         $this->template->search = $search;
         $this->template->error = 'Nic nebylo nalezeno';
     } else {
         $this->template->search = $search;
         $this->template->result = $result;
     }
 }
Esempio n. 15
0
 /**
  * Returns options part of command
  *
  * @param mixed $width
  * @param mixed $height
  * @param null|int $quality
  * @return string
  */
 private function getCommandOptions($width, $height, $quality)
 {
     $options = [];
     if (isset($width) && (int) $width === 0) {
         $width = $this->image->getWidth() . '!';
     }
     if (isset($height) && (int) $height === 0) {
         $height = $this->image->getHeight() . '!';
     }
     if (!isset($height)) {
         $options['resize'] = '"' . $width . '"';
     } elseif (!isset($width)) {
         $options['resize'] = '"x' . $height . '"';
     } else {
         $options['resize'] = '"' . Strings::trim($width, '!') . 'x' . Strings::trim($height, '!') . '^"';
     }
     if (isset($width) && isset($height)) {
         $options['gravity'] = 'center';
         $options['crop'] = '"' . $width . 'x' . $height . '+0+0"';
     }
     if (isset($quality) && $quality !== 0) {
         $options['quality'] = $quality;
     }
     $command = [];
     foreach ($options as $opt => $value) {
         $command[] = '-' . $opt . ' ' . $value;
     }
     return implode(' ', $command);
 }
Esempio n. 16
0
 /**
  * Filter: removes unnecessary whitespace and shortens value to control's max length.
  * @return string
  */
 public function sanitize($value)
 {
     if ($this->control->maxlength) {
         $value = Nette\Utils\Strings::substring($value, 0, $this->control->maxlength);
     }
     if (strcasecmp($this->control->getName(), 'input') === 0) {
         $value = Nette\Utils\Strings::trim(strtr($value, "\r\n", '  '));
     }
     return $value;
 }
Esempio n. 17
0
 /**
  * @param \Reflector $element
  *
  * @return bool
  */
 protected function checkPermission(\Reflector $element)
 {
     // Check if element has @Secured\Permission annotation
     if ($element->hasAnnotation('Secured\\Permission')) {
         $permissions = (array) $element->getAnnotation('Secured\\Permission');
         foreach ($permissions as $permission) {
             // Parse resource & privilege from permission
             list($resource, $privilege) = explode(Security\Permission::DELIMITER, $permission);
             // Remove white spaces
             $resource = Utils\Strings::trim($resource);
             $privilege = Utils\Strings::trim($privilege);
             if ($this->user->isAllowed($resource, $privilege)) {
                 return TRUE;
             }
         }
         return FALSE;
     }
     return TRUE;
 }
Esempio n. 18
0
 /**
  * @param string $email
  * @return string
  */
 public static function sanitizeUserEmail($email)
 {
     return Strings::lower(Strings::trim($email));
 }
Esempio n. 19
0
 /**
  * Generates control's HTML element.
  * @return \Nette\Utils\Html
  */
 public function getControl()
 {
     $container = \Nette\Utils\Html::el('div');
     /** @var $control \Nette\Utils\Html */
     $control = parent::getControl();
     if ($this->delimiter !== NULL && Strings::trim($this->delimiter) !== '') {
         $control->attrs['data-tag-delimiter'] = $this->delimiter;
     }
     if ($this->joiner !== NULL && Strings::trim($this->joiner) !== '') {
         $control->attrs['data-tag-joiner'] = $this->joiner;
     }
     if ($this->suggestCallback !== NULL) {
         $form = $this->getForm();
         if (!$form || !$form instanceof Form) {
             throw new InvalidStateException("TagInput supports only Nette\\Application\\UI\\Form.");
         }
         $control->attrs['data-tag-suggest'] = $form->getPresenter()->link('this', array('do' => $this->lookupPath('Nette\\Application\\UI\\Presenter') . '-suggest'));
     }
     $container->add($control);
     return $container;
 }
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $languageArgument = $input->getArgument(self::LANGUAGE_ARGUMENT);
     /** @var Language $language */
     if (($language = $this->languagesRepository->findOneBy(['shortCode' => $languageArgument])) === NULL) {
         $output->writeln("<error>Unknown language {$languageArgument}</error>");
         return 1;
     }
     /** @var Season $season */
     foreach ($this->seasonsRepository->findBy(['language' => $language]) as $season) {
         foreach ($season->getEpisodes() as $episode) {
             $file = "S{$season->getNumber()}E{$episode->getNumber()}{$language->getShortCode()}.txt";
             $handle = fopen($this->scenariosDir . '/' . $file, 'r');
             if ($handle) {
                 $screenplayLine = 1;
                 while (($line = fgets($handle)) !== FALSE) {
                     $name = Strings::before($line, ':');
                     $isCharacter = $name && !in_array($name, self::KNOWN_NON_CHARACTERS, TRUE) && str_word_count($name, 0) < 3 ? TRUE : FALSE;
                     $character = $isCharacter ? $this->charactersRepository->findOneBy(['slug' => Strings::webalize($name), 'language' => $language]) : NULL;
                     if ($isCharacter && $character === NULL) {
                         $character = new Character(Strings::capitalize($name), $language);
                         $this->entityManager->persist($character);
                         $this->entityManager->flush($character);
                     }
                     $text = $isCharacter ? str_replace($name . ': ', '', $line) : $line;
                     $text = Strings::trim($text);
                     if (empty($text)) {
                         continue;
                     }
                     $screenplay = new Screenplay($episode, $text, $character, $screenplayLine, !$isCharacter);
                     $this->entityManager->persist($screenplay);
                     $this->entityManager->flush($screenplay);
                     $screenplayLine++;
                 }
                 fclose($handle);
             } else {
                 $output->writeln("<error>Scénář {$file} neexistuje!</error>");
                 return 1;
             }
         }
     }
     return 0;
 }
Esempio n. 21
0
 /**
  * @param string|array $permission
  * @param array $details
  *
  * @return $this
  *
  * @throws Exceptions\InvalidArgumentException
  */
 public function addPermission($permission, $details = [])
 {
     if (is_array($permission)) {
         if (!isset($permission['resource']) || !isset($permission['privilege'])) {
             throw new Exceptions\InvalidArgumentException('Permission must include resource & privilege.');
         }
         // Remove white spaces
         $resource = Utils\Strings::trim($permission['resource']);
         $privilege = Utils\Strings::trim($permission['privilege']);
         // Convert it to string form
         $permission = $resource . self::DELIMITER . $privilege;
         // Store permission definition in object
         $this->permissions[$permission] = new Entities\Permission($resource, $privilege, $details);
     } else {
         if ($permission instanceof Entities\IPermission) {
             // Extract resource & privilege from permission
             $resource = $permission->getResource();
             $privilege = $permission->getPrivilege();
             // Store permission definition in object
             $this->permissions[(string) $permission] = $permission;
             // Resource & privilege is in string with delimiter
         } else {
             if (is_string($permission) && Utils\Strings::contains($permission, self::DELIMITER)) {
                 // Parse resource & privilege from permission
                 list($resource, $privilege) = explode(self::DELIMITER, $permission);
                 // Remove white spaces
                 $resource = Utils\Strings::trim($resource);
                 $privilege = Utils\Strings::trim($privilege);
                 // Convert it to string form
                 $permission = $resource . self::DELIMITER . $privilege;
                 // Store permission definition in object
                 $this->permissions[$permission] = new Entities\Permission($resource, $privilege, $details);
             } else {
                 throw new Exceptions\InvalidArgumentException('Permission must be only string with delimiter, array with resource & privilege or instance of IPub\\Permissions\\Entities\\IPermission, ' . gettype($permission) . ' given');
             }
         }
     }
     // Check if resource exists...
     if (!$this->hasResource($resource)) {
         // ...& add resource to parent
         $this->addResource($resource);
     }
     foreach ($this->roles as $role) {
         // Allow all privileges for administrator
         if ($role->isAdministrator()) {
             $this->allow($role->getKeyName(), self::ALL, self::ALL);
             // For others apply setup privileges
         } else {
             // This combination role-resource-privilege is allowed
             if ($role->hasPermission($permission)) {
                 $this->allow($role->getKeyName(), $resource, $privilege);
             }
         }
     }
     return $this;
 }
Esempio n. 22
0
 /**
  * @param Utils\ArrayHash $element
  *
  * @return bool
  */
 protected function checkPermission(Utils\ArrayHash $element)
 {
     // Check if element has permission parameter
     if ($element->offsetExists('permission')) {
         $permissions = (array) $element->offsetGet('permission');
         foreach ($permissions as $permission) {
             // Parse resource & privilege from permission
             list($resource, $privilege) = explode(Security\Entities\IPermission::DELIMITER, $permission);
             // Remove white spaces
             $resource = Utils\Strings::trim($resource);
             $privilege = Utils\Strings::trim($privilege);
             if ($this->user->isAllowed($resource, $privilege)) {
                 return TRUE;
             }
         }
         return FALSE;
     }
     return TRUE;
 }
Esempio n. 23
0
 /**
  * Filter: removes unnecessary whitespace
  *
  * @return string
  */
 public function sanitize($value)
 {
     return Strings::trim(strtr($value, "\r\n", '  '));
 }
Esempio n. 24
0
 /**
  * @param array $values
  */
 public function __construct(array $values)
 {
     $values[static::TASK] = isset($values[static::TASK]) && is_string($values[static::TASK]) ? Strings::trim($values[static::TASK]) : '';
     $this->values = $values;
 }
Esempio n. 25
0
 public function getWordVariations($word)
 {
     $sNoBrackets = Strings::replace($word, "/[\\[\\](){}]/", "");
     $keywords = array_merge(array($word, $sNoBrackets), explode("-", $sNoBrackets), explode("_", $sNoBrackets), explode(" ", $sNoBrackets), Strings::split($sNoBrackets, "[ _-]"));
     foreach ($keywords as $index => $kw) {
         $keywords[$index] = Strings::trim($kw);
         $keywords[$index] = Strings::replace($keywords[$index], '/^\\+/', '');
         // remove + operator
         if (Strings::length($keywords[$index]) < 3) {
             unset($keywords[$index]);
         } else {
             $keywords[] = Strings::toAscii($keywords[$index]);
         }
     }
     $keywords = array_unique($keywords);
     $keywords = array_values($keywords);
     return $keywords;
 }
Esempio n. 26
0
 /**
  * @param \Reflector $element
  *
  * @return bool
  */
 protected function checkPermission(\Reflector $element)
 {
     // Check if element has @Secured\Permission annotation
     if ($element->hasAnnotation('Secured\\Permission')) {
         $permission = $element->getAnnotation('Secured\\Permission');
         list($resource, $privilege) = explode(Security\Entities\IPermission::DELIMITER, $permission);
         $resource = Utils\Strings::trim($resource);
         $privilege = Utils\Strings::trim($privilege);
         if ($this->user->isAllowed($resource, $privilege)) {
             return TRUE;
         }
         return FALSE;
     }
     return TRUE;
 }
Esempio n. 27
0
 /**
  * Sets directory with thumbnails
  *
  * @param string $thumbnailsDirectory
  * @throws \Imager\NotExistsException
  * @throws \Imager\BadPermissionException
  */
 private function setThumbnailsDirectory($thumbnailsDirectory)
 {
     $thumbnailsDirectory = Strings::trim($thumbnailsDirectory);
     $thumbnailsDirectory = rtrim($thumbnailsDirectory, DIRECTORY_SEPARATOR);
     if (!is_dir($thumbnailsDirectory)) {
         try {
             FileSystem::createDir($thumbnailsDirectory);
         } catch (Nette\IOException $e) {
             $msg = sprintf('Directory "%s" with thumbnails not exists and cannot be create.', $thumbnailsDirectory);
             throw new NotExistsException($msg, 0, $e);
         }
     }
     if (!is_writable($thumbnailsDirectory)) {
         $msg = sprintf('Directory "%s" with thumbnails is not writable.', $thumbnailsDirectory);
         throw new BadPermissionException($msg);
     }
     $this->thumbnailsDirectory = $thumbnailsDirectory . DIRECTORY_SEPARATOR;
 }
Esempio n. 28
0
use Nette\Utils\Strings;
require __DIR__ . '/shortcuts.php';
require __DIR__ . '/../vendor/autoload.php';
$configurator = new Nette\Configurator();
$debugMode = FALSE;
$environmentFile = __DIR__ . '/local/environment';
if (file_exists($environmentFile)) {
    $environment = file_get_contents($environmentFile);
    $debugMode = $environment === 'production' ? FALSE : TRUE;
} else {
    $environment = 'production';
}
$environment = Strings::trim(Strings::lower($environment));
$debugSwitchFile = __DIR__ . '/local/debug';
if (file_exists($debugSwitchFile)) {
    $debugMode = Strings::trim(mb_strtolower(file_get_contents($debugSwitchFile))) === 'true' ? TRUE : FALSE;
}
// Enable Nette Debugger for error visualisation & logging
$configurator->setDebugMode($debugMode);
$configurator->enableDebugger(__DIR__ . '/../log');
// Specify folder for cache
$configurator->setTempDirectory(__DIR__ . '/../temp');
// Enable RobotLoader - this will load all classes automatically
$configurator->createRobotLoader()->addDirectory(__DIR__)->addDirectory(__DIR__ . '/../libs')->register();
// Create Dependency Injection container from config.neon file
$configurator->addConfig(__DIR__ . '/config/config.neon');
$localConfig = __DIR__ . '/local/config.local.neon';
if (file_exists($localConfig)) {
    $configurator->addConfig($localConfig);
}
$container = $configurator->createContainer();
Esempio n. 29
0
 /**
  * @param string $key
  *
  * @return Utils\Html
  *
  * @throws Exceptions\InvalidArgumentException
  */
 public function getControlPart($key)
 {
     $name = $this->getHtmlName();
     // Try to get translator
     $translator = $this->getTranslator();
     if ($translator instanceof Localization\ITranslator && method_exists($translator, 'getLocale') === TRUE) {
         try {
             $locale = $translator->getLocale();
         } catch (\Exception $ex) {
             $locale = 'en_US';
         }
     } else {
         $locale = 'en_US';
     }
     if ($key === static::FIELD_COUNTRY) {
         $control = Forms\Helpers::createSelectBox(array_reduce($this->getAllowedCountries(), function (array $result, $row) use($locale) {
             $countryName = FormPhone\Locale\Locale::getDisplayRegion(FormPhone\Locale\Locale::countryCodeToLocale($row), $locale);
             $result[$row] = Utils\Html::el('option')->setText('+' . $this->phoneUtils->getCountryCodeForCountry($row) . ' (' . $countryName . ')')->addAttributes(['data-mask' => preg_replace('/[0-9]/', '9', $this->phoneUtils->getExampleNationalNumber($row))])->value($row);
             return $result;
         }, []), ['selected?' => $this->country === NULL ? $this->defaultCountry : $this->country]);
         $control->addAttributes(['name' => $name . '[' . static::FIELD_COUNTRY . ']', 'id' => $this->getHtmlId() . '-' . static::FIELD_COUNTRY, 'data-ipub-forms-phone' => '', 'data-settings' => json_encode(['field' => $name . '[' . static::FIELD_NUMBER . ']'])]);
         if ($this->isDisabled()) {
             $control->disabled(TRUE);
         }
         return $control;
     } else {
         if ($key === static::FIELD_NUMBER) {
             $input = parent::getControl();
             $control = Utils\Html::el('input');
             $control->addAttributes(['name' => $name . '[' . static::FIELD_NUMBER . ']', 'id' => $this->getHtmlId() . '-' . static::FIELD_NUMBER, 'value' => $this->number, 'type' => 'text', 'data-nette-empty-value' => Utils\Strings::trim($this->translate($this->emptyValue)), 'data-nette-rules' => $input->{'data-nette-rules'}]);
             if ($this->isDisabled()) {
                 $control->disabled(TRUE);
             }
             return $control;
         }
     }
     throw new Exceptions\InvalidArgumentException('Part ' . $key . ' does not exist.');
 }
 /**
  * @param string $html
  * @return \Lunchbot\Menu\LunchMenuItem[]
  */
 public function parseHtml(string $html) : array
 {
     $crawler = new Crawler();
     $crawler->addContent($html);
     $rows = $crawler->filter('div.entry-content table tr')->each(function (Crawler $node) {
         return $node;
     });
     $todayDayOfWeek = (int) $this->today->format('N');
     $currentDayBlock = false;
     /** @var Crawler $item */
     $result = [];
     foreach ($rows as $item) {
         $headlineTag = $item->children();
         $headline = $headlineTag->text();
         $dayOfWeek = \Nette\Utils\Strings::match($headline, '~^(\\w+)\\s~u')[1] ?? null;
         if (isset(self::$DAYS[$dayOfWeek])) {
             if ($currentDayBlock) {
                 break;
                 // found tomorrow menu block
             } elseif (self::$DAYS[$dayOfWeek] === $todayDayOfWeek) {
                 $currentDayBlock = true;
             }
         } elseif ($currentDayBlock) {
             if (\Nette\Utils\Strings::trim($headline) === 'Dezert') {
                 break;
             }
             $result[] = new LunchMenuItem($headlineTag->siblings()->text());
         }
     }
     return $result;
 }