예제 #1
0
 /**
  * Check Options Integrity
  *
  * @throws Next\Tools\ClassMapper\ClassMapperException
  *   Output directory is not set
  *
  * @throws Next\Tools\ClassMapper\ClassMapperException
  *   Output directory doesn't exist or it's not a valid directory
  *
  * @throws Next\Tools\ClassMapper\ClassMapperException
  *   Output directory is not writable
  *
  * @throws Next\Tools\ClassMapper\ClassMapperException
  *   Filename is missing
  */
 protected function checkIntegrity()
 {
     // If we want to save the File...
     if ($this->options->save !== FALSE) {
         // ... an Output Directory must be set...
         if (empty($this->options->outputDirectory)) {
             throw ClassMapperException::noOutputDirectory();
         }
         // ... must exist
         if (!is_dir($this->options->outputDirectory)) {
             throw ClassMapperException::invalidOutputDirectory($this->options->outputDirectory);
         }
         // ... and must be writable
         if (!is_writable($this->options->outputDirectory)) {
             throw ClassMapperException::unwritableOutputDirectory($this->options->outputDirectory);
         }
         // ... and a filename must be set too
         if (empty($this->options->filename)) {
             throw ClassMapperException::missingOutputFilename();
         }
     }
 }
예제 #2
0
파일: XML.php 프로젝트: nextframework/next
 /**
  * Checks Options Integrity
  *
  * @throws Next\Tools\ClassMapper\ClassMapperException
  *   Output directory is not set
  *
  * @throws Next\Tools\ClassMapper\ClassMapperException
  *   Output directory doesn't exist or it's not a valid directory
  *
  * @throws Next\Tools\ClassMapper\ClassMapperException
  *   Output directory is not writable
  *
  * @throws Next\Tools\ClassMapper\ClassMapperException
  *   Filename is missing
  */
 protected function checkIntegrity()
 {
     // If the root node name was overwritten with an empty string...
     if (empty($this->options->rootNode)) {
         throw new ClassMapperException('You must enter the the Top Level Node Name of XML File!');
     }
     // If we want to save the File...
     if ($this->options->save) {
         // ... an Output Directory must be set...
         if (empty($this->options->outputDirectory)) {
             throw ClassMapperException::noOutputDirectory();
         }
         // ... must exist
         if (!is_dir($this->options->outputDirectory)) {
             throw ClassMapperException::invalidOutputDirectory($this->options->outputDirectory);
         }
         // ... and must be writable
         if (!is_writable($this->options->outputDirectory)) {
             throw ClassMapperException::unwritableOutputDirectory($this->options->outputDirectory);
         }
         if ($this->options->save) {
             if (empty($this->options->filename)) {
                 throw ClassMapperException::missingOutputFilename();
             }
         }
     }
 }
예제 #3
0
 /**
  * Build the Class Map
  *
  * @param string $format
  *   Output Format from Available Formats
  *
  * @param mixed|optional $options
  *   List of Options to affect Database Drivers. Acceptable values are:
  *
  *   <p>
  *
  *       <ul>
  *
  *           <li>Associative and multidimensional array</li>
  *
  *           <li>
  *
  *               An {@link http://php.net/manual/en/reserved.classes.php stdClass Object}
  *
  *           </li>
  *
  *           <li>A well formed Next\Components\Parameter Object</li>
  *
  *       </ul>
  *
  *   </p>
  *
  *   <p>There are no Common Options defined so far.</p>
  *
  *   <p>
  *       All the arguments taken in consideration are defined in
  *       and by factored classes
  *   </p>
  *
  * @see Next\Components\Parameter
  *
  * @return mixed|void
  *   If chosen format allow the result to be returned, it will
  *   accordingly to the its rules
  *
  *   Otherwise, nothing is returned
  *
  * @throws Next\Tools\ClassMapper\ClassMapperException
  *   Invalid or unsupported Mapping Format
  */
 public function build($format, $options = NULL)
 {
     if (!in_array((string) $format, $this->available)) {
         throw ClassMapperException::unknown();
     }
     // Building Definitions
     $map = new \stdClass();
     $iterator =& $this;
     iterator_apply($iterator, function () use($iterator, $map) {
         $file = $iterator->current();
         $namespace = '';
         if (!empty($file->namespace)) {
             $namespace = sprintf('%s\\', $file->namespace);
         }
         $classname = $namespace . $file->classname;
         $map->{$classname} = $file->getRealPath();
         return TRUE;
     });
     // Building Output Format Classname
     $class = sprintf('Next\\Tools\\ClassMapper\\%s', (string) $format);
     // Instantiating Object
     $instance = new $class($options);
     // Building!
     return $instance->build(ArrayUtils::map($map));
 }