Ejemplo n.º 1
0
 public function getDependentServices(Tokenize $tokenize)
 {
     /**
             0000163(00027) - T_VARIABLE: '$container'
             0000164(00027) - T_OBJECT_OPERATOR: '->'
             0000165(00027) - T_STRING: 'get'
             0000166(-----) - CHARACTER: '('
             0000167(00027) - T_CONSTANT_ENCAPSED_STRING: ''annotation_reader''
             0000168(-----) - CHARACTER: ')'
              **/
     $i = 0;
     $containerGets = array();
     while ($i = $tokenize->findExactOffsetAfter($i, T_VARIABLE, '$container')) {
         if (preg_match('/(\\$[\\w]+)\\s+=\\s+\\$container->get\\(/', $tokenize->getLineAt($i), $match)) {
             $i = $tokenize->findExactOffsetAfter($i, T_STRING, 'get');
             $i = $tokenize->findAfter($i, T_CONSTANT_ENCAPSED_STRING);
             $containerGets[$tokenize->extractStringAt($i)] = $match[1];
         }
     }
     $methodsToMock = array();
     foreach ($containerGets as $serviceId => $instance) {
         $methods = array();
         $i = 0;
         while ($i = $tokenize->findExactOffsetAfter($i, T_VARIABLE, $instance)) {
             //$tokenize->dumpAround($i, 5);
             if (T_WHITESPACE == $tokenize->getTokenTypeAt($i + 1)) {
                 continue;
             }
             $i = $tokenize->findAfter($i, T_STRING);
             $methods[] = $tokenize->getStringAt($i);
         }
         $methodsToMock[$serviceId] = $methods;
     }
     return $methodsToMock;
 }
Ejemplo n.º 2
0
 private function tokenizeRequires(Tokenize $tokenize)
 {
     $dependencies = array();
     $i = 0;
     while ($i = $tokenize->findAfter($i, T_REQUIRE_ONCE)) {
         $i = $tokenize->findAfter($i, T_CONSTANT_ENCAPSED_STRING);
         if (empty($i)) {
             /**
              * Probably require_once $var, which is not important to resolve
              * at the moment
              */
             return;
         }
         $depRelpath = $tokenize->extractStringAt($i);
         if (is_file($this->libraryPath . DIRECTORY_SEPARATOR . $depRelpath)) {
             $dependencies[] = $depRelpath;
         }
     }
     return $dependencies;
 }