当前位置: 首页>>代码示例>>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;未经允许,请勿转载。