コード例 #1
0
 /**
  * Will look for a logically balanced connector pointcut of a certain type
  *
  * @param string $expression String to be analysed for potential connector pointcut use
  * @param string $class      Type of connector pointcut to look for
  *
  * @return boolean|\AppserverIo\Doppelgaenger\Interfaces\PointcutInterface
  */
 protected function findConnectorPointcut($expression, $class)
 {
     // break up the string at the defined connectors and check for the bracket count on each side.
     // an even bracket count on both sides means we found the outermost connection
     $connector = constant($class . '::CONNECTOR');
     if (strpos($expression, $connector) !== false) {
         $connectorCount = substr_count($expression, $connector);
         $connectionIndex = 0;
         // get a parsing helper and analyze bracket counts to determine where we are at
         $parserUtil = new Parser();
         for ($i = 0; $i < $connectorCount; $i++) {
             $connectionIndex = strpos($expression, $connector, $connectionIndex + 1);
             $leftCandidate = substr($expression, 0, $connectionIndex);
             $rightCandidate = str_replace($leftCandidate . $connector, '', $expression);
             $leftBrackets = $parserUtil->getBracketCount($leftCandidate, '(');
             if ($leftBrackets === 0 && !empty($leftCandidate)) {
                 if ($parserUtil->getBracketCount($rightCandidate, '(') === 0 && !empty($rightCandidate)) {
                     return new $class($leftCandidate, $rightCandidate);
                 }
             }
         }
     }
     // if we arrived here we did not find anything
     return false;
 }
コード例 #2
0
 /**
  * Will return a list of parameter definition objects extracted from a given token array
  *
  * @param array $tokens The token array
  *
  * @return \AppserverIo\Doppelgaenger\Entities\Lists\ParameterDefinitionList
  *
  * TODO Does this have to be this long?
  */
 public function getParameterDefinitionList(array $tokens)
 {
     // Check the tokens
     $parameterString = '';
     $parameterDefinitionList = new ParameterDefinitionList();
     $tokenCount = count($tokens);
     for ($i = 0; $i < $tokenCount; $i++) {
         // If we got the function definition, no scan everything from the first ( to the next )
         if ($tokens[$i][0] === T_FUNCTION) {
             $bracketPassed = null;
             for ($j = $i; $j < $tokenCount; $j++) {
                 // If we got the function definition, no scan everything from the first ( to the closing )
                 if ($tokens[$j] === '(') {
                     if ($bracketPassed === null) {
                         $bracketPassed = 1;
                         // We do not want to get this token as well.
                         continue;
                     } else {
                         $bracketPassed++;
                     }
                 }
                 // We got A closing bracket, decrease the counter
                 if ($tokens[$j] === ')') {
                     $bracketPassed--;
                 }
                 if ($bracketPassed > 0 && $bracketPassed !== null) {
                     // Collect what we get
                     if (is_array($tokens[$j])) {
                         $parameterString .= $tokens[$j][1];
                     } else {
                         $parameterString .= $tokens[$j];
                     }
                 } elseif ($bracketPassed !== null) {
                     // If we got the closing bracket we can leave both loops
                     break 2;
                 }
             }
         }
     }
     // Now lets analyse what we got
     $parameterStrings = explode(',', $parameterString);
     $parserUtils = new Parser();
     foreach ($parameterStrings as $key => $param) {
         if ($parserUtils->getBracketCount($param, '(') > 0) {
             $param = $param . ', ' . $parameterStrings[$key + 1];
             unset($parameterStrings[$key + 1]);
         }
         $param = trim($param);
         $paramPieces = explode('$', $param);
         // Get a new ParameterDefinition
         $parameterDefinition = new ParameterDefinition();
         // we either get one or two pieces
         if (count($paramPieces) === 1) {
             continue;
         } elseif (count($paramPieces) === 2) {
             $parameterDefinition->type = trim($paramPieces[0]);
             // We might have an overload going on
             $nameArray = explode('=', $paramPieces[1]);
             $parameterDefinition->name = '$' . trim($nameArray[0]);
             // check if we got a default value for overloading
             if (isset($nameArray[1])) {
                 unset($nameArray[0]);
                 $parameterDefinition->defaultValue = trim(implode('=', $nameArray));
             }
         }
         // Add the definition to the list
         $parameterDefinitionList->add($parameterDefinition);
     }
     return $parameterDefinitionList;
 }