Goetas\Xsd\XsdToPhp\Php\PathGenerator\Psr4PathGenerator::getPath PHP Method

getPath() public method

public getPath ( PHPClass $php )
$php Goetas\Xsd\XsdToPhp\Php\Structure\PHPClass
    public function getPath(PHPClass $php)
    {
        foreach ($this->namespaces as $namespace => $dir) {
            if (strpos(trim($php->getNamespace()) . "\\", $namespace) === 0) {
                $d = strtr(substr($php->getNamespace(), strlen($namespace)), "\\", "/");
                $dir = rtrim($dir, "/") . "/" . $d;
                if (!is_dir($dir) && !mkdir($dir, 0777, true)) {
                    throw new PathGeneratorException("Can't create the '{$dir}' directory");
                }
                return rtrim($dir, "/") . "/" . $php->getName() . ".php";
            }
        }
        throw new PathGeneratorException("Can't find a defined location where save '{$php}' object");
    }

Usage Example

Beispiel #1
0
 protected function convert(AbstractConverter $converter, array $schemas, array $targets, OutputInterface $output)
 {
     $generator = new ClassGenerator();
     $generator->setTargetPhpVersion($converter->getTargetPhpVersion());
     $generator->setBaseClass($converter->getBaseClass());
     $pathGenerator = new Psr4PathGenerator($targets);
     $progress = $this->getHelperSet()->get('progress');
     $items = $converter->convert($schemas);
     $progress->start($output, count($items));
     foreach ($items as $item) {
         $progress->advance(1, true);
         $output->write(" Creating <info>" . $output->getFormatter()->escape($item->getFullName()) . "</info>... ");
         $path = $pathGenerator->getPath($item);
         $fileGen = new FileGenerator();
         $fileGen->setFilename($path);
         $classGen = new \Zend\Code\Generator\ClassGenerator();
         if ($generator->generate($classGen, $item)) {
             $fileGen->setClass($classGen);
             $fileGen->write();
             $output->writeln("done.");
         } else {
             $output->write("skip.");
         }
     }
     $progress->finish();
 }
All Usage Examples Of Goetas\Xsd\XsdToPhp\Php\PathGenerator\Psr4PathGenerator::getPath
Psr4PathGenerator