Example #1
0
 /**
  * @param string $msg
  */
 public static function log($msg)
 {
     if (!self::$_project) {
         echo "{$msg}\n";
         return;
     }
     self::$_project->log($msg);
 }
 /**
  * Build a list of files (from the fileset elements)
  * and call the phpDocumentor parser
  *
  * @return string
  */
 private function parseFiles()
 {
     $parser = $this->app['parser'];
     $builder = $this->app['descriptor.builder'];
     $builder->createProjectDescriptor();
     $projectDescriptor = $builder->getProjectDescriptor();
     $projectDescriptor->setName($this->title);
     $paths = array();
     // filesets
     foreach ($this->filesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $dir = $fs->getDir($this->project);
         $srcFiles = $ds->getIncludedFiles();
         foreach ($srcFiles as $file) {
             $paths[] = $dir . FileSystem::getFileSystem()->getSeparator() . $file;
         }
     }
     $this->project->log("Will parse " . count($paths) . " file(s)", Project::MSG_VERBOSE);
     $files = new \phpDocumentor\Fileset\Collection();
     $files->addFiles($paths);
     $mapper = new \phpDocumentor\Descriptor\Cache\ProjectDescriptorMapper($this->app['descriptor.cache']);
     $mapper->garbageCollect($files);
     $mapper->populate($projectDescriptor);
     $parser->setPath($files->getProjectRoot());
     $parser->setDefaultPackageName($this->defaultPackageName);
     $parser->parse($builder, $files);
     $mapper->save($projectDescriptor);
     return $mapper;
 }
 /**
  * Runs phpDocumentor 2 
  */
 public function run()
 {
     $this->initializePhpDocumentor();
     $cache = $this->app['descriptor.cache'];
     $cache->getOptions()->setCacheDir($this->destDir->getAbsolutePath());
     $this->parseFiles();
     $this->project->log("Transforming...", Project::MSG_VERBOSE);
     $this->transformFiles();
 }
 /**
  * Runs phpDocumentor 2 
  */
 public function run()
 {
     $this->initializePhpDocumentor();
     $xml = $this->parseFiles();
     $this->project->log("Transforming...", Project::MSG_VERBOSE);
     $transformer = new phpDocumentor\Transformer\Transformer();
     $transformer->setTemplatesPath($this->phpDocumentorPath . '/../data/templates');
     $transformer->setTemplates($this->template);
     $transformer->setSource($xml);
     $transformer->setTarget($this->destDir->getAbsolutePath());
     $transformer->execute();
 }
Example #5
0
 /**
  * The entry point for this class. Does some checking, then processes and
  * performs the tasks for this target.
  */
 public function main()
 {
     if ($this->testIfCondition() && $this->testUnlessCondition()) {
         foreach ($this->children as $o) {
             if ($o instanceof Task) {
                 // child is a task
                 $o->perform();
             } else {
                 // child is a RuntimeConfigurable
                 $o->maybeConfigure($this->project);
             }
         }
     } elseif (!$this->testIfCondition()) {
         $this->project->log("Skipped target '" . $this->name . "' because property '" . $this->ifCondition . "' not set.", Project::MSG_VERBOSE);
     } else {
         $this->project->log("Skipped target '" . $this->name . "' because property '" . $this->unlessCondition . "' set.", Project::MSG_VERBOSE);
     }
 }
 /**
  *
  * @throws BuildException
  * @return array
  */
 public function parse()
 {
     $this->properties = array();
     $contents = @file_get_contents($this->file);
     if ($contents === false) {
         $message = sprintf('Could not read file [%s].', $this->file);
         throw new BuildException($message);
     }
     $lines = explode("\n", $contents);
     $count = count($lines);
     $isMultiLine = false;
     for ($i = 0; $i < $count; $i++) {
         $line = $lines[$i];
         if ($isMultiLine) {
             $isMultiLine = $this->extractContinuedValue($line);
         } else {
             $this->name = null;
             $this->value = '';
             $isMultiLine = $this->extractNameAndValue($line);
         }
         if ($this->name !== null && !$isMultiLine) {
             if (array_key_exists($this->name, $this->properties)) {
                 $message = sprintf('Property [%s] overwritten: old value [%s], new value [%s].', $this->name, $this->properties[$this->name], $this->value);
                 $this->project->log($message, Project::MSG_WARN);
             }
             // Unescape backslashes.
             $this->value = str_replace('\\\\', '\\', $this->value);
             $this->properties[$this->name] = $this->value;
         }
     }
     if ($isMultiLine) {
         $message = sprintf('Last property looks like a multi-lined value, but end of file found. Name = [%s].', $this->name);
         throw new BuildException($message);
     }
     return $this->properties;
 }
Example #7
0
 /**
  * Creates a named nested element. 
  * 
  * Valid creators can be in the form createFoo() or addFoo(Bar).
  * @return object Returns the nested element.
  * @throws BuildException
  */
 function createElement(Project $project, $element, $elementName)
 {
     $addMethod = "add" . strtolower($elementName);
     $createMethod = "create" . strtolower($elementName);
     $nestedElement = null;
     if (isset($this->nestedCreators[$createMethod])) {
         $method = $this->nestedCreators[$createMethod];
         try {
             // try to invoke the creator method on object
             $project->log("    -calling creator " . $method->getDeclaringClass()->getName() . "::" . $method->getName() . "()", PROJECT_MSG_DEBUG);
             $nestedElement = $method->invoke($element);
         } catch (Exception $exc) {
             throw new BuildException($exc);
         }
     } elseif (isset($this->nestedCreators[$addMethod])) {
         $method = $this->nestedCreators[$addMethod];
         // project components must use class hints to support the add methods
         try {
             // try to invoke the adder method on object
             $project->log("    -calling adder " . $method->getDeclaringClass()->getName() . "::" . $method->getName() . "()", PROJECT_MSG_DEBUG);
             // we've already assured that correct num of params
             // exist and that method is using class hints
             $params = $method->getParameters();
             $classname = null;
             if (($hint = $params[0]->getClass()) !== null) {
                 $classname = $hint->getName();
             }
             // create a new instance of the object and add it via $addMethod
             $nestedElement = new $classname();
             $method->invoke($element, $nestedElement);
         } catch (Exception $exc) {
             throw new BuildException($exc);
         }
     } else {
         $msg = $this->getElementName($project, $element) . " doesn't support the '{$elementName}' creator/adder.";
         throw new BuildException($msg);
     }
     if ($nestedElement instanceof ProjectComponent) {
         $nestedElement->setProject($project);
     }
     return $nestedElement;
 }
Example #8
0
 /**
  * Utility function for logging
  */
 function log($level, $msg)
 {
     $this->project->log($level, $msg);
 }
 /**
  * Creates a named nested element.
  *
  * @param  Project        $project
  * @param  string         $element
  * @param  string         $child
  * @param  string|null    $elementName
  * @return void
  * @throws BuildException
  */
 public function storeElement($project, $element, $child, $elementName = null)
 {
     if ($elementName === null) {
         return;
     }
     $storer = "addconfigured" . strtolower($elementName);
     if (isset($this->nestedStorers[$storer])) {
         $method = $this->nestedStorers[$storer];
         try {
             $project->log("    -calling storer " . $method->getDeclaringClass()->getName() . "::" . $method->getName() . "()", Project::MSG_DEBUG);
             $method->invoke($element, $child);
         } catch (Exception $exc) {
             throw new BuildException($exc);
         }
     }
 }
 /**
  * Logs a message with the given priority.
  *
  * @param string  $msg   The message to be logged.
  * @param integer $level The message's priority at this message should have
  *
  * @return void
  */
 public function log($msg, $level = Project::MSG_INFO)
 {
     if ($this->project !== null) {
         $this->project->log($msg, $level);
     }
 }