コード例 #1
0
ファイル: bootstrapTest.php プロジェクト: rouffj/Sismo
 public function setUp()
 {
     $this->app = (require __DIR__ . '/../src/bootstrap.php');
     $this->baseDir = sys_get_temp_dir() . '/sismo';
     $fs = new Filesystem();
     $fs->mkdir($this->baseDir);
     $fs->mkdir($this->baseDir . '/config');
     $app['data.path'] = $this->baseDir . '/db';
     $app['config.file'] = $this->baseDir . '/config.php';
     @unlink($this->app['db.path']);
     file_put_contents($app['config.file'], '<?php return array();');
 }
コード例 #2
0
 /**
  * @see Command
  *
  * @throws \InvalidArgumentException When the target directory does not exist
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->writeSection($output, '[Propel] You are running the command: propel:build-sql');
     if ($input->getOption('verbose')) {
         $this->additionalPhingArgs[] = 'verbose';
     }
     $finder = new Finder();
     $filesystem = new Filesystem();
     $sqlDir = $this->getApplication()->getKernel()->getRootDir() . DIRECTORY_SEPARATOR . 'propel' . DIRECTORY_SEPARATOR . 'sql';
     $filesystem->remove($sqlDir);
     $filesystem->mkdir($sqlDir);
     // Execute the task
     $ret = $this->callPhing('build-sql', array('propel.sql.dir' => $sqlDir));
     if (true === $ret) {
         $files = $finder->name('*')->in($sqlDir);
         $nbFiles = 0;
         foreach ($files as $file) {
             $this->writeNewFile($output, (string) $file);
             if ('sql' === pathinfo($file->getFilename(), PATHINFO_EXTENSION)) {
                 $nbFiles++;
             }
         }
         $this->writeSection($output, sprintf('<comment>%d</comment> <info>SQL file%s ha%s been generated.</info>', $nbFiles, $nbFiles > 1 ? 's' : '', $nbFiles > 1 ? 've' : 's'), 'bg=black');
     } else {
         $this->writeSection($output, array('[Propel] Error', '', 'An error has occured during the "build-sql" task process. To get more details, run the command with the "--verbose" option.'), 'fg=white;bg=red');
     }
 }
コード例 #3
0
 /**
  * Prepare the cache directory
  *
  * @param string $tmpdir    The temporary directory path.
  */
 protected function prepareCache($tmpdir)
 {
     // Recreate a propel directory in cache
     $this->filesystem->remove($tmpdir);
     $this->filesystem->mkdir($tmpdir);
     $fixturesdir = $tmpdir . '/fixtures/';
     $this->filesystem->remove($fixturesdir);
     $this->filesystem->mkdir($fixturesdir);
 }
コード例 #4
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $items = array("Unlimited", "Rated", "Casual", "No game available right now, create one!", "This game is rated", "White creates the game", "Black creates the game", "White joins the game", "Black joins the game", "Draw offer sent", "Draw offer declined", "Draw offer accepted", "Draw offer canceled", "Takeback proposition sent", "Takeback proposition declined", "Takeback proposition accepted", "Takeback proposition canceled", "Game over", "Your turn", "Waiting for opponent");
     $tm = $this->getContainer()->get('lichess_translation.manager');
     $translator = $this->getContainer()->get('translator');
     $fs = new Filesystem();
     $dir = $this->getContainer()->getParameter('kernel.root_dir') . '/../web/trans';
     $fs->mkdir($dir);
     foreach ($tm->getAvailableLanguages() as $code => $name) {
         $translator->setLocale($code);
         $translations = array();
         foreach ($items as $item) {
             $translations[$item] = $translator->trans($item);
         }
         $content = sprintf("lichess_translations = %s;", json_encode($translations));
         $file = sprintf("%s/%s.js", $dir, $code);
         file_put_contents($file, $content);
     }
     $output->writeLn('Done');
 }
コード例 #5
0
ファイル: PhingCommand.php プロジェクト: rozwell/PropelBundle
 /**
  * Call a Phing task.
  *
  * @param string $taskName  A Propel task name.
  * @param array $properties An array of properties to pass to Phing.
  */
 protected function callPhing($taskName, $properties = array())
 {
     $kernel = $this->getApplication()->getKernel();
     $filesystem = new Filesystem();
     if (isset($properties['propel.schema.dir'])) {
         $this->tmpDir = $properties['propel.schema.dir'];
     } else {
         $this->tmpDir = sys_get_temp_dir() . '/propel-gen';
         $filesystem->remove($this->tmpDir);
         $filesystem->mkdir($this->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()));
             $length = count(explode('\\', $bundle->getNamespace())) * -1;
             $prefix = implode('.', array_slice($parts, 1, $length));
             foreach ($schemas as $schema) {
                 $tempSchema = md5($schema) . '_' . $schema->getBaseName();
                 $this->tempSchemas[$tempSchema] = array('bundle' => $bundle->getName(), 'basename' => $schema->getBaseName(), 'path' => $schema->getPathname());
                 $file = $this->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']);
                 } else {
                     throw new \RuntimeException(sprintf('Please define a `package` attribute or a `namespace` attribute for schema `%s`', $schema->getBaseName()));
                 }
                 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']);
                     } else {
                         $table['package'] = $database['package'];
                     }
                 }
                 file_put_contents($file, $database->asXML());
             }
         }
     }
     // build.properties
     $this->buildPropertiesFile = $kernel->getRootDir() . '/config/propel.ini';
     $filesystem->touch($this->buildPropertiesFile);
     $filesystem->copy($this->buildPropertiesFile, $this->tmpDir . '/build.properties');
     // Required by the Phing task
     $this->createBuildTimeFile($this->tmpDir . '/buildtime-conf.xml');
     $args = array();
     $properties = array_merge(array('propel.database' => 'mysql', 'project.dir' => $this->tmpDir, 'propel.output.dir' => $kernel->getRootDir() . '/propel', 'propel.php.dir' => '/', 'propel.packageObjectModel' => true), $properties);
     $properties = array_merge($properties, $this->getContainer()->get('propel.build_properties')->getProperties());
     foreach ($properties as $key => $value) {
         $args[] = "-D{$key}={$value}";
     }
     // Build file
     $args[] = '-f';
     $args[] = realpath($this->getContainer()->getParameter('propel.path') . '/generator/build.xml');
     $bufferPhingOutput = !$this->getContainer()->getParameter('kernel.debug');
     // 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::setErrorStream(new \OutputStream(fopen('php://output', 'w')));
     Phing::startup();
     Phing::setProperty('phing.home', getenv('PHING_HOME'));
     ob_start();
     $phing = new Phing();
     $returnStatus = true;
     // optimistic way
     try {
         $phing->execute($args);
         $phing->runBuild();
         $this->buffer = ob_get_contents();
         $returnStatus = false !== preg_match('#failed. Aborting.#', $this->buffer);
     } catch (Exception $e) {
         $returnStatus = false;
     }
     if ($bufferPhingOutput) {
         ob_end_clean();
     } else {
         ob_end_flush();
     }
     chdir($kernel->getRootDir());
     return $returnStatus;
 }
コード例 #6
0
 /**
  * @param KernelInterface $kernel   The application kernel.
  */
 protected function copySchemas(KernelInterface $kernel, $cacheDir)
 {
     $filesystem = new Filesystem();
     if (!is_dir($cacheDir)) {
         $filesystem->mkdir($cacheDir);
     }
     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()));
             $length = count(explode('\\', $bundle->getNamespace())) * -1;
             $prefix = implode('/', array_slice($parts, 1, $length));
             foreach ($schemas as $schema) {
                 $tempSchema = $bundle->getName() . '-' . $schema->getBaseName();
                 $this->tempSchemas[$tempSchema] = array('bundle' => $bundle->getName(), 'basename' => $schema->getBaseName(), 'path' => $schema->getPathname());
                 $file = $cacheDir . DIRECTORY_SEPARATOR . $tempSchema;
                 $filesystem->copy((string) $schema, $file, true);
                 // 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']);
                 } else {
                     throw new \RuntimeException(sprintf('%s : Please define a `package` attribute or a `namespace` attribute for schema `%s`', $bundle->getName(), $schema->getBaseName()));
                 }
                 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']);
                     } else {
                         $table['package'] = $database['package'];
                     }
                 }
                 file_put_contents($file, $database->asXML());
             }
         }
     }
 }