public static function findTemplate($stack, $action = NULL) { $template = strtolower(\Staq\Util::getStackSubQuery($stack, '/')) . '.twig'; $template = str_replace('_', '/', $template); if (!empty($action)) { $template = $action . '/' . $template; } $folder = strtolower(\Staq\Util::getStackType($stack)); while (TRUE) { if (\Staq::App()->getFilePath('template/' . $folder . '/' . $template)) { break; } if (\UString::has($template, '/')) { $template = \UString::substrBeforeLast($template, '/') . '.twig'; } else { $template = 'index.twig'; break; } } return $folder . '/' . $template; }
public function addInputFilter($inputName, $filterName, $filterCallback = NULL, $errorMessage = NULL) { if (is_null($errorMessage) && is_string($filterCallback) && \UString::has($filterCallback, ' ')) { $errorMessage = $filterCallback; $filterCallback = NULL; } $input = $this->getInput($inputName); $filterClass = $this->namespace . '\\FormInputFilter'; $filter = new $filterClass($filterName, $filterCallback); $input->filters[$filter->getName()] = $filter; if (!is_null($errorMessage)) { $filter->errorMessage = $errorMessage; } return $this; }
protected function initializeNamespaces() { if (empty($this->namespaces)) { $vendorPath = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR; if (\UString::has(__DIR__, $vendorPath)) { $baseDir = \UString::substrBeforeLast(__DIR__, $vendorPath); } else { $baseDir = __DIR__ . '/../..'; } $psr0 = (require $baseDir . '/vendor/composer/autoload_namespaces.php'); foreach ($psr0 as $namespace => $pathList) { foreach ($pathList as $key => $path) { $psr0[$namespace][$key] = realpath($path . '/' . str_replace('\\', '/', $namespace)); } } $psr4 = (require $baseDir . '/vendor/composer/autoload_psr4.php'); foreach ($psr4 as $namespace => $pathList) { foreach ($pathList as $key => $path) { $psr0[$namespace][$key] = realpath($path); } } $this->namespaces = array_merge($psr0, $psr4); } }
public static function substrAfterLast($haystack, $needles) { \UArray::doConvertToArray($needles); $result = $haystack; foreach ($needles as $needle) { if (!empty($needle) && \UString::has($haystack, $needle)) { $cut = substr($haystack, strrpos($haystack, $needle) + strlen($needle)); if (strlen($cut) < strlen($result)) { $result = $cut; } } } return $result; }
public function test_has__multiple_no_match() { $test = \UString::has('/path/to/a/folder', array('php', '.')); $this->assertFalse($test); }
protected function parseIni($file) { $parsed = array(); if (is_array($file)) { $parsed = $file; } else { if (\UString::has($file, PHP_EOL)) { $parsed = @parse_ini_string($file, TRUE); if ($parsed === FALSE) { $this->manageError('The ini string has a bad format.'); } } else { if (is_file($file)) { $parsed = @parse_ini_file($file, TRUE); if ($parsed === FALSE) { $this->manageError('The ini file has a bad format: ' . $file); } } else { $this->manageError('No such file or directory: ' . $file); } } } return $parsed; }
public static function isDeepSelector($selector) { return \UString::has($selector, '.'); }
public function testLiveFildet_Validation_Nok() { $_POST['username'] = '******'; $form = $this->getLoginForm()->addInputFilter('username', 'with_a', function ($field) { return $field === '' || \UString::has($field, 'a'); }); $this->assertTrue($form->isActive(), 'Form must be active'); $this->assertFalse($form->isValid(), 'Form must be invalid'); $this->assertEquals($_POST['username'], $form->username, 'The given entry must be intact'); $this->assertEquals('with_a', $form->getInputError('username'), 'One error must be thrown, the username field must not validate the live filter'); }
protected function getClauseConditionList($request, &$parameters = false) { $whereList = []; if (is_array($request)) { foreach ($request as $fieldName => $fieldValue) { if (is_numeric($fieldName)) { if (is_string($fieldValue)) { $whereList[] = $fieldValue; } else { if (is_array($fieldValue) && isset($fieldValue[0]) && isset($fieldValue[1]) && isset($fieldValue[2])) { $fieldName = $fieldValue[0]; if (!\UString::has($fieldValue[0], '.')) { $fieldName = $this->table . '.' . $fieldName; } $whereList[] = $this->getClauseCondition($fieldName, $fieldValue[1], $fieldValue[2], $parameters); } } } else { if (!\UString::has($fieldName, '.')) { $fieldName = $this->table . '.' . $fieldName; } $whereList[] = $this->getClauseCondition($fieldName, '=', $fieldValue, $parameters); } } } else { $whereList[] = $request; } $whereList = array_filter($whereList, function ($a) { return !empty($a); }); return $whereList; }
public static function isStackableClass($stackable) { \UObject::doConvertToClass($stackable); return \UString::has($stackable, '\\Stack\\'); }