/**
  * Adds new policies to the provider.
  * @param array $mappedPolicies The mapped policies
  * @param Line $policiesCodeLine The found code line.
  * @param string $rawMatch
  * @return PolicyWriter
  */
 protected function addNewPoliciesToProvider(array $mappedPolicies, Line $policiesCodeLine, $rawMatch)
 {
     $file = $this->getAuthProviderFile();
     $newPolicyLines = '';
     foreach ($mappedPolicies as $model => $policy) {
         $newPolicyLines .= $model . ' => ' . $policy . ",\n";
     }
     // foreach
     $policiesCodeLine->setContent(str_replace($rawMatch, "\n" . trim($newPolicyLines, ",\n") . "\n", $policiesCodeLine));
     $file->save();
     return $this;
 }
 /**
  * Parses a single line out of the given tokens. Removes the found token for the created line from the tokens array.
  * @param array $tokens
  * @return Line|null
  */
 protected function parseLine(array &$tokens)
 {
     $content = '';
     $return = null;
     $tokenIdent = null;
     while ($token = array_shift($tokens)) {
         $isSimpleString = !is_array($token);
         if ($isSimpleString && $token === '}') {
             break;
         }
         if ($tokenIdent === null) {
             // Every line starts with a token. As long as there is no token, whitespace, etc. skip it!
             if ($isSimpleString || in_array($token[0], [T_WHITESPACE])) {
                 continue;
             }
             // if
             $tokenIdent = $token[0];
         }
         // if
         if (!$isSimpleString) {
             $token = $token[1];
         }
         // if
         // Ignore line ends.
         if (!in_array($token, [';', '}', '{'])) {
             $content .= $token;
         }
         // if
         // Change or break depth
         $isComment = in_array($tokenIdent, array(T_DOC_COMMENT, T_COMMENT), true);
         if (in_array($token, [';', '{']) || $isComment) {
             $return = new Line($content, $tokenIdent);
             // Dive into depth.
             if ($token === '{') {
                 $return->setChildLines($this->parseLines($tokens));
             }
             // if
             break;
         }
         // if
     }
     // while
     return $return;
 }
Beispiel #3
0
 /**
  * Prepends a line.
  * @param Line $line
  * @return Line The line itself.
  */
 public function prependLine(Line $line)
 {
     array_unshift($this->ChildLines, $line->setNestingLevel($this->getNestingLevel() + 1)->setParent($this));
     return $line;
 }