Ejemplo n.º 1
0
 /**
  * @param PackageEvent $event
  */
 public function onCreatePackage(PackageEvent $event)
 {
     $package = $event->getPackage();
     $config = $this->entityManager->getRepository('Terramar\\Packages\\Plugin\\Sami\\PackageConfiguration')->findOneBy(array('package' => $package));
     if (!$config) {
         $config = new PackageConfiguration();
         $config->setPackage($package);
     }
     $this->entityManager->persist($config);
 }
Ejemplo n.º 2
0
    private function writeConfig($configFilePath, Package $package, PackageConfiguration $config)
    {
        $cachePath = $this->getCacheDir($package);
        $tagsCode = $config->getTags() ? '    ->addFromTags(\'' . implode('\',\'', explode(',', $config->getTags())) . '\\)' . PHP_EOL : '';
        $refsCode = '';
        foreach ($this->getRefs($config) as $ref) {
            $refsCode .= '    ->add(\'' . $ref[0] . '\', \'' . $ref[1] . '\')' . PHP_EOL;
        }
        $templatesCode = '';
        if ($templatesDir = $config->getTemplatesDir()) {
            $templatesCode = '    \'templates_dir\' => array(\'' . $templatesDir . '\'),' . "\n";
        }
        $code = <<<END
<?php

\$iterator = Symfony\\Component\\Finder\\Finder::create()
    ->files()
    ->name('*.php')
    ->exclude('Resources')
    ->exclude('Tests')
    ->in(\$dir = '{$config->getRepositoryPath()}/{$config->getDocsPath()}');

\$versions = Sami\\Version\\GitVersionCollection::create(\$dir)
{$tagsCode}{$refsCode};

return new Sami\\Sami(\$iterator, array(
    'title' => '{$config->getTitle()}',
    'build_dir' => '{$cachePath}/build/%version%',
    'cache_dir' => '{$cachePath}/cache/%version%',
    'default_opened_level' => 2,
    'theme' => '{$config->getTheme()}',
{$templatesCode}    'versions' => \$versions
));
END;
        file_put_contents($configFilePath, $code);
    }