Zephir\Stubs\Generator::generate PHP Method

generate() public method

Generates stubs
public generate ( string $path )
$path string
    public function generate($path)
    {
        if ($this->config->get('indent', 'extra') === 'tabs') {
            $indent = "\t";
        } else {
            $indent = '    ';
        }
        $namespace = $this->config->get('namespace');
        foreach ($this->files as $file) {
            $class = $file->getClassDefinition();
            $source = $this->buildClass($class, $indent);
            $filename = ucfirst($class->getName()) . '.zep.php';
            $filePath = $path . str_replace($namespace, '', str_replace($namespace . '\\\\', DIRECTORY_SEPARATOR, strtolower($class->getNamespace())));
            $filePath = str_replace('\\', DIRECTORY_SEPARATOR, $filePath);
            $filePath = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $filePath);
            if (!is_dir($filePath)) {
                mkdir($filePath, 0777, true);
            }
            $filePath = realpath($filePath) . '/';
            file_put_contents($filePath . $filename, $source);
        }
    }

Usage Example

Example #1
0
 /**
  * Generate IDE stubs
  *
  * @param CommandInterface $command
  * @param bool             $fromGenerate
  */
 public function stubs(CommandInterface $command, $fromGenerate = false)
 {
     if (!$fromGenerate) {
         $this->generate($command);
     }
     $this->logger->output('Generating stubs...');
     $stubsGenerator = new Stubs\Generator($this->files, $this->config);
     $path = $this->config->get('path', 'stubs');
     $path = str_replace('%version%', $this->config->get('version'), $path);
     $path = str_replace('%namespace%', ucfirst($this->config->get('namespace')), $path);
     $stubsGenerator->generate($path);
 }