コード例 #1
0
 public function testRemoveNamespace()
 {
     $this->assertEquals('test', StringTools::removeNamespaceFromClass('test'));
     $this->assertEquals('test', StringTools::removeNamespaceFromClass('\\test'));
     $this->assertEquals('test', StringTools::removeNamespaceFromClass('test\\test'));
     $this->assertEquals('test', StringTools::removeNamespaceFromClass('\\test\\test'));
     $this->assertEquals('test', StringTools::removeNamespaceFromClass('test\\test\\test'));
     $this->assertEquals('test', StringTools::removeNamespaceFromClass('\\dir1\\dir2\\test'));
     $this->assertEquals('test', StringTools::removeNamespaceFromClass('dir1\\dir2\\test'));
     $this->assertNotEquals('test', StringTools::removeNamespaceFromClass('tests'));
     $this->assertNotEquals('test', StringTools::removeNamespaceFromClass('\\tests'));
     $this->assertNotEquals('test', StringTools::removeNamespaceFromClass('test\\tests'));
     $this->assertNotEquals('test', StringTools::removeNamespaceFromClass('\\test\\tests'));
     $this->assertNotEquals('test', StringTools::removeNamespaceFromClass('test\\test\\tests'));
     $this->assertNotEquals('test', StringTools::removeNamespaceFromClass('\\dir1\\dir2\\tests'));
     $this->assertNotEquals('test', StringTools::removeNamespaceFromClass('dir1\\dir2\\tests'));
     $this->assertNotEquals('dir', StringTools::removeNamespaceFromClass('test'));
     $this->assertNotEquals('dir', StringTools::removeNamespaceFromClass('\\test'));
     $this->assertNotEquals('test\\dir', StringTools::removeNamespaceFromClass('test'));
     $this->assertNotEquals('dir\\test\\dir', StringTools::removeNamespaceFromClass('\\test'));
     $this->assertNotEquals('tests', StringTools::removeNamespaceFromClass('test'));
     $this->assertNotEquals('tests', StringTools::removeNamespaceFromClass('\\test'));
     $this->assertNotEquals('test\\tests', StringTools::removeNamespaceFromClass('test'));
     $this->assertNotEquals('dir\\test\\tests', StringTools::removeNamespaceFromClass('\\test'));
 }
コード例 #2
0
 public function toDocAnnotation($curIndentLevel = 0)
 {
     $str = '';
     $reflect = new \ReflectionClass($this);
     $publicVars = $reflect->getProperties(\ReflectionProperty::IS_PUBLIC);
     $str = '@' . StringTools::removeNamespaceFromClass(get_class($this));
     if ($this->isEmptyAnnotation($publicVars)) {
         $str .= '()';
         return $str;
     }
     $str .= '(' . PHP_EOL;
     ++$curIndentLevel;
     foreach ($publicVars as $key => $property) {
         $name = $property->getName();
         $value = $this->{$name};
         if (is_null($value)) {
             continue;
         }
         $str .= self::printIndents($curIndentLevel);
         $str .= "{$name}=";
         $str .= self::printValue($value, $curIndentLevel);
         $str .= ',' . PHP_EOL;
         // TODO: consider combining multiple into a line
     }
     // remove last comma and EOL. Can't just check for end, since NULL values
     // are skipped.
     $str = trim($str);
     if (substr($str, -1) == ',') {
         $str = substr($str, 0, strlen($str) - 1);
     }
     --$curIndentLevel;
     $str .= PHP_EOL . self::printIndents($curIndentLevel) . ')';
     return $str;
 }
コード例 #3
0
 /**
  * Generates the name of the container that represents the mappings for a
  * particular annotation type.
  * @param annotation Annotation Annotation to determine mapping of
  * @return string Name of mapping container in this class for this type of
  * Annotation
  * @throws \InvalidArgumentException
  */
 private static function generateMapping(Annotation $annotation)
 {
     $type = lcfirst(StringTools::removeNamespaceFromClass(get_class($annotation)));
     $mappingVariable = $type . 'Mapping';
     if (!isset(self::${$mappingVariable})) {
         throw new \InvalidArgumentException("Type '{$type}' is not a valid Annotation type to map to.");
     }
     return $mappingVariable;
 }
コード例 #4
0
 /**
  * @param a Annotation Annotation at fault
  * @param subject string Class or method at fault
  * @param message string Message to display
  */
 public function __construct(Annotation $a, $subject, $message)
 {
     $aType = StringTools::removeNamespaceFromClass(get_class($a));
     if ($aType == 'Endpoint') {
         $subjectType = 'class';
     } else {
         if ($aType = 'EndpointMethod') {
             $subjectType = 'method';
         } else {
             $subjectType = strtolower($aType) . ' in ';
         }
     }
     $err = "Error on {$subjectType} '{$subject}': {$message}";
     parent::__construct($err);
 }
コード例 #5
0
 private function parameterToParameterAnnotation($parameter)
 {
     if (!is_object($parameter)) {
         throw new \InvalidArgumentException('Argument must be a well-formed object of a valid parameter');
     }
     $annotation = new Parameter();
     $this->mapping->docsNamesToAnnotation($parameter, $annotation);
     if ($parameter->Type == 'enumerated') {
         $annotation->enum = array();
         foreach ($parameter->EnumeratedList as $enumName) {
             $desc = null;
             if (isset($parameter->EnumeratedDescription) && array_key_exists($enumName, $parameter->EnumeratedDescription)) {
                 $desc = $parameter->EnumeratedDescription[$enumName];
             }
             $annotation->enum[] = $this->enumToEnumAnnotation(StringTools::scalarToString($enumName), $desc);
         }
     }
     return $annotation;
 }
コード例 #6
0
 /**
  * Runs API doc generator and returns json output.
  * @param config array Configuration for the generator.
  * @param toIODocs boolean Whether to convert from iodocs to phpdocs, or
  * reverse
  * @return string JSON output of the API doc generator.
  */
 public function generate($command)
 {
     if ($command['action'] == 'iodocs') {
         $params = $command['params'];
         $apiLocation = $params['api'];
         $exclusions = isset($params['exclude']) ? $params['exclude'] : null;
         $dependencies = isset($params['dependencies']) ? $params['dependencies'] : null;
         $bootstrap = isset($params['bootstrap']) ? $params['bootstrap'] : null;
         $bootstrapArgs = isset($params['bootstrap_args']) ? (array) $params['bootstrap_args'] : null;
         $bootstrapRel = !is_null($bootstrap) ? $this->getBootstrapRelativeLocation($params) : null;
         $generator = new IODocsGenerator($apiLocation, $exclusions, $dependencies, $bootstrap, $bootstrapRel, $bootstrapArgs);
     } else {
         $generator = new PHPDocGenerator($command['params']['input']);
     }
     echo "Starting API doc generation.\n";
     $start = microtime(true);
     try {
         $result = $generator->generate();
     } catch (AnnotationException $e) {
         // format AnnotationException message for end user
         $errmsg = $e->getMessage();
         $type = StringTools::removeNamespaceFromClass(get_class($e));
         $message = "{$errmsg}\nAPI doc generation failed.";
         throw new \RuntimeException($message);
     }
     $elapsed = round(microtime(true) - $start, 2);
     echo "API doc generation completed in {$elapsed} seconds.\n";
     if (empty($result)) {
         // TODO: generator should make better message.
         throw new \RuntimeException('Generator failed');
     }
     return $result;
 }