private function maybeReplacePlaceholderWithPrefix($key) { if (Strings::startsWith($key, self::PREFIX_PLACEHOLDER)) { return $this->dbPrefix . Strings::substring($key, Strings::length(self::PREFIX_PLACEHOLDER)); } return $key; }
public function add($id, $line) { if (\Nette\Utils\Strings::startsWith($id, '$')) { return; } $this->messages[$id] = ['line' => $line, 'msgid' => $id]; }
private static function prepareMacro(MacroNode $node, PhpWriter $writer) { $media = null; $module = null; while ($node->tokenizer->hasNext()) { $words[] = $node->tokenizer->fetchWord(); } foreach ($words as $index => $word) { if (Strings::startsWith($word, "module:")) { $module = self::parseModule($word); unset($words[$index]); } if (Strings::startsWith($word, "media:")) { $media = self::parseMedia($word); unset($words[$index]); } if (Strings::startsWith($word, "alt=")) { unset($words[$index]); } } $param = implode(', ', $words); $result = $writer->write("\$assetsLoader = \$control->getWidget('assetsLoader');"); if (isset($module)) { $result .= $writer->write("\$assetsLoader->setModule('{$module}');"); } else { $result .= $writer->write("\$assetsLoader->setModule(null);"); } $result .= $writer->write("\$assetsLoader->setMedia('{$media}');"); $result .= 'if ($assetsLoader instanceof Nette\\Application\\UI\\IPartiallyRenderable) $assetsLoader->validateControl();'; return array('php' => $result, 'param' => $param); }
public function createComponent($name) { if (Strings::startsWith($name, 'vysledkovka')) { return $this->createComponentVysledkovka($name); } return parent::createComponent($name); }
/** * @param \Nette\DI\Container $dic * @throws MemberAccessException * @internal */ public function injectComponentFactories(Nette\DI\Container $dic) { if (!$this instanceof Nette\Application\UI\PresenterComponent && !$this instanceof Nette\Application\UI\Component) { throw new MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.'); } $this->autowireComponentFactoriesLocator = $dic; $storage = $dic->hasService('autowired.cacheStorage') ? $dic->getService('autowired.cacheStorage') : $dic->getByType('Nette\\Caching\\IStorage'); $cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireComponentFactories'); if ($cache->load($presenterClass = get_class($this)) !== NULL) { return; } $ignore = class_parents('Nette\\Application\\UI\\Presenter') + ['ui' => 'Nette\\Application\\UI\\Presenter']; $rc = new ClassType($this); foreach ($rc->getMethods() as $method) { if (in_array($method->getDeclaringClass()->getName(), $ignore, TRUE) || !Strings::startsWith($method->getName(), 'createComponent')) { continue; } foreach ($method->getParameters() as $parameter) { if (!($class = $parameter->getClassName())) { // has object type hint continue; } if (!$this->findByTypeForFactory($class) && !$parameter->allowsNull()) { throw new MissingServiceException("No service of type {$class} found. Make sure the type hint in {$method} is written correctly and service of this type is registered."); } } } $files = array_map(function ($class) { return ClassType::from($class)->getFileName(); }, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore)); $files[] = ClassType::from($this->autowireComponentFactoriesLocator)->getFileName(); $cache->save($presenterClass, TRUE, [$cache::FILES => $files]); }
/** * @return self */ public static function from(\ReflectionParameter $from) { $param = new static(); $param->name = $from->getName(); $param->reference = $from->isPassedByReference(); if ($from->isArray()) { $param->typeHint = 'array'; } elseif (PHP_VERSION_ID >= 50400 && $from->isCallable()) { $param->typeHint = 'callable'; } else { try { $param->typeHint = $from->getClass() ? '\\' . $from->getClass()->getName() : NULL; } catch (\ReflectionException $e) { if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) { $param->typeHint = '\\' . $m[1]; } else { throw $e; } } } $param->optional = PHP_VERSION_ID < 50407 ? $from->isOptional() || $param->typeHint && $from->allowsNull() : $from->isDefaultValueAvailable(); $param->defaultValue = PHP_VERSION_ID === 50316 ? $from->isOptional() : $from->isDefaultValueAvailable() ? $from->getDefaultValue() : NULL; $namespace = $from->getDeclaringClass() ? $from->getDeclaringClass()->getNamespaceName() : NULL; $namespace = $namespace ? "\\{$namespace}\\" : '\\'; if (Nette\Utils\Strings::startsWith($param->typeHint, $namespace)) { $param->typeHint = substr($param->typeHint, strlen($namespace)); } return $param; }
public function constructUrl(Request $appRequest, Url $refUrl) { // Module prefix not match. if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) { return null; } $params = $appRequest->getParameters(); $urlStack = []; // Module prefix $moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName())); $resourceName = array_pop($moduleFrags); $urlStack += $moduleFrags; // Resource $urlStack[] = Strings::lower($resourceName); // Id if (isset($params['id']) && is_scalar($params['id'])) { $urlStack[] = $params['id']; unset($params['id']); } // Set custom action if (isset($params['action']) && $this->_isApiAction($params['action'])) { unset($params['action']); } $url = $refUrl->getBaseUrl() . implode('/', $urlStack); // Add query parameters if (!empty($params)) { $url .= "?" . http_build_query($params); } return $url; }
/** * @param string $user * @param string $name * @param string $type * @param string $action * @param mixed[] $templateArgs */ public function send($user, $name, $type, $action, array $templateArgs = array()) { $presenter = $this->createPresenter(); $request = $this->getRequest($type, $action); $response = $presenter->run($request); $presenter->template->user = $user; $presenter->template->name = $name; foreach ($templateArgs as $key => $val) { $presenter->template->{$key} = $val; } if (!$response instanceof TextResponse) { throw new InvalidArgumentException(sprintf('Type \'%s\' does not exist.', $type)); } try { $data = (string) $response->getSource(); } catch (\Nette\Application\BadRequestException $e) { if (Strings::startsWith($e->getMessage(), 'Page not found. Missing template')) { throw new InvalidArgumentException(sprintf('Type \'%s\' does not exist.', $type)); } } $message = new Message(); $message->setHtmlBody($data); $message->setSubject(ucfirst($action)); $message->setFrom($this->senderEmail, $this->senderName ?: null); $message->addTo($user, $name); $this->mailer->send($message); }
/** * Akce pro kontrolu přístupů ke složkám a souborům */ public function actionFiles() { $filesManager = $this->createFilesManager(); $writableDirectories = $filesManager->checkWritableDirectories(); $writableFiles = $filesManager->checkWritableFiles(); $stateError = false; $statesArr = []; if (!empty($writableDirectories)) { foreach ($writableDirectories as $directory => $state) { $statesArr['Directory: ' . (Strings::startsWith($directory, '/') ? '.' : '') . $directory] = $state; if (!$state) { $stateError = true; } } } if (!empty($writableFiles)) { foreach ($writableFiles as $file => $state) { $statesArr['File: ' . (Strings::startsWith($file, '/') ? '.' : '') . $file] = $state; if (!$state) { $stateError = true; } } } if ($stateError) { //vyskytla se chyba $this->template->states = $statesArr; } else { $this->redirect($this->getNextStep('files')); } }
/** @return ClassType */ public static function from($from) { $from = $from instanceof \ReflectionClass ? $from : new \ReflectionClass($from); $class = new static($from->getShortName()); $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class'); $class->final = $from->isFinal(); $class->abstract = $from->isAbstract() && $class->type === 'class'; $class->implements = $from->getInterfaceNames(); $class->documents = preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n")); $namespace = $from->getNamespaceName(); if ($from->getParentClass()) { $class->extends = $from->getParentClass()->getName(); if ($namespace) { $class->extends = Strings::startsWith($class->extends, "{$namespace}\\") ? substr($class->extends, strlen($namespace) + 1) : '\\' . $class->extends; } $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames()); } if ($namespace) { foreach ($class->implements as &$interface) { $interface = Strings::startsWith($interface, "{$namespace}\\") ? substr($interface, strlen($namespace) + 1) : '\\' . $interface; } } foreach ($from->getProperties() as $prop) { $class->properties[$prop->getName()] = Property::from($prop); } foreach ($from->getMethods() as $method) { if ($method->getDeclaringClass() == $from) { // intentionally == $class->methods[$method->getName()] = Method::from($method); } } return $class; }
/** * @param \Nette\Application\Application $application * @param \Nette\Application\Request $request */ public function __invoke(Application $application, Request $request) { if (PHP_SAPI === 'cli') { newrelic_background_job(TRUE); } $params = $request->getParameters(); $action = $request->getPresenterName(); if (isset($params[$this->actionKey])) { $action = sprintf('%s:%s', $action, $params[$this->actionKey]); } if (!empty($this->map)) { foreach ($this->map as $pattern => $appName) { if ($pattern === '*') { continue; } if (Strings::endsWith($pattern, '*')) { $pattern = Strings::substring($pattern, 0, -1); } if (Strings::startsWith($pattern, ':')) { $pattern = Strings::substring($pattern, 1); } if (Strings::startsWith($action, $pattern)) { \VrtakCZ\NewRelic\Tracy\Bootstrap::setup($appName, $this->license); break; } } } newrelic_name_transaction($action); newrelic_disable_autorum(); }
/** * @param string * @param string * @return bool */ public function isModuleCurrent($module, $presenter = NULL) { if (Strings::startsWith($name = $this->getName(), trim($module, ':') . ':')) { return $presenter === NULL ? TRUE : Strings::endsWith($name, ':' . $presenter); } return FALSE; }
public function __call($name, $args) { if (Strings::startsWith($name, 'render')) { $this->doRenderView($this->getViewByRenderMethod($name), $args); } else { return parent::__call($name, $args); } }
/** * @param string $name * @return string|null */ public function __get($name) { $value = @$this->params[$name]; if (Strings::startsWith($value, '/')) { //pokud začínáme lomítkem, doplníme cestu na absolutní return __DIR__ . '/../..' . $value; } return $value; }
/** * @param string $type * @return string */ private function getDirectory($type) { foreach ($this->getGroups(TRUE) as $group) { if (Strings::startsWith($group->name, $type)) { return $group->directory; } } throw new Nextras\Migrations\LogicException("Unknown type '{$type}' given, expected on of 's', 'b' or 'd'."); }
/** * @return array */ public function getCart() { $out = array(); foreach ($this->shopCart as $k => $v) { if (!Nette\Utils\Strings::startsWith($k, '_') && $v > 0) { $out[$k] = $v; } } ksort($out); return $out; }
/** * @return string|NULL */ private function getNormalizedRouterName() { $config = $this->getConfig($this->defaults); if (empty($config['router'])) { return NULL; } if (Strings::startsWith($config['router'], '@')) { return Strings::substring($config['router'], 1); } return $config['router']; }
/** * @param \Nette\Application\Request $appRequest * @param \Nette\Http\Url $refUrl * @return string|null */ public function constructUrl(Request $appRequest, Url $refUrl) { $presenter = $appRequest->getPresenterName(); if (!Strings::startsWith($presenter, self::SUBMODULE_NAME . ':')) { return null; } if (Strings::endsWith($presenter, ':' . self::DEFAULT_PRESENTER)) { $presenter = substr($presenter, 0, -strlen(':' . self::DEFAULT_PRESENTER)); } $appRequest->setPresenterName(substr($presenter, strlen(self::SUBMODULE_NAME . ':'))); return parent::constructUrl($appRequest, $refUrl); }
/** * Get status code from response * @param string $response Response * @return string Status message */ public function getMessage($response) { if ($response == 'OK') { return 'OK'; } else { if (Strings::startsWith($response, 'ERROR ') && Validators::isInRange(explode(' ', $response)[1], [1, 18])) { return explode(';', $response)[1]; } else { throw new \InvalidArgumentException('Invalid response'); } } }
public function beforeRender() { parent::beforeRender(); $this->template->setTranslator($this->translator); $this->template->isHp = $this->isHp; $this->template->isMobile = $this->isMobile(); $this->template->getLatte()->addFilter('externalUrl', function ($s) { if (!Nette\Utils\Strings::startsWith($s, 'http://') && !Nette\Utils\Strings::startsWith($s, 'https://')) { $s = 'http://' . $s; } return $s; }); }
/** * @param string $key * @return bool */ public function doesExist($key) : bool { $cacheKey = sprintf('doesExists_%s', $key); $result = $this->cache->load($cacheKey); if ($result === null) { if (!Strings::startsWith($key, 'fakturoid.account')) { $result = false; } else { $property = $this->getLastToken($key); $result = $property !== null && property_exists($this->getAccount(), $property); } $this->cache->save($cacheKey, $result, [Cache::EXPIRE => self::CACHE_EXPIRATION]); } return $result; }
/** * Returns all VP tags in an associative array. VP tags are identified * as separate lines in the commit body that start with the "VP-" prefix. * * @return array Array of tagName => value (trimmed) */ public function getVersionPressTags() { if (!$this->tags) { $tagLines = array_filter(array_map("trim", explode("\n", $this->getBody())), function ($line) { return Strings::startsWith($line, "VP-") || Strings::startsWith($line, "X-VP-"); }); $tags = array(); foreach ($tagLines as $line) { list($key, $value) = array_map("trim", explode(":", $line, 2)); $tags[$key] = $value; } $this->tags = $tags; } return $this->tags; }
/** * Processes configuration data * * @return void */ public function loadConfiguration() { if (!$this->getConfig()) { // ignore migrations if config section not exist return; } $config = $this->getConfig($this->getDefaults()); $builder = $this->getContainerBuilder(); $connection = Strings::startsWith($config['connection'], '@') ? $config['connection'] : '@' . $config['connection']; $consoleOutput = $builder->addDefinition($this->prefix('consoleOutput'))->setClass('Doctrine\\DBAL\\Migrations\\OutputWriter')->setFactory(get_called_class() . '::createConsoleOutput')->setAutowired(FALSE); $configuration = $builder->addDefinition($this->prefix('configuration'))->setClass('Doctrine\\DBAL\\Migrations\\Configuration\\Configuration', array($connection, $consoleOutput))->addSetup('setName', array($config['name']))->addSetup('setMigrationsTableName', array($config['table']))->addSetup('setMigrationsDirectory', array($config['directory']))->addSetup('setMigrationsNamespace', array($config['namespace']))->addSetup('registerMigrationsFromDirectory', array($config['directory'])); if (isset($config['console']) && $config['console']) { $this->processConsole($configuration); } }
/** * @param string[] $filters * @return string[] * @throws InvalidStateException */ protected function prepareFilterServices(array $filters) { $builder = $this->getContainerBuilder(); foreach ($filters as &$value) { if (\Nette\Utils\Strings::startsWith($value, '@')) { $value = substr($value, 1); } else { $class = $value; $value = $this->prefix('filters.' . str_replace('\\', '.', $value)); $builder->addDefinition($value)->setClass($class); } $this->filters[] = $value; } return $filters; }
/** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $classesName = []; $entityClassNames = $this->entityManager->getConfiguration()->getMetadataDriverImpl()->getAllClassNames(); foreach ($entityClassNames as $entity) { $index = $this->entityManager->getMetadataFactory()->getMetadataFor($entity)->getName(); $data = explode('\\', $index); $index = $data[0] . $data[1] . ':' . $data[count($data) - 1]; $value = (new \ReflectionClass($this->entityManager->getMetadataFactory()->getMetadataFor($entity)->getName()))->getShortName(); if (Strings::startsWith($index, 'Necktie')) { $classesName[$index] = $value; } } $builder->add('listRulesGroup', 'collection', ['type' => new ListRulesGroupType($this->entityManager), 'allow_add' => true, 'allow_delete' => true]); $builder->add('submit', 'submit'); }
/** * Make relative url absolute * @param string image url * @param string single or double quote * @param string absolute css file path * @param string source path * @return string */ public static function absolutizeUrl($url, $quote, $cssFile, $sourcePath, $docroot, $basePath) { // is already absolute if (preg_match("/^([a-z]+:\\/)?\\//", $url)) { return $url; } // inside document root if (Strings::startsWith($cssFile, $docroot)) { $path = $basePath . substr(dirname($cssFile), strlen($docroot)) . DIRECTORY_SEPARATOR . $url; // outside document root } else { $path = $basePath . substr($sourcePath, strlen($docroot)) . DIRECTORY_SEPARATOR . $url; } //$path = self::cannonicalizePath($path); return $quote === '"' ? addslashes($path) : $path; }
/** * Maps HTTP request to a Request object. * @param Nette\Http\IRequest * @return Nette\Application\Request|NULL */ public function match(Nette\Http\IRequest $httpRequest) { if (Strings::startsWith($httpRequest->getUrl()->getPath(), '/admin')) { $router = $this->adminRouter; } else { $router = $this->frontRouter; } foreach ($router as $route) { $appRequest = $route->match($httpRequest); if ($appRequest !== NULL) { $appRequest->setPresenterName($appRequest->getPresenterName()); return $appRequest; } } return NULL; }
/** * Returns system DI container. * @return Container */ public function createContainer() { $loader = new ContainerLoader(function ($files) { return array_filter($files, function ($file) { foreach ($this->ignorePaths as $path) { if (Strings::startsWith($file, $path)) { return false; } } return true; }); }, $this->getCacheDirectory() . '/Arachne.Configurator', $this->parameters['debugMode']); $class = $loader->load(array($this->parameters, $this->files), array($this, 'generateContainer')); $container = new $class(); $container->initialize(); return $container; }
public function submitFormSet(Form $form) { $values = $form->getValues(); foreach ($values as $key => $val) { if (\Nette\Utils\Strings::startsWith($key, 'privilege_')) { $id = explode('_', $key); if ($val) { if (!$this->permissions->where('role_id = ?', $this->row['id'])->where('resource_id = ?', $this->resource['id'])->where('privilege_id = ?', $id[1])->fetch()) { $this->permissions->insert(array('role_id' => $this->row['id'], 'resource_id' => $this->resource['id'], 'privilege_id' => $id[1])); } } else { $this->permissions->where('role_id = ?', $this->row['id'])->where('resource_id = ?', $this->resource['id'])->where('privilege_id = ?', $id[1])->delete(); } } } $this->flashMessage($this->translator->translate('admin.role.privilegeSet')); $this->redirect('permission', $this->row->id); }
/** * @param TexyHandlerInvocation handler invocation * @param string * @param string * @param TexyModifier * @param TexyLink * @return TexyHtml|string|FALSE */ public function netteLink($invocation, $phrase, $content, $modifier, $link) { // is there link? if (!$link) { return $invocation->proceed(); } $url = $link->URL; if (Strings::startsWith($url, "plink://")) { $url = substr($url, 8); list($presenter, $params) = explode("?", $url, 2); $arr = array(); if ($params) { parse_str($params, $arr); } $link->URL = $this->presenter->link($presenter, $arr); } return $invocation->proceed(); }