Exemple #1
0
 /**
  * This method parses a PHP 5.3 namespace declaration.
  *
  * @return void
  * @since 0.9.5
  */
 private function _parseNamespaceDeclaration()
 {
     // Consume namespace keyword and strip optional comments
     $this->_consumeToken(self::T_NAMESPACE);
     $this->_consumeComments();
     // Lookup next token type
     $tokenType = $this->_tokenizer->peek();
     // Search for a namespace identifier
     if ($tokenType === self::T_STRING) {
         // Reset namespace property
         $this->_namespaceName = null;
         // Read qualified namespace identifier
         $qualifiedName = $this->_parseQualifiedName();
         // Consume optional comments an check for namespace scope
         $this->_consumeComments();
         if ($this->_tokenizer->peek() === self::T_CURLY_BRACE_OPEN) {
             // Consume opening curly brace
             $this->_consumeToken(self::T_CURLY_BRACE_OPEN);
         } else {
             // Consume closing semicolon token
             $this->_consumeToken(self::T_SEMICOLON);
         }
         // Create a package for this namespace
         $this->_namespaceName = $qualifiedName;
         $this->_builder->buildPackage($qualifiedName);
     } else {
         if ($tokenType === self::T_BACKSLASH) {
             // Same namespace reference, something like:
             //   new namespace\Foo();
             // or:
             //   $x = namespace\foo::bar();
             // Now parse a qualified name
             $this->_parseQualifiedNameRaw();
         } else {
             // Consume opening curly brace
             $this->_consumeToken(self::T_CURLY_BRACE_OPEN);
             // Create a package for this namespace
             $this->_namespaceName = '';
             $this->_builder->buildPackage('');
         }
     }
     $this->reset();
 }
Exemple #2
0
 /**
  * Returns the currently active package or namespace.
  *
  * @return PHP_Depend_Code_Package
  * @since 1.0.0
  */
 private function _getNamespaceOrPackage()
 {
     return $this->builder->buildPackage($this->_getNamespaceOrPackageName());
 }
Exemple #3
0
 /**
  * This method parses a function declaration.
  *
  * @return PHP_Depend_Code_Function
  * @since 0.9.5
  */
 private function _parseFunctionDeclaration()
 {
     $this->consumeComments();
     // Next token must be the function identifier
     $functionName = $this->parseFunctionName();
     $function = $this->_builder->buildFunction($functionName);
     $function->setSourceFile($this->_sourceFile);
     $function->setUUID($this->_uuidBuilder->forFunction($function));
     $this->_parseCallableDeclaration($function);
     // First check for an existing namespace
     if ($this->_namespaceName !== null) {
         $packageName = $this->_namespaceName;
     } else {
         if ($this->_packageName !== self::DEFAULT_PACKAGE) {
             $packageName = $this->_packageName;
         } else {
             $packageName = $this->_globalPackageName;
         }
     }
     $this->_builder->buildPackage($packageName)->addFunction($function);
     // Store function in source file, because we need them during the file's
     // __wakeup() phase for function declarations within another function or
     // method declaration.
     $this->_sourceFile->addChild($function);
     return $function;
 }