Used with events: - "spress.start".
저자: Victor Puertas (vpgugr@gmail.com)
상속: extends Symfony\Component\EventDispatcher\Event
 /**
  * Extract configuration and override the default DataWriter on startup
  *
  * @param EnvironmentEvent $event The start event
  */
 public function onStart(EnvironmentEvent $event)
 {
     $configValues = $event->getConfigValues();
     $configuration = new Configuration($configValues);
     $event->setConfigValues($configuration->get());
     $event->setDataWriter(new FilesystemDataWriter($event->getDataWriter(), $configuration));
 }
 /**
  * Register the `codeblock` tag on startup
  *
  * @param EnvironmentEvent $event The start event
  */
 public function onStart(EnvironmentEvent $event)
 {
     $renderizer = $event->getRenderizer();
     if (method_exists($renderizer, 'addTwigTag')) {
         $renderizer->addTwigTag(new CodeBlockParser());
     }
 }
 public function onStart(EnvironmentEvent $event)
 {
     $io = $event->getIO();
     $configValues = $event->getConfigValues();
     $io->write('Getting Github metadata...');
     $repository = $this->getRepositoryComponents($configValues['repository']);
     if (2 != count($repository)) {
         $io->write('<error>Invalid repository name.</error>');
         return;
     }
     $client = new \Github\Client();
     $metadataRepo = $client->api('repo')->show($repository['vendor'], $repository['name']);
     $metadata = ['name' => $metadataRepo['name'], 'full_name' => $metadataRepo['full_name'], 'description' => $metadataRepo['description'], 'fork' => $metadataRepo['fork'], 'html_url' => $metadataRepo['html_url'], 'clone_url' => $metadataRepo['clone_url'], 'git_url' => $metadataRepo['git_url'], 'ssh_url' => $metadataRepo['ssh_url'], 'mirror_url' => $metadataRepo['mirror_url'], 'homepage' => $metadataRepo['homepage'], 'forks_count' => $metadataRepo['forks_count'], 'stargazers_count' => $metadataRepo['stargazers_count'], 'watchers_count' => $metadataRepo['watchers_count'], 'size' => $metadataRepo['size'], 'default_branch' => $metadataRepo['default_branch'], 'open_issues_count' => $metadataRepo['open_issues_count'], 'has_issues' => $metadataRepo['has_issues'], 'has_wiki' => $metadataRepo['has_wiki'], 'has_pages' => $metadataRepo['has_pages'], 'has_downloads' => $metadataRepo['has_downloads'], 'pushed_at' => $metadataRepo['pushed_at'], 'created_at' => $metadataRepo['created_at'], 'updated_at' => $metadataRepo['updated_at'], 'owner' => ['login' => $metadataRepo['owner']['login'], 'avatar_url' => $metadataRepo['owner']['avatar_url'], 'gravatar_id' => $metadataRepo['owner']['gravatar_id'], 'html_url' => $metadataRepo['owner']['html_url']], 'organization' => [], 'source' => [], 'contributors' => []];
     if (isset($metadataRepo['organization'])) {
         $metadata['organization'] = ['login' => $metadataRepo['organization']['login'], 'avatar_url' => $metadataRepo['organization']['avatar_url'], 'html_url' => $metadataRepo['organization']['html_url']];
     }
     if (isset($metadataRepo['source'])) {
         $metadata['source'] = ['name' => $metadataRepo['source']['name'], 'full_name' => $metadataRepo['source']['full_name'], 'description' => $metadataRepo['source']['description'], 'html_url' => $metadataRepo['source']['html_url'], 'clone_url' => $metadataRepo['source']['clone_url'], 'git_url' => $metadataRepo['source']['git_url'], 'ssh_url' => $metadataRepo['source']['ssh_url'], 'svn_url' => $metadataRepo['source']['svn_url'], 'mirror_url' => $metadataRepo['source']['mirror_url'], 'homepage' => $metadataRepo['source']['homepage'], 'forks_count' => $metadataRepo['source']['forks_count'], 'stargazers_count' => $metadataRepo['source']['stargazers_count'], 'watchers_count' => $metadataRepo['source']['watchers_count'], 'size' => $metadataRepo['source']['size'], 'default_branch' => $metadataRepo['source']['default_branch'], 'open_issues_count' => $metadataRepo['source']['open_issues_count'], 'has_issues' => $metadataRepo['source']['has_issues'], 'has_wiki' => $metadataRepo['source']['has_wiki'], 'has_pages' => $metadataRepo['source']['has_pages'], 'has_downloads' => $metadataRepo['source']['has_downloads'], 'pushed_at' => $metadataRepo['source']['pushed_at'], 'created_at' => $metadataRepo['source']['created_at'], 'updated_at' => $metadataRepo['source']['updated_at']];
     }
     $contributors = $client->api('repo')->contributors($repository['vendor'], $repository['name']);
     foreach ($contributors as $contributor) {
         $metadata['contributors'][] = ['login' => $contributor['login'], 'avatar_url' => $contributor['avatar_url'], 'html_url' => $contributor['html_url'], 'type' => $contributor['type'], 'contributions' => $contributor['contributions']];
     }
     $configValues['github'] = $metadata;
     $event->setConfigValues($configValues);
 }
 public function onStart(EnvironmentEvent $event)
 {
     $this->io = $event->getIO();
     $configValues = $event->getConfigValues();
     if (isset($configValues['html_beautifier_excluded'])) {
         $this->excluded_files = $configValues['html_beautifier_exclude'];
     }
 }
 public function onStart(EnvironmentEvent $event)
 {
     $configValues = $event->getConfigValues();
     if (isset($configValues['google_analytics'])) {
         $this->googleAnalyticsID = $configValues['google_analytics']['id'];
         $this->googleAnalyticsSite = $configValues['google_analytics']['site'];
     }
 }
 public function onStart(EnvironmentEvent $event)
 {
     $this->io = $event->getIO();
     $configValues = $event->getConfigValues();
     if (isset($configValues['html_compress_exclude'])) {
         $this->html_compress_exclude = $configValues['html_compress_exclude'];
     }
 }
 public function onStart(EnvironmentEvent $event)
 {
     $renderizer = $event->getRenderizer();
     $renderizer->addTwigFilter('slugify', function ($text) {
         $string = new StringWrapper($text);
         return $string->slug();
     });
 }
예제 #8
0
 public function onStart(EnvironmentEvent $event)
 {
     $dsm = $event->getDataSourceManager();
     $item = new Item('Content from item in memory data source', 'memory-datasource.txt');
     $item->setPath('memory-datasource.txt', Item::SNAPSHOT_PATH_RELATIVE);
     $memoryDataSource = new MemoryDataSource();
     $memoryDataSource->addItem($item);
     $dsm->setDataSource('memory-plugin', $memoryDataSource);
 }
예제 #9
0
 public function testEnvironmentEvent()
 {
     $dsm = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\DataSource\\DataSourceManager')->getMock();
     $cm = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\ContentManager\\Converter\\ConverterManager')->getMock();
     $gm = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\ContentManager\\Generator\\GeneratorManager')->getMock();
     $renderizer = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\ContentManager\\Renderizer\\RenderizerInterface')->getMock();
     $io = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\IO\\IOInterface')->getMock();
     $dw = $this->getMockBuilder('\\Yosymfony\\Spress\\Core\\DataWriter\\DataWriterInterface')->getMock();
     $configValues = ['name' => 'Yo! Symfony'];
     $event = new EnvironmentEvent($dsm, $dw, $cm, $gm, $renderizer, $io, $configValues);
     $this->assertInstanceOf('\\Yosymfony\\Spress\\Core\\DataSource\\DataSourceManager', $event->getDataSourceManager());
     $this->assertInstanceOf('\\Yosymfony\\Spress\\Core\\DataWriter\\DataWriterInterface', $event->getDataWriter());
     $this->assertInstanceOf('\\Yosymfony\\Spress\\Core\\ContentManager\\Converter\\ConverterManager', $event->getConverterManager());
     $this->assertInstanceOf('\\Yosymfony\\Spress\\Core\\ContentManager\\Generator\\GeneratorManager', $event->getGeneratorManager());
     $this->assertInstanceOf('\\Yosymfony\\Spress\\Core\\ContentManager\\Renderizer\\RenderizerInterface', $event->getRenderizer());
     $this->assertInstanceOf('\\Yosymfony\\Spress\\Core\\IO\\IOInterface', $event->getIO());
     $values = $event->getConfigValues();
     $this->assertTrue(is_array($values));
     $this->assertArrayHasKey('name', $values);
     $this->assertEquals('Yo! Symfony', $values['name']);
     $values['title'] = 'My blog page';
     $event->setConfigValues($values);
     $this->assertArrayHasKey('name', $configValues);
     $this->assertEquals('My blog page', $configValues['title']);
 }
 /**
  * Load requested Twig extensions on startup
  *
  * @param EnvironmentEvent $event The start event
  */
 public function onStart(EnvironmentEvent $event)
 {
     $configValues = $event->getConfigValues();
     $configValues['twig_extensions'] = (new Configuration($configValues))->getExtensions();
     $event->setConfigValues($configValues);
     $factory = new ExtensionFactory();
     $renderizer = $event->getRenderizer();
     foreach ($configValues['twig_extensions'] as $extension) {
         try {
             $factory->getExtension($extension)->load($renderizer);
         } catch (\UnexpectedValueException $e) {
             $event->getIO()->warning($e->getMessage());
         }
     }
 }
 public function onStart(EnvironmentEvent $event)
 {
     $renderizer = $event->getRenderizer();
     $renderizer->addTwigFilter('excerpt', function ($text) {
         return $this->getExcerpt($text);
     });
     $renderizer->addTwigFilter('content', function ($text) {
         return $this->getContentWithoutExcerptLabel($text);
     });
     $renderizer->addTwigFilter('excerpt_label', function ($text) {
         return $this->getExcerptLabel($text);
     });
     $renderizer->addTwigTest('with_excerpt', function ($text) {
         return $this->hasExcerpt($text);
     });
 }
 public function onStart(EnvironmentEvent $event)
 {
     $configValues = $event->getConfigValues();
     $dataDir = __DIR__ . '/../../../data';
     $data = [];
     if (file_exists($dataDir) && is_dir($dataDir)) {
         if ($items = scandir($dataDir)) {
             foreach ($items as $item) {
                 if ($splFile = $this->getSplFile($dataDir, $item)) {
                     $data += $this->readJsonFile($splFile);
                 }
             }
         }
     }
     $configValues['data'] = $data;
     $event->setConfigValues($configValues);
 }
 public function onStart(EnvironmentEvent $event)
 {
     $renderizer = $event->getRenderizer();
     $renderizer->addTwigFunction('remote_json', function ($url) {
         if (!file_exists('.cache')) {
             mkdir('.cache');
         }
         $cache_file = '.cache/' . sha1($url);
         if (file_exists($cache_file) && filemtime($cache_file) > time() - 60 * 5) {
             $json = file_get_contents($cache_file);
         } else {
             $curl = curl_init();
             curl_setopt_array($curl, [CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => 'spress/' . Yosymfony\Spress\Core\Spress::VERSION, CURLOPT_URL => $url]);
             $json = curl_exec($curl);
             file_put_contents($cache_file, $json, LOCK_EX);
         }
         return json_decode($json);
     });
 }
 public function onStart(EnvironmentEvent $event)
 {
     $event->getConverterManager()->addConverter(new SassMinify());
 }