public static function init() { if (!static::$initialized) { $sessionTimeLimit = 20 * 60; session_set_cookie_params($sessionTimeLimit); session_start(); // Verify if session already is valid $keyDiscardTime = '___discard_after___'; $now = time(); if (isset($_SESSION[$keyDiscardTime]) && $now > $_SESSION[$keyDiscardTime]) { // this session has worn out its welcome; kill it and start a brand new one session_unset(); session_destroy(); session_start(); } // either new or old, it should live at most for another hour $_SESSION[$keyDiscardTime] = $now + $sessionTimeLimit; static::$initialized = true; //Clear all old flash data foreach ($_SESSION as $k => $v) { if (Str::contains($k, ":old:")) { static::clear($k); } } //Set all new flash data as old, to be cleared on the next request foreach ($_SESSION as $k => $v) { $parts = explode(":new:", $k); if (is_array($parts) && count($parts) == 2) { $newKey = "flash:old:" . $parts[1]; static::set($newKey, $v); static::clear($k); } } } }
/** * @param string $content * @param string $formClass * * @return string */ protected function addAllowedActionsToController($content, $formClass) { $allowedActions = 'private static $allowed_actions'; if (!Str::contains($content, $allowedActions)) { } return $content; }
public static function containsAny($haystack, $needles) { foreach ($needles as $needle) { if (Str::contains($haystack, $needle)) { return true; } } return false; }
/** * Parses custom function calls for geting function name and parameters. * * @param string $function * * @return array */ private function parseFunction($function) { if (!Str::contains($function, ':')) { return [$function, []]; } list($function, $params) = explode(':', $function, 2); $params = (array) Json::decode($params, true); return [$function, $params]; }
/** * Dispatch a call over to Form * * @param string $method The method called * @param array $parameters Its parameters * * @return Form */ public function toForm($method, $parameters) { // Disregards if the method doesn't contain 'open' if (!Str::contains($method, 'open') and !Str::contains($method, 'Open')) { return false; } $form = new Form\Form($this->app, $this->app['url'], $this->app['former.populator']); return $form->openForm($method, $parameters); }
/** * @return Member|null */ protected function getMemberByEmailOrID() { $emailorid = $this->argument('emailorid'); $member = null; if (Str::contains($emailorid, '@')) { $member = Member::get()->where("Email = '" . Convert::raw2sql($emailorid) . "'")->first(); } else { $member = Member::get()->byID($emailorid); } return $member; }
public static function fromReflectionMethod(\ReflectionMethod $method) { $methodName = $method->getName(); $docComment = $method->getDocComment(); $reactivexId = extract_doc_annotation($docComment, '@reactivex'); $demoFiles = extract_doc_annotations($docComment, '@demo'); $description = extract_doc_description($docComment); $isObservable = Str::contains($docComment, '@observable'); $demos = array_map(function ($path) { return Demo::fromPath($path); }, $demoFiles); return new DocumentedMethod($methodName, $reactivexId, $description, $demos, $isObservable); }
/** * Get array item by path separated by dots. Example: getByPath('dir.file', ['dir' => ['file' => 'text.txt']]) return "text.txt" * @param string $path * @param array|null $array * @param string $delimiter * @return array|string|null */ public static function getByPath($path, $array = null, $delimiter = '.') { // path of nothing? interest if (!Obj::isArray($array) || count($array) < 1) { return null; } // c'mon man, what the f*ck are you doing? )) if (!Str::contains($delimiter, $path)) { return $array[$path]; } $output = $array; $pathArray = explode($delimiter, $path); foreach ($pathArray as $key) { $output = $output[$key]; } return $output; }
public static function remove($key, $asMask = false) { $key = Str::toURIParam($key); if (!$asMask) { $path = static::$path . $key . ".cache"; return File::delete($path); } else { $deleted = false; $files = File::lsdir(static::$path, ".cache"); foreach ($files as $file) { if (Str::contains($file, $key)) { File::delete(static::$path . $file); $delete = true; } } return $deleted; } }
/** * Parse an option expression. * * @param string $token * * @return \Symfony\Component\Console\Input\InputOption */ protected static function parseOption($token) { $description = null; if (Str::contains($token, ' : ')) { list($token, $description) = explode(' : ', $token); $token = trim($token); $description = trim($description); } $shortcut = null; $matches = preg_split('/\\s*\\|\\s*/', $token, 2); if (isset($matches[1])) { $shortcut = $matches[0]; $token = $matches[1]; } switch (true) { case Str::endsWith($token, '='): return new InputOption(trim($token, '='), $shortcut, InputOption::VALUE_OPTIONAL, $description); case Str::endsWith($token, '=*'): return new InputOption(trim($token, '=*'), $shortcut, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $description); case preg_match('/(.+)\\=(.+)/', $token, $matches): return new InputOption($matches[1], $shortcut, InputOption::VALUE_OPTIONAL, $description, $matches[2]); default: return new InputOption($token, $shortcut, InputOption::VALUE_NONE, $description); } }
/** * Validates the cache item key according to PSR-6. * * @param string $key Cache item key * * @throws \Elegant\Cache\Exception\InvalidArgumentException For invalid key */ public static final function validateKey($key) { if (Str::contains($key, ['{', '}', '(', ')', '/', '\\', '@', ':'])) { throw new InvalidArgumentException(sprintf('Invalid key "%s" provided; contains reserved characters "{}()/\\@:".', $key)); } }
/** * Determine if a given string contains a given substring. * * @param string $haystack * @param string|array $needles * @return bool */ function str_contains($haystack, $needles) { return Str::contains($haystack, $needles); }
$options = [0 => 'Ninguna']; foreach ($tmp as $key => $value) { $options[$key] = $value; } return Form::selectFormGroup($name, $options, $title, $formname, $attributes); }); Form::macro('theMediaFormGroup', function ($name, $title, $formname, $attributes) { $options = ['Televisión', 'Periódico', 'Radio', 'Otro']; return Form::selectFormGroup($name, $options, $title, $formname, $attributes); }); Form::macro('selectFormGroup', function ($name, $options, $title, $formname, $attr) { return "\n" . '<div class="form-group"' . "\n" . ' ng-class="{\'has-error\' : film_form.' . $name . '.$invalid }">' . "\n" . ' <label for="' . $name . '" class="col-sm-2 control-label text-right">' . $title . '</label>' . "\n" . ' <div class="col-sm-10">' . "\n" . Form::select($name, $options, null, $attr) . ' </div>' . "\n" . '</div>' . "\n"; }); /** * By default all the text area inputs have the widget CKEditor. * * If you do not want the CKEditor you must set the $attr['class'] = 'no-ckeditor'. */ Form::macro('textareaFormGroup', function ($name, $title, $formname, $attr) { $attr['class'] = isset($attr['class']) ? $attr['class'] : ''; /** * If it does not has a ckeditor class then we add a full editor. */ if (!Str::contains($attr['class'], 'ckeditor')) { $attr['class'] .= ' ckeditor-full'; } return Form::wrapperInput($name, $title, Form::textarea($name, null, $attr)); }); Form::macro('wrapperInput', function ($name, $title, $input) { return "\n" . '<div class="form-group">' . "\n" . ' <label for="' . $name . '" class="col-sm-2 control-label text-right">' . $title . '</label>' . "\n" . ' <div class="col-sm-10">' . "\n" . ' ' . $input . "\n" . ' </div>' . "\n" . '</div>' . "\n"; });
public function hasFlag($flag) { return Str::contains($this->flags, $flag); }
function build_code_samples(Demo $demo) { $lines = explode("\n", $demo->demoCode); $start = -1; foreach ($lines as $position => $line) { if (Str::contains($line, 'require_once')) { $start = $position; break; } } array_splice($lines, 0, $start + 2); $demoCode = implode("\n", $lines); $url = $demo->getURL(); return <<<DEMO <div class="code php"> <pre> //from {$url} {$demoCode} </pre> </div> <div class="output"> <pre> {$demo->demoOutput} </pre> </div> DEMO; }
private static function match($method, $uri) { foreach (self::method($method) as $route => $action) { if (Str::contains($route, "(")) { list($search, $replace) = array_divide(self::$optional); $key = str_replace($search, $replace, $route, $count); if ($count > 0) { $key .= str_repeat(')?', $count); } $pattern = "#^" . strtr($key, self::$patterns) . "\$#u"; if (preg_match($pattern, $uri, $parameters)) { return new Route($method, $route, $action, array_slice($parameters, 1)); } } } }
/** * Check if the $attr is a plural form of $field, case insensitive, * or if the $field contains the $attr * * @param string $field * @param string $attr * @return boolean */ protected function attrContains($field, $attr) { return $field == \Str::singular(strtoupper($attr)) || $field == \Str::singular($attr) || $field == strtoupper($attr) || \Str::contains($field, $attr); }
/** * Get the true callable for a queued e-mail message. * * @param array $data * @return mixed */ protected function getQueuedCallable(array $data) { if (Str::contains($data['callback'], 'SerializableClosure')) { return unserialize($data['callback'])->getClosure(); } return $data['callback']; }
public static function lsdir($path, $mask = null, $options = fIterator::SKIP_DOTS) { $files = array(); $items = new fIterator($path, $options); foreach ($items as $item) { $itemFileName = $item->getBasename(); if (empty($mask) || Str::contains($itemFileName, $mask)) { $files[] = $itemFileName; } } natsort($files); return $files; }
/** * @param string $customDir * @param array $defaultDirs * * @return string|array */ protected function setTargetDirectoriesByString($customDir, $defaultDirs) { // MakeCommand.default_dirs = mymodule/somedir if (Str::contains($customDir, '/')) { return BASE_PATH . '/' . $customDir; } // MakeCommand.default_dirs = mymodule foreach ($defaultDirs as $key => $dir) { $defaultDirs[$key] = Str::replaceFirst('mysite', $customDir, $dir); } return $defaultDirs; }
/** * @param \Symfony\Component\HttpFoundation\ParameterBag $params * * @return int */ public function removeByParams(ParameterBag $params) { if (empty($params)) { return 0; } $query = $this->_query(); $hasSetCondition = false; if ($this->queryDelegate) { $query = call_user_func_array($this->queryDelegate, [$query, $params]); $hasSetCondition = true; } else { foreach ($params as $name => $value) { if (!empty($name) && $this->hasColumn($name)) { if (Str::contains($value, ',')) { $query->whereIn($name, explode(',', trim($value, ','))); } else { $query->where($name, '=', $value); } $hasSetCondition = true; } } } return $hasSetCondition ? $query->delete() : 0; }
/** * Fetches the translation of the key based on the current locale. * * @param string $key translation to obtain * @param array $values Values to be replaced in the translation string * * @return string Translated value */ public function dt($key, $values = []) { $namespace = '__main__'; if (Str::contains($key, '::')) { list($namespace, $key) = explode('::', $key); } if (empty($this->translations)) { return ''; } $loc = $this->getLocale(); if (array_key_exists($namespace, $this->translations[$loc]) && array_key_exists($key, $this->translations[$loc][$namespace])) { $translation = $this->translations[$loc][$namespace][$key]; foreach ($values as $name => $value) { $translation = str_replace(':' . $name, $value, $translation); } return $translation; } else { return ''; } }