當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Strings::match方法代碼示例

本文整理匯總了PHP中Nette\Utils\Strings::match方法的典型用法代碼示例。如果您正苦於以下問題:PHP Strings::match方法的具體用法?PHP Strings::match怎麽用?PHP Strings::match使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Nette\Utils\Strings的用法示例。


在下文中一共展示了Strings::match方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: tryCall

 /**
  * Calls public method if exists.
  * @param string $method
  * @param array $params
  * @throws \Nette\Application\BadRequestException
  * @return bool  does method exist?
  */
 protected function tryCall($method, array $params)
 {
     $rc = $this->getReflection();
     if ($rc->hasMethod($method)) {
         $rm = $rc->getMethod($method);
         if ($rm->isPublic() && !$rm->isAbstract() && !$rm->isStatic()) {
             $this->checkRequirements($rm);
             $args = $rc->combineArgs($rm, $params);
             if (\Nette\Utils\Strings::match($method, "~^(action|render|handle).+~")) {
                 $methodParams = $rm->getParameters();
                 foreach ($methodParams as $i => $param) {
                     /** @var \Nette\Reflection\Parameter $param */
                     if ($className = $param->getClassName()) {
                         if ($paramValue = $args[$i]) {
                             $entity = $this->findById($className, $paramValue);
                             if ($entity) {
                                 $args[$i] = $entity;
                             } else {
                                 throw new \Nette\Application\BadRequestException("Value '{$paramValue}' not found in collection '{$className}'.");
                             }
                         } else {
                             if (!$param->allowsNull()) {
                                 throw new \Nette\Application\BadRequestException("Value '{$param}' cannot be NULL.");
                             }
                         }
                     }
                 }
             }
             $rm->invokeArgs($this, $args);
             return TRUE;
         }
     }
     return FALSE;
 }
開發者ID:frosty22,項目名稱:ale,代碼行數:41,代碼來源:Presenter.php

示例2: charsetFromContentType

 /**
  * @param string $contentType
  * @return string
  */
 public static function charsetFromContentType($contentType)
 {
     if ($m = Strings::match($contentType, static::CONTENT_TYPE)) {
         return $m['charset'];
     }
     return NULL;
 }
開發者ID:noikiy,項目名稱:Curl,代碼行數:11,代碼來源:HtmlResponse.php

示例3: getPresenterClass

 /**
  * Generates and checks presenter class name.
  * @param  string  presenter name
  * @return string  class name
  * @throws InvalidPresenterException
  */
 public function getPresenterClass(&$name)
 {
     if (isset($this->cache[$name])) {
         return $this->cache[$name];
     }
     if (!is_string($name) || !Nette\Utils\Strings::match($name, '#^[a-zA-Z\\x7f-\\xff][a-zA-Z0-9\\x7f-\\xff:]*\\z#')) {
         throw new InvalidPresenterException("Presenter name must be alphanumeric string, '{$name}' is invalid.");
     }
     $class = $this->formatPresenterClass($name);
     if (!class_exists($class)) {
         throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' was not found.");
     }
     $reflection = new \ReflectionClass($class);
     $class = $reflection->getName();
     if (!$reflection->implementsInterface('Nette\\Application\\IPresenter')) {
         throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is not Nette\\Application\\IPresenter implementor.");
     } elseif ($reflection->isAbstract()) {
         throw new InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is abstract.");
     }
     $this->cache[$name] = $class;
     if ($name !== ($realName = $this->unformatPresenterClass($class))) {
         trigger_error("Case mismatch on presenter name '{$name}', correct name is '{$realName}'.", E_USER_WARNING);
         $name = $realName;
     }
     return $class;
 }
開發者ID:jave007,項目名稱:test,代碼行數:32,代碼來源:PresenterFactory.php

示例4: getGitInfo

 /**
  * Returns Git info
  *
  * @return array
  */
 public static function getGitInfo()
 {
     $gitBinary = VP_GIT_BINARY;
     $info = [];
     $process = new Process(ProcessUtils::escapeshellarg($gitBinary) . " --version");
     $process->run();
     $info['git-binary-as-configured'] = $gitBinary;
     $info['git-available'] = $process->getErrorOutput() === null || !strlen($process->getErrorOutput());
     if ($info['git-available'] === false) {
         $info['output'] = ['stdout' => trim($process->getOutput()), 'stderr' => trim($process->getErrorOutput())];
         $info['env-path'] = getenv('PATH');
         return $info;
     }
     $output = trim($process->getOutput());
     $match = Strings::match($output, "~git version (\\d[\\d\\.]+\\d).*~");
     $version = $match[1];
     $gitPath = "unknown";
     if ($gitBinary == "git") {
         $osSpecificWhereCommand = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? "where" : "which";
         $process = new Process("{$osSpecificWhereCommand} git");
         $process->run();
         if ($process->isSuccessful()) {
             $gitPath = $process->getOutput();
         }
     } else {
         $gitPath = $gitBinary;
     }
     $info['git-version'] = $version;
     $info['git-binary-as-called-by-vp'] = $gitBinary;
     $info['git-full-path'] = $gitPath;
     $info['versionpress-min-required-version'] = RequirementsChecker::GIT_MINIMUM_REQUIRED_VERSION;
     $info['matches-min-required-version'] = RequirementsChecker::gitMatchesMinimumRequiredVersion($version);
     return $info;
 }
開發者ID:versionpress,項目名稱:versionpress,代碼行數:39,代碼來源:SystemInfo.php

示例5: getIndexData

 /**
  * Values to be saved to es index
  *
  * @return FALSE|array [field => data]
  */
 public function getIndexData()
 {
     if ($this->hidden) {
         return FALSE;
     }
     $blockCount = 0;
     $schemaCount = 0;
     $positions = [];
     foreach ($this->blocks as $block) {
         $blockCount++;
         $schemaCount += $block->blockSchemaBridges->count();
         $positions[] = $block->getPositionOf($this);
     }
     if ($blockCount) {
         $avgPosition = array_sum($positions) / count($positions);
     } else {
         // title heuristics
         $number = Strings::match($this->title, '~\\s(\\d\\d?)(?!\\.)\\D*$~');
         $avgPosition = $number ? $number[1] : 0;
         if ($avgPosition > 20) {
             // most probably not number of part
             $avgPosition = 0;
         }
     }
     return ['title' => $this->title, 'suggest' => $this->title, 'bucket' => $this->type, 'description' => $this->description, 'block_count' => $blockCount, 'schema_count' => $schemaCount, 'position' => $avgPosition];
 }
開發者ID:VasekPurchart,項目名稱:khanovaskola-v3,代碼行數:31,代碼來源:Content.php

示例6: getVersion

 public final function getVersion()
 {
     if (($version = Strings::match(get_class($this), '#\\d{10}#')) === null) {
         throw new InvalidStateException('Invalid migration class name - it does not contains timestamp');
     }
     return (int) $version[0];
 }
開發者ID:joseki,項目名稱:migration,代碼行數:7,代碼來源:AbstractMigration.php

示例7: macroControl

 /**
  * {control name[:method] [params]}
  */
 public function macroControl(MacroNode $node, PhpWriter $writer)
 {
     $words = $node->tokenizer->fetchWords();
     if (!$words) {
         throw new CompileException('Missing control name in {control}');
     }
     $name = $writer->formatWord($words[0]);
     $method = isset($words[1]) ? ucfirst($words[1]) : '';
     $method = Strings::match($method, '#^\\w*\\z#') ? "render{$method}" : "{\"render{$method}\"}";
     $tokens = $node->tokenizer;
     $pos = $tokens->position;
     $param = $writer->formatArray();
     $tokens->position = $pos;
     while ($tokens->nextToken()) {
         if ($tokens->isCurrent('=>') && !$tokens->depth) {
             $wrap = TRUE;
             break;
         }
     }
     if (empty($wrap)) {
         $param = substr($param, 1, -1);
         // removes array() or []
     }
     return "/* line {$node->startLine} */ " . ($name[0] === '$' ? "if (is_object({$name})) \$_tmp = {$name}; else " : '') . '$_tmp = $this->global->uiControl->getComponent(' . $name . '); ' . 'if ($_tmp instanceof Nette\\Application\\UI\\IRenderable) $_tmp->redrawControl(NULL, FALSE); ' . ($node->modifiers === '' ? "\$_tmp->{$method}({$param});" : $writer->write("ob_start(function () {}); \$_tmp->{$method}({$param}); echo %modify(ob_get_clean());"));
 }
開發者ID:hrach,項目名稱:nette-application,代碼行數:28,代碼來源:UIMacros.php

示例8: macroElement

 /**
  * {element name[:method] [key]}
  */
 public function macroElement(MacroNode $node, PhpWriter $writer)
 {
     $rawName = $node->tokenizer->fetchWord();
     if ($rawName === FALSE) {
         throw new CompileException("Missing element type in {element}");
     }
     $rawName = explode(':', $rawName, 2);
     $name = $writer->formatWord($rawName[0]);
     $method = isset($rawName[1]) ? ucfirst($rawName[1]) : '';
     $method = Strings::match($method, '#^\\w*$#') ? "render{$method}" : "{\"render{$method}\"}";
     $idRaw = $node->tokenizer->fetchWord();
     $param = $writer->formatArray();
     if (!Strings::contains($node->args, '=>')) {
         $param = substr($param, 6, -1);
         // removes array()
     }
     if (!$idRaw) {
         throw new CompileException("Missing element title in {element}");
     }
     if (substr($idRaw, 0, 1) !== '$') {
         $id = Helpers::encodeName($idRaw);
     } else {
         $id = $idRaw;
     }
     return '$_ctrl = $_presenter->getComponent(\\CmsModule\\Content\\ElementManager::ELEMENT_PREFIX . ' . '"' . $id . '"' . ' . \'_\' . ' . $name . '); ' . '$_ctrl->setName("' . trim($idRaw, '"\'') . '");' . 'if ($presenter->isPanelOpened() && (!isset($__element) || !$__element)) { echo "<span id=\\"' . \CmsModule\Content\ElementManager::ELEMENT_PREFIX . (substr($id, 0, 1) === '$' ? '{' . $id . '}' : $id) . '_' . $rawName[0] . '\\" style=\\"display: inline-block; min-width: 50px; min-height: 25px;\\" class=\\"venne-element-container\\" data-venne-element-id=\\"' . trim($id, '"\'') . '\\" data-venne-element-name=\\"' . $rawName[0] . '\\" data-venne-element-route=\\"" . $presenter->route->id . "\\" data-venne-element-language=\\"" . $presenter->language->id . "\\" data-venne-element-buttons=\\"" . (str_replace(\'"\', "\'", json_encode($_ctrl->getViews()))) . "\\">"; }' . 'if ($_ctrl instanceof Nette\\Application\\UI\\IRenderable) $_ctrl->validateControl(); ' . "\$_ctrl->{$method}({$param});" . 'if ($presenter->isPanelOpened()) { echo "</span>"; }';
 }
開發者ID:svobodni,項目名稱:web,代碼行數:29,代碼來源:ElementMacro.php

示例9: createFromDuplicateEntryException

 /**
  * @param \Doctrine\DBAL\Exception\UniqueConstraintViolationException $e
  * @param \Kdyby\Doctrine\EntityDao $dao
  * @param \Carrooi\Doctrine\Entities\BaseEntity $entity
  * @return static
  */
 public static function createFromDuplicateEntryException(UniqueConstraintViolationException $e, EntityDao $dao, BaseEntity $entity)
 {
     $match = Strings::match($e->getMessage(), '/DETAIL:\\s+Key\\s\\(([a-z_]+)\\)/');
     $column = $dao->getClassMetadata()->getColumnName($match[1]);
     $value = $dao->getClassMetadata()->getFieldValue($entity, $match[1]);
     return new static($e, $entity, $column, $value);
 }
開發者ID:carrooi,項目名稱:doctrine,代碼行數:13,代碼來源:exceptions.php

示例10: convertFrom

 public function convertFrom(&$data)
 {
     if ($data instanceof \DateTime) {
         $this->entity->data->{$this->fieldName} = $data->format('Y-m-d H:i:s');
         $this->setTimestamp($data->getTimestamp());
         // @ - Bug #45543 - https://bugs.php.net/bug.php?id=45543
         if ($data->getTimezone() !== false) {
             @$this->setTimezone($data->getTimezone());
         }
         return;
     } elseif (is_int($data) || intval($data) == $data) {
         $this->setTimestamp(intval($data));
         $this->entity->data->{$this->fieldName} = $this->format('Y-m-d H:i:s');
         return;
     } elseif (is_string($data)) {
         if (($matches = Strings::match($data, '#^[0-4]{4}-[0-9]{2}-[0-9]{2}$#')) !== false) {
             $this->setTimestamp(strtotime($data));
             $this->entity->data->{$this->fieldName} = $this->format('Y-m-d H:i:s');
         } else {
             throw new Nette\InvalidArgumentException("Unsupported string format " . var_export($data, true) . " for " . get_called_class());
         }
         return;
     }
     throw new Nette\InvalidArgumentException("'" . gettype($data) . "' is not supported by " . get_called_class());
 }
開發者ID:vbuilder,項目名稱:framework,代碼行數:25,代碼來源:DateTime.php

示例11: getPresenterClass

 /**
  * Generates and checks presenter class name.
  *
  * @param  string presenter name
  * @return string  class name
  * @throws Application\InvalidPresenterException
  */
 public function getPresenterClass(&$name)
 {
     if (isset($this->cache[$name])) {
         return $this->cache[$name];
     }
     if (!is_string($name) || !Nette\Utils\Strings::match($name, '#^[a-zA-Z\\x7f-\\xff][a-zA-Z0-9\\x7f-\\xff:]*\\z#')) {
         throw new Application\InvalidPresenterException("Presenter name must be alphanumeric string, '{$name}' is invalid.");
     }
     $classes = $this->formatPresenterClasses($name);
     if (!$classes) {
         throw new Application\InvalidPresenterException("Cannot load presenter '{$name}', no applicable mapping found.");
     }
     $class = $this->findValidClass($classes);
     if (!$class) {
         throw new Application\InvalidPresenterException("Cannot load presenter '{$name}', none of following classes were found: " . implode(', ', $classes));
     }
     $reflection = new Nette\Reflection\ClassType($class);
     $class = $reflection->getName();
     if (!$reflection->implementsInterface('Nette\\Application\\IPresenter')) {
         throw new Application\InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is not Nette\\Application\\IPresenter implementor.");
     }
     if ($reflection->isAbstract()) {
         throw new Application\InvalidPresenterException("Cannot load presenter '{$name}', class '{$class}' is abstract.");
     }
     return $this->cache[$name] = $class;
 }
開發者ID:librette,項目名稱:presenter-factory,代碼行數:33,代碼來源:PresenterFactory.php

示例12: __construct

 public function __construct(Nette\Loaders\RobotLoader $robotLoader)
 {
     $classes = $robotLoader->getIndexedClasses();
     foreach ($classes as $class => $file) {
         if (class_exists($class)) {
             $reflection = new \Nette\Reflection\ClassType($class);
             if ($reflection->implementsInterface('Tatami\\Modules\\IModule')) {
                 if (!($reflection->isAbstract() or $reflection->isInterface())) {
                     $this->modules[] = $this->parseModuleName($reflection->getShortName());
                 }
             }
             if ($reflection->isSubclassOf('Tatami\\Presenters\\BackendPresenter')) {
                 $moduleName = $this->parseModuleName($reflection->getNamespaceName());
                 $presenterName = $this->parsePresenterName($reflection->getShortName());
                 $this->presenters[$moduleName][] = $presenterName;
                 $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
                 foreach ($methods as $method) {
                     if (Strings::match($method->name, '/action/') or Strings::match($method->name, '/render/')) {
                         $this->actions[$presenterName][] = $this->parseActionName($method->name);
                     }
                 }
             }
             unset($reflection);
         }
     }
 }
開發者ID:bazo,項目名稱:Tatami,代碼行數:26,代碼來源:ShortcutsManager.php

示例13: matches

 public function matches($urlPath)
 {
     if (!($matches = Strings::match($urlPath, $this->re))) {
         // stop, not matched
         return NULL;
     }
     // deletes numeric keys, restore '-' chars
     $params = array();
     foreach ($matches as $k => $v) {
         if (is_string($k) && $v !== '') {
             $params[str_replace('___', '-', $k)] = $v;
             // trick
         }
     }
     // 4) APPLY FILTERS & FIXITY
     foreach ($this->metadata as $name => $meta) {
         if (isset($params[$name])) {
             if (!is_scalar($params[$name])) {
             } elseif (isset($meta[self::FILTER_IN])) {
                 // applies filterIn only to scalar parameters
                 $params[$name] = call_user_func($meta[self::FILTER_IN], (string) $params[$name]);
             }
         }
     }
     if (isset($this->metadata[NULL][self::FILTER_IN])) {
         $params = call_user_func($this->metadata[NULL][self::FILTER_IN], $params);
         if ($params === NULL) {
             return NULL;
         }
     }
     return $params;
 }
開發者ID:vbuilder,項目名稱:framework,代碼行數:32,代碼來源:ResourceUrlMatcher.php

示例14: addError

 /**
  * @param string $message
  * @param array $args
  */
 public function addError($message, $args = array())
 {
     // Hack for translator - and key string like "foo.bar"
     if ($this->translator && \Nette\Utils\Strings::match($message, '~^[a-z\\.]+$~i')) {
         $message = $this->translator->translate($message, NULL, $args);
     }
     parent::addError($message);
 }
開發者ID:frosty22,項目名稱:ale,代碼行數:12,代碼來源:Form.php

示例15: parse

 /**
  * Convert client request data to array or traversable
  * @param string $data
  * @return Media
  *
  * @throws MappingException
  */
 public function parse($data)
 {
     $matches = Strings::match($data, "@^data:([\\w/]+?);(\\w+?),(.*)\$@si");
     if (!$matches) {
         throw new MappingException('Given data URL is invalid.');
     }
     return new Media(base64_decode($matches[3]), $matches[1]);
 }
開發者ID:lucien144,項目名稱:Restful,代碼行數:15,代碼來源:DataUrlMapper.php


注:本文中的Nette\Utils\Strings::match方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。