/**
  * @dataProvider getFormat
  * @runInSeparateProcess
  */
 public function testExecution($format)
 {
     $tmpDir = sys_get_temp_dir() . '/sf_hello';
     $filesystem = new Filesystem();
     $filesystem->remove($tmpDir);
     $filesystem->mkdirs($tmpDir);
     chdir($tmpDir);
     $tester = new CommandTester(new InitCommand());
     $tester->execute(array('--name' => 'Hello' . $format, '--app-path' => 'hello' . $format, '--web-path' => 'web', '--src-path' => 'src', '--format' => $format));
     // autoload
     $content = file_get_contents($file = $tmpDir . '/src/autoload.php');
     $content = str_replace("__DIR__.'/vendor", "'" . __DIR__ . "/../../../../src/vendor", $content);
     file_put_contents($file, $content);
     // Kernel
     $class = 'Hello' . $format . 'Kernel';
     $file = $tmpDir . '/hello' . $format . '/' . $class . '.php';
     $this->assertTrue(file_exists($file));
     $content = file_get_contents($file);
     $content = str_replace("__DIR__.'/../src/vendor/Symfony/src/Symfony/Bundle'", "'" . __DIR__ . "/../../../../src/vendor/Symfony/src/Symfony/Bundle'", $content);
     file_put_contents($file, $content);
     require_once $file;
     $kernel = new $class('dev', true);
     $response = $kernel->handle(Request::create('/'));
     $this->assertRegExp('/successfully/', $response->getContent());
     $filesystem->remove($tmpDir);
 }
    /**
     * @see Command
     *
     * @throws \InvalidArgumentException When the target directory does not exist
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (!is_dir($input->getArgument('target'))) {
            throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
        }

        $filesystem = new Filesystem();

        foreach ($this->container->get('kernel')->getBundles() as $bundle) {
            if (is_dir($originDir = $bundle->getPath().'/Resources/public')) {
                $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $bundle->getNamespacePrefix(), $bundle->getName()));

                $targetDir = $input->getArgument('target').'/bundles/'.preg_replace('/bundle$/', '', strtolower($bundle->getName()));

                $filesystem->remove($targetDir);

                if ($input->getOption('symlink')) {
                    $filesystem->symlink($originDir, $targetDir);
                } else {
                    mkdir($targetDir, 0777, true);
                    $filesystem->mirror($originDir, $targetDir);
                }
            }
        }
    }
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $finder = new Finder();
     $cachePath = $this->container->getParameter('assetpackager.options.cache_path');
     $finder = $finder->files()->in($cachePath);
     $filesystem = new Filesystem();
     $count = 0;
     foreach ($finder as $file) {
         $filesystem->remove($file);
         $count++;
     }
     $output->writeln("removed {$count} cache file(s)");
 }
    /**
     * @see Command
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $cachePath = $this->container->getParameter('assetoptimizer.cache_path');
        $filesystem = new Filesystem();

        // Remove and Recreaetd the cachepath
        $filesystem->remove($cachePath);

        if ($filesystem->mkdirs($cachePath)) {
            $filesystem->chmod($cachePath, 0777);
        } else {
            throw new \LogicException(sprintf('Could not create the directory "%s"', $cachePath));
        }

        $output->writeln(sprintf('Removed cache files in <info>%s</info>.', realpath($cachePath)));
    }
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->callPhing('sql', array('propel.packageObjectModel' => false));
     $filesystem = new Filesystem();
     $basePath = $this->application->getKernel()->getRootDir() . DIRECTORY_SEPARATOR . 'propel' . DIRECTORY_SEPARATOR . 'sql';
     $sqlMap = file_get_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map');
     foreach ($this->tempSchemas as $schemaFile => $schemaDetails) {
         $sqlFile = str_replace('.xml', '.sql', $schemaFile);
         $targetSqlFile = $schemaDetails['bundle'] . '-' . str_replace('.xml', '.sql', $schemaDetails['basename']);
         $targetSqlFilePath = $basePath . DIRECTORY_SEPARATOR . $targetSqlFile;
         $sqlMap = str_replace($sqlFile, $targetSqlFile, $sqlMap);
         $filesystem->remove($targetSqlFilePath);
         $filesystem->rename($basePath . DIRECTORY_SEPARATOR . $sqlFile, $targetSqlFilePath);
         $output->writeln(sprintf('Wrote SQL file for bundle "<info>%s</info>" in "<info>%s</info>"', $schemaDetails['bundle'], $targetSqlFilePath));
     }
     file_put_contents($basePath . DIRECTORY_SEPARATOR . 'sqldb.map', $sqlMap);
 }
Beispiel #6
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When namespace doesn't end with Bundle
  * @throws \RuntimeException         When bundle can't be executed
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (!preg_match('/Bundle$/', $namespace = $input->getArgument('namespace'))) {
         throw new \InvalidArgumentException('The namespace must end with Bundle.');
     }
     $dirs = $this->container->get('kernel')->getBundleDirs();
     $tmp = str_replace('\\', '/', $namespace);
     $namespace = str_replace('/', '\\', dirname($tmp));
     $bundle = basename($tmp);
     if (!isset($dirs[$namespace])) {
         throw new \InvalidArgumentException(sprintf("Unable to initialize the bundle (%s is not a defined namespace).\n" . "Defined namespaces are: %s", $namespace, implode(', ', array_keys($dirs))));
     }
     $dir = $dirs[$namespace];
     $output->writeln(sprintf('Initializing bundle "<info>%s</info>" in "<info>%s</info>"', $bundle, realpath($dir)));
     if (file_exists($targetDir = $dir . '/' . $bundle)) {
         throw new \RuntimeException(sprintf('Bundle "%s" already exists.', $bundle));
     }
     $filesystem = new Filesystem();
     $filesystem->mirror(__DIR__ . '/../Resources/skeleton/bundle', $targetDir);
     Mustache::renderDir($targetDir, array('namespace' => $namespace, 'bundle' => $bundle));
     rename($targetDir . '/Bundle.php', $targetDir . '/' . $bundle . '.php');
 }
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (file_exists($targetDir = $input->getArgument('path'))) {
         throw new \RuntimeException(sprintf('The directory "%s" already exists.', $targetDir));
     }
     if (!file_exists($webDir = $input->getArgument('web_path'))) {
         mkdir($webDir, 0777, true);
     }
     $parameters = array('class' => $input->getArgument('name'), 'application' => strtolower($input->getArgument('name')), 'format' => $input->getOption('format'));
     $filesystem = new Filesystem();
     $filesystem->mirror(__DIR__ . '/../Resources/skeleton/application/generic', $targetDir);
     $filesystem->mirror(__DIR__ . '/../Resources/skeleton/application/' . $input->getOption('format'), $targetDir);
     Mustache::renderDir($targetDir, $parameters);
     $filesystem->chmod($targetDir . '/console', 0777);
     $filesystem->chmod($targetDir . '/logs', 0777);
     $filesystem->chmod($targetDir . '/cache', 0777);
     $filesystem->rename($targetDir . '/Kernel.php', $targetDir . '/' . $input->getArgument('name') . 'Kernel.php');
     $filesystem->rename($targetDir . '/Cache.php', $targetDir . '/' . $input->getArgument('name') . 'Cache.php');
     $filesystem->copy(__DIR__ . '/../Resources/skeleton/web/front_controller.php', $file = $webDir . '/' . (file_exists($webDir . '/index.php') ? strtolower($input->getArgument('name')) : 'index') . '.php');
     Mustache::renderFile($file, $parameters);
     $filesystem->copy(__DIR__ . '/../Resources/skeleton/web/front_controller_debug.php', $file = $webDir . '/' . strtolower($input->getArgument('name')) . '_dev.php');
     Mustache::renderFile($file, $parameters);
 }
 /**
  * execute the command
  *
  * @param InputInterface $input 
  * @param OutputInterface $output 
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // var_dump($this->application);die();
     if (!is_dir($input->getArgument('target'))) {
         throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
     }
     $filesystem = new Filesystem();
     $dirs = $this->application->getKernel()->getBundleDirs();
     foreach ($this->application->getKernel()->getBundles() as $bundle) {
         $tmp = dirname(str_replace('\\', '/', get_class($bundle)));
         $namespace = str_replace('/', '\\', dirname($tmp));
         $class = basename($tmp);
         if (isset($dirs[$namespace]) && is_dir($originDir = $dirs[$namespace] . '/' . $class . '/Resources/public')) {
             $output->writeln(sprintf('Installing assets for <comment>%s\\%s</comment>', $namespace, $class));
             $targetDir = $input->getArgument('target') . '/bundles/' . preg_replace('/bundle$/', '', strtolower($class));
             $filesystem->remove($targetDir);
             if (!file_exists(dirname($targetDir))) {
                 mkdir(dirname($targetDir), 0755, true);
             }
             $filesystem->symlink($originDir, $targetDir);
         }
     }
 }
Beispiel #9
0
 protected function tearDown()
 {
     $filesystem = new Filesystem();
     $filesystem->remove($this->dir);
 }
Beispiel #10
0
 public function __destruct()
 {
     $fs = new Filesystem();
     $fs->remove($this->rootDir);
 }
Beispiel #11
0
 protected function callPhing($taskName, $properties = array())
 {
     $kernel = $this->application->getKernel();
     $tmpDir = sys_get_temp_dir() . '/propel-gen';
     $filesystem = new Filesystem();
     $filesystem->remove($tmpDir);
     $filesystem->mkdirs($tmpDir);
     foreach ($kernel->getBundles() as $bundle) {
         if (is_dir($dir = $bundle->getPath() . '/Resources/config')) {
             $finder = new Finder();
             $schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir);
             $parts = explode(DIRECTORY_SEPARATOR, realpath($bundle->getPath()));
             $prefix = implode('.', array_slice($parts, 1, -2));
             foreach ($schemas as $schema) {
                 $tempSchema = md5($schema) . '_' . $schema->getBaseName();
                 $this->tempSchemas[$tempSchema] = array('bundle' => $bundle->getName(), 'basename' => $schema->getBaseName(), 'path' => $schema->getPathname());
                 $file = $tmpDir . DIRECTORY_SEPARATOR . $tempSchema;
                 $filesystem->copy((string) $schema, $file);
                 // the package needs to be set absolute
                 // besides, the automated namespace to package conversion has not taken place yet
                 // so it needs to be done manually
                 $database = simplexml_load_file($file);
                 if (isset($database['package'])) {
                     $database['package'] = $prefix . '.' . $database['package'];
                 } elseif (isset($database['namespace'])) {
                     $database['package'] = $prefix . '.' . str_replace('\\', '.', $database['namespace']);
                 }
                 foreach ($database->table as $table) {
                     if (isset($table['package'])) {
                         $table['package'] = $prefix . '.' . $table['package'];
                     } elseif (isset($table['namespace'])) {
                         $table['package'] = $prefix . '.' . str_replace('\\', '.', $table['namespace']);
                     }
                 }
                 file_put_contents($file, $database->asXML());
             }
         }
     }
     $filesystem->touch($tmpDir . '/build.properties');
     $args = array();
     //        $bufferPhingOutput = !$this->commandApplication->withTrace();
     $properties = array_merge(array('propel.database' => 'mysql', 'project.dir' => $tmpDir, 'propel.output.dir' => $kernel->getRootDir() . '/propel', 'propel.php.dir' => '/', 'propel.packageObjectModel' => true), $properties);
     foreach ($properties as $key => $value) {
         $args[] = "-D{$key}={$value}";
     }
     // Build file
     $args[] = '-f';
     $args[] = realpath($kernel->getContainer()->getParameter('propel.path') . '/generator/build.xml');
     /*
             // Logger
             if (DIRECTORY_SEPARATOR != '\\' && (function_exists('posix_isatty') && @posix_isatty(STDOUT))) {
                 $args[] = '-logger';
                 $args[] = 'phing.listener.AnsiColorLogger';
             }
     
             // Add our listener to detect errors
             $args[] = '-listener';
             $args[] = 'sfPhingListener';
     */
     // Add any arbitrary arguments last
     foreach ($this->additionalPhingArgs as $arg) {
         if (in_array($arg, array('verbose', 'debug'))) {
             $bufferPhingOutput = false;
         }
         $args[] = '-' . $arg;
     }
     $args[] = $taskName;
     // enable output buffering
     Phing::setOutputStream(new \OutputStream(fopen('php://output', 'w')));
     Phing::startup();
     Phing::setProperty('phing.home', getenv('PHING_HOME'));
     //      $this->logSection('propel', 'Running "'.$taskName.'" phing task');
     $bufferPhingOutput = false;
     if ($bufferPhingOutput) {
         ob_start();
     }
     $m = new Phing();
     $m->execute($args);
     $m->runBuild();
     if ($bufferPhingOutput) {
         ob_end_clean();
     }
     print $bufferPhingOutput;
     chdir($kernel->getRootDir());
     /*
             // any errors?
             $ret = true;
             if (sfPhingListener::hasErrors())
             {
                 $messages = array('Some problems occurred when executing the task:');
     
                 foreach (sfPhingListener::getExceptions() as $exception)
                 {
                   $messages[] = '';
                   $messages[] = preg_replace('/^.*build\-propel\.xml/', 'build-propel.xml', $exception->getMessage());
                   $messages[] = '';
                 }
     
                 if (count(sfPhingListener::getErrors()))
                 {
                   $messages[] = 'If the exception message is not clear enough, read the output of the task for';
                   $messages[] = 'more information';
                 }
     
                 $this->logBlock($messages, 'ERROR_LARGE');
     
                 $ret = false;
             }
     */
     $ret = true;
     return $ret;
 }
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $finder = new Finder();
     if (iterator_count($finder->in(getcwd()))) {
         throw new \RuntimeException('The current directory is not empty.');
     }
     $parameters = array('class' => $input->getOption('name'), 'application' => strtolower($input->getOption('name')), 'format' => $input->getOption('format'));
     $filesystem = new Filesystem();
     $skeletonDir = __DIR__ . '/../../skeleton';
     $appPath = getcwd() . '/' . $input->getOption('app-path');
     $srcPath = getcwd() . '/' . $input->getOption('src-path');
     $webPath = getcwd() . '/' . $input->getOption('web-path');
     $filesystem->mirror($skeletonDir . '/application/generic', $appPath);
     $filesystem->mirror($skeletonDir . '/application/' . $input->getOption('format'), $appPath);
     $filesystem->mirror($skeletonDir . '/src', $srcPath);
     Mustache::renderDir($appPath, $parameters);
     $filesystem->chmod($appPath . '/console', 0777);
     $filesystem->chmod($appPath . '/logs', 0777);
     $filesystem->chmod($appPath . '/cache', 0777);
     $filesystem->rename($appPath . '/Kernel.php', $appPath . '/' . $input->getOption('name') . 'Kernel.php');
     $filesystem->rename($appPath . '/Cache.php', $appPath . '/' . $input->getOption('name') . 'Cache.php');
     $filesystem->copy($skeletonDir . '/web/front_controller.php', $file = $webPath . '/' . (file_exists($webPath . '/index.php') ? strtolower($input->getOption('name')) : 'index') . '.php');
     Mustache::renderFile($file, $parameters);
     $filesystem->copy($skeletonDir . '/web/front_controller_debug.php', $file = $webPath . '/' . strtolower($input->getOption('name')) . '_dev.php');
     Mustache::renderFile($file, $parameters);
 }