예제 #1
0
 public static function generate()
 {
     $dir = getcwd() . "/";
     $file = "{$dir}/vendor/autoload.php";
     $finder = new Finder();
     $finder->files()->name("*.php")->in($dir);
     $generator = new Generator($finder);
     $generator->relativePaths(true)->includePSR0Autoloader(false)->multipleFiles()->generate($file, "{$file}.cache");
     return true;
 }
예제 #2
0
 public function build()
 {
     if ($this->stub) {
         $autoload = new Autoloader\Generator($this->tmp);
         $autoload->relativePaths()->IncludePSR0Autoloader(false);
         $autoload->generate($this->tmp . "/" . $this->autoload, getcwd() . "/.phar-build-tmp");
         $this->phar->setStub("#!/usr/bin/env php\n" . $this->phar->createDefaultStub($this->stub));
     }
     $this->phar->startBuffering();
     $this->phar->buildFromDirectory($this->tmp);
     $this->phar->setSignatureAlgorithm(phar::SHA1);
     $this->phar->stopBuffering();
 }
예제 #3
0
 /**
  *  @Cli("generate", "Generate autoloader")
  *  @Option('library')
  *  @Option('relative')
  *  @Option('multi')
  *  @Option('enable-cache')
  *  @Option('include-psr-0', default=true)
  *  @Arg('output', REQUIRED)
  *  @Arg('dir', REQUIRED|IS_ARRAY)
  */
 public function generate(InputInterface $input, OutputInterface $output)
 {
     $file = $this->getPath($input->getArgument('output'));
     $finder = $this->getFinderObject($input->getOption('library'), $input->getArgument('dir'));
     $relative = $input->getOption('relative');
     $include = $input->getOption('include-psr-0');
     $cache = $input->getOption('enable-cache');
     $multi = $input->getOption('multi');
     try {
         $generator = new Generator($finder);
         $generator->setStepCallback(function ($file, $classes, $error = false) use($output) {
             if ($error) {
                 $output->write("<error>failed: {$file}</error>\n");
             } else {
                 $output->write("<comment>scanning {$file}</comment>\n");
             }
         });
         $generator->relativePaths($relative);
         $generator->includePSR0Autoloader($include);
         if ($multi) {
             $generator->multipleFiles();
         } else {
             $generator->singleFile();
         }
         $generator->generate($file, $cache ? $file . '.cache' : NULL);
     } catch (\exception $e) {
         $output->write("<error>Fatal error, stopping generator</error>\n");
     }
     $output->write("<info>{$file} was generated</info>\n");
 }