当前位置: 首页>>代码示例>>PHP>>正文


PHP SplStack::offsetGet方法代码示例

本文整理汇总了PHP中SplStack::offsetGet方法的典型用法代码示例。如果您正苦于以下问题:PHP SplStack::offsetGet方法的具体用法?PHP SplStack::offsetGet怎么用?PHP SplStack::offsetGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplStack的用法示例。


在下文中一共展示了SplStack::offsetGet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: offsetGet

 /**
  * @param int $index
  *
  * @return ResourceInterface
  */
 public function offsetGet($index)
 {
     return $this->transform(parent::offsetGet($index));
 }
开发者ID:treehouselabs,项目名称:feeder,代码行数:9,代码来源:ResourceCollection.php

示例2: _handleRepetition

 /**
  * Handles a repetition token
  * 
  * @param Token $token Token
  * 
  * @return void
  */
 protected function _handleRepetition(Token $token)
 {
     //If there is no current item, throw exception
     if ($this->_currentItem === null) {
         throw new Exception\InvalidRepetition("Nothing to repeat");
     }
     //Repetitions are allowed only after certain tokens, so check the last
     //emitted token
     $lastToken = $this->_tokensStack->top();
     switch ($lastToken->getType()) {
         //Handle lazy repetition
         case Token::TYPE_REPETITION:
             $prevLastToken = $this->_tokensStack->offsetGet(1);
             //if this token is "?" and follows a repetition token that
             //does not come after another repetition token set the lazy flag
             if ($token->getIdentifier() === "?" && $prevLastToken->getType() !== Token::TYPE_REPETITION) {
                 //Check if last repetition supports the lazy flag
                 $lastRepetition = $this->_currentItem->getRepetition();
                 if ($lastRepetition->supportsLazy()) {
                     $lastRepetition->setLazy(true);
                 }
                 return;
             } else {
                 throw new Exception\InvalidRepetition("Nothing to repeat");
             }
             break;
             //Tokens that can handle the repetition
         //Tokens that can handle the repetition
         case Token::TYPE_NON_PRINTING_CHAR:
         case Token::TYPE_GENERIC_CHAR_TYPE:
         case Token::TYPE_CONTROL_CHAR:
         case Token::TYPE_EXT_UNICODE_SEQUENCE:
         case Token::TYPE_UNICODE_CHAR_CLASS:
         case Token::TYPE_HEX_CHAR:
         case Token::TYPE_DOT:
         case Token::TYPE_BYTE:
         case Token::TYPE_SUBPATTERN_END:
         case Token::TYPE_COMMENT:
         case Token::TYPE_OCTAL_CHAR:
         case Token::TYPE_BACK_REFERENCE:
         case Token::TYPE_CHAR_CLASS_END:
         case Token::TYPE_RECURSIVE_PATTERN:
             break;
             //When simple characters are grouped, repetition is valid only
             //for the last one, so it needs to be splitted so that the last
             //character belongs to a different object
         //When simple characters are grouped, repetition is valid only
         //for the last one, so it needs to be splitted so that the last
         //character belongs to a different object
         case Token::TYPE_CHAR:
             $chars = $this->_currentItem->getChar();
             if (strlen($chars) > 1) {
                 $this->_currentItem->setChar(substr($chars, 0, -1));
                 $this->_currentItem = new Pattern\Char($chars[strlen($chars) - 1]);
                 $this->_containersStack->top()->addChild($this->_currentItem);
             }
             break;
         default:
             throw new Exception\InvalidRepetition("Repetition cannot be inserted at this point");
             break;
     }
     //Get the right repetition class
     switch ($token->getIdentifier()) {
         case "*":
             $repetition = new Pattern\Repetition\ZeroOrMore();
             break;
         case "+":
             $repetition = new Pattern\Repetition\OneOrMore();
             break;
         case "?":
             $repetition = new Pattern\Repetition\Optional();
             break;
         case "{":
             //Check if {}
             if (strpos($token->getSubject(), ",") === false) {
                 $repetition = new Pattern\Repetition\Number($token->getSubject());
             } else {
                 $limits = explode(",", $token->getSubject());
                 $repetition = new Pattern\Repetition\Range($limits[0], $limits[1] === "" ? null : $limits[1]);
             }
             break;
     }
     //Set the repetition on the current item
     $this->_currentItem->setRepetition($repetition);
 }
开发者ID:mck89,项目名称:rebuilder,代码行数:92,代码来源:Builder.php


注:本文中的SplStack::offsetGet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。