Exemplo n.º 1
0
 /**
  *
  * @param DocParserResponse $res
  * @param \ReflectionClass $rc
  * @return DocParserResponse
  */
 public function checkClassName($res, $rc)
 {
     $res->setValid(false);
     if ($class = $res->getClassName()) {
         if (strpos($class, '\\') !== 0) {
             $ns = $rc->getNamespaceName();
             $fullName = $ns . '\\' . $class;
             if (class_exists($fullName)) {
                 $res->setValid(true);
                 $res->setClassName($fullName);
             } else {
                 $file = $rc->getFileName();
                 $useName = $this->tokenParser->findUseStatement($file, $class);
                 if (class_exists($useName)) {
                     $res->setValid(true);
                     $res->setClassName($useName);
                 } elseif (class_exists($class)) {
                     $res->setValid(true);
                 }
             }
         } else {
             if (class_exists($class)) {
                 $res->setValid(true);
             }
         }
     }
     return $res;
 }
 /**
  * Analyzes this file.
  */
 protected function analyze_file()
 {
     // Load the contents of the file
     if (is_null($this->filecontents) || !$this->filecontents) {
         $this->filecontents = file_get_contents($this->filepath);
     }
     if (false === $this->filecontents) {
         return;
     }
     // Parse the tokens
     require_once VIP_SCANNER_DIR . '/class-token-parser.php';
     $parser = new TokenParser();
     $items = $parser->parse_contents($this->filecontents);
     // Parse the items
     $this->hierarchy_elements = array();
     $this->parse_token_results($items);
 }
Exemplo n.º 3
0
 /**
  * Tests for TokenParser behavior in the face of quoted strings with spaces.
  */
 public function testTokenParsing()
 {
     $p = new TokenParser('tag thevar|filter sometag');
     $this->assertEquals($p->tagname, 'tag');
     $this->assertEquals($p->value(), 'thevar|filter');
     $this->assertTrue($p->more());
     $this->assertEquals($p->tag(), 'sometag');
     $this->assertFalse($p->more());
     $p = new TokenParser('tag "a value"|filter sometag');
     $this->assertEquals($p->tagname, 'tag');
     $this->assertEquals($p->value(), '"a value"|filter');
     $this->assertTrue($p->more());
     $this->assertEquals($p->tag(), 'sometag');
     $this->assertFalse($p->more());
     $p = new TokenParser("tag 'a value'|filter sometag");
     $this->assertEquals($p->tagname, 'tag');
     $this->assertEquals($p->value(), "'a value'|filter");
     $this->assertTrue($p->more());
     $this->assertEquals($p->tag(), 'sometag');
     $this->assertFalse($p->more());
 }
Exemplo n.º 4
0
 private function _render($block, $language_id = FALSE)
 {
     $message = '';
     if (!is_numeric($language_id)) {
         $language_id = $this->config->get('config_language_id');
     }
     $content = $block['content'][$language_id];
     $templates = $this->config->get('html_block_theme');
     if (isset($block['theme']) && isset($templates[$block['theme_id']]) && !empty($templates[$block['theme_id']]['template'])) {
         $parser = TokenParser::getInstance($templates[$block['theme_id']]['template']);
         $tokenTitle = new Token();
         $tokenTitle->setReplace($block['title'][$language_id]);
         $parser->AddToken('[title]', $tokenTitle);
         $tokenContent = new Token();
         $tokenContent->setReplace($content);
         $parser->AddToken('[content]', $tokenContent);
         $content = $parser->replace();
     }
     $content = TokenParser::getInstance($content)->replace();
     $message = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
     if (isset($block['use_php']) && preg_match('|<\\?php.+?\\?>|isu', $message)) {
         ob_start();
         @eval('?>' . $message);
         $message = ob_get_contents();
         ob_end_clean();
     }
     return $message;
 }
Exemplo n.º 5
0
 function parse_function_call($properties = array())
 {
     $properties = array_merge(array('type' => 'function_call', 'name' => '', 'args' => array(), 'path' => $this->get_current_path_str(), 'line' => $this->line), $properties);
     $levels = array('(' => 0, '{' => 0, 'path' => array());
     $state = self::POTENTIAL_FUNCTION_CALL;
     $current_arg = '';
     for (; $this->index < $this->token_count; ++$this->index) {
         $this->get_token($token, $token_contents);
         $this->maybe_toggle_double_quoted_string($token);
         $this->parse_contents_line_breaks($token_contents);
         if (T_WHITESPACE === $token) {
             continue;
         }
         // Checks for an unexpected closing block
         if ($this->closes_block($token, $levels, true)) {
             if ($state === self::FUNCTION_CALL_ARGS) {
                 break;
             } else {
                 if (true === $this->is_inside_double_quoted_string()) {
                     break;
                 } else {
                     $this->index -= 1;
                     return;
                 }
             }
         }
         switch ($state) {
             case self::POTENTIAL_FUNCTION_CALL:
                 switch ($token) {
                     case T_VARIABLE:
                         $properties['name'] .= substr($token_contents, 1);
                         break;
                     case T_STRING:
                     case T_EVAL:
                     case T_EMPTY:
                     case T_EXIT:
                     case T_HALT_COMPILER:
                     case T_INCLUDE:
                     case T_INCLUDE_ONCE:
                     case T_REQUIRE:
                     case T_REQUIRE_ONCE:
                     case T_ISSET:
                     case T_LIST:
                     case T_PRINT:
                     case T_UNSET:
                         $properties['name'] .= $token_contents;
                         break;
                     case T_DOUBLE_COLON:
                     case T_OBJECT_OPERATOR:
                         $properties['name'] .= self::PATH_SEPERATOR;
                         break;
                     case '(':
                         $state = self::FUNCTION_CALL_ARGS;
                         break;
                     default:
                         // This doesn't look like a proper function call. Get out.
                         return;
                 }
                 break;
             case self::FUNCTION_CALL_ARGS:
                 switch ($token) {
                     case ')':
                         if (0 === $levels['(']) {
                             break 3;
                         } elseif ($levels['('] < 0) {
                             break 3;
                         }
                         $current_arg .= $token_contents;
                         break;
                     case '(':
                         $current_arg .= $token_contents;
                         break;
                     default:
                         if (0 === $levels['(']) {
                             if (is_string($token)) {
                                 break 3;
                             }
                         }
                         // Check if this is a new argument
                         if (1 === $levels['('] && ',' === $token) {
                             $properties['args'][] = $current_arg;
                             $current_arg = '';
                             break;
                         }
                         $current_arg .= $token_contents;
                 }
                 break;
         }
     }
     if (!empty($current_arg)) {
         $properties['args'][] .= $current_arg;
     }
     $parser = new TokenParser();
     foreach ($properties['args'] as $arg) {
         if (!empty($properties['path'])) {
             $parser->add_to_path($properties['path']);
         }
         $parser->line = $this->line;
         foreach ($parser->parse_contents("<?php {$arg}") as $element) {
             $this->elements[] = $element;
         }
         $this->line = $parser->line;
         $parser->reset();
     }
     return $properties;
 }