Author: Victor Puertas (vpgugr@gmail.com)
 public function testBuild()
 {
     $builder = new PluginManagerBuilder($this->pluginDir, new EventDispatcher());
     $pm = $builder->build();
     $pluginCollection = $pm->getPluginCollection();
     $this->assertCount(2, $pluginCollection);
     $plugin = $pluginCollection->get('Test plugin');
     $metas = $plugin->getMetas();
     $this->assertEquals('Test plugin', $metas['name']);
     $plugin = $pluginCollection->get('Hello plugin');
     $metas = $plugin->getMetas();
     $this->assertEquals('Hello plugin', $metas['name']);
 }
 public function testBuild()
 {
     $builder = new PluginManagerBuilder($this->pluginDir, new EventDispatcher());
     $pm = $builder->build();
     $this->assertEquals(2, $pm->countPlugins());
     $plugin = $pm->getPlugin('Test plugin');
     $this->assertInstanceOf('Yosymfony\\Spress\\Core\\Plugin\\PluginInterface', $plugin);
     $metas = $plugin->getMetas();
     $this->assertEquals('Test plugin', $metas['name']);
     $plugin = $pm->getPlugin('Hello plugin');
     $this->assertInstanceOf('Yosymfony\\Spress\\Core\\Plugin\\PluginInterface', $plugin);
     $metas = $plugin->getMetas();
     $this->assertEquals('Hello plugin', $metas['name']);
 }
Esempio n. 3
0
 public function __construct()
 {
     parent::__construct();
     $this['spress.version'] = self::VERSION;
     $this['spress.version.details'] = ['id' => self::VERSION_ID, 'major' => self::MAJOR_VERSION, 'minor' => self::MINOR_VERSION, 'release' => self::RELEASE_VERSION, 'extra' => self::EXTRA_VERSION];
     $this['spress.externals'] = [];
     $this['spress.config.default_filename'] = __DIR__ . '/config/default.yml';
     $this['spress.config.site_dir'] = realpath('./');
     $this['spress.config.build_dir'] = function ($c) {
         return $c['spress.config.site_dir'] . '/build';
     };
     $this['spress.config.plugin_dir'] = function ($c) {
         return $c['spress.config.site_dir'] . '/src/plugins';
     };
     $this['spress.config.vendor_dir'] = function ($c) {
         return 'vendor';
     };
     $this['spress.config.composer_filename'] = 'composer.json';
     $this['spress.config.env'] = null;
     $this['spress.config.safe'] = null;
     $this['spress.config.drafts'] = null;
     $this['spress.config.url'] = null;
     $this['spress.config.timezone'] = null;
     $this['spress.config.values'] = function ($c) {
         $configLoader = $c['spress.config'];
         $attributes = $configLoader->loadConfiguration($c['spress.config.site_dir'], $c['spress.config.env']);
         if (is_null($this['spress.config.drafts']) === false) {
             $attributes['drafts'] = (bool) $this['spress.config.drafts'];
         }
         if (is_null($this['spress.config.safe']) === false) {
             $attributes['safe'] = (bool) $this['spress.config.safe'];
         }
         if (is_null($this['spress.config.timezone']) === false) {
             $attributes['timezone'] = $this['spress.config.timezone'];
         }
         if (is_null($this['spress.config.url']) === false) {
             $attributes['url'] = $this['spress.config.url'];
         }
         return $attributes;
     };
     $this['spress.config'] = function ($c) {
         return new Configuration($c['lib.configLoader'], $c['spress.config.default_filename']);
     };
     $this['lib.configLoader'] = function ($c) {
         $locator = new FileLocator([]);
         return new Config([new \Yosymfony\ConfigLoader\Loaders\YamlLoader($locator), new \Yosymfony\ConfigLoader\Loaders\JsonLoader($locator)]);
     };
     $this['lib.eventDispatcher'] = function ($c) {
         return new EventDispatcher();
     };
     $this['lib.twig.loader_array'] = function ($c) {
         return new \Twig_Loader_Array([]);
     };
     $this['lib.twig.options'] = function ($c) {
         return ['autoescape' => false, 'debug' => $c['spress.config.values']['debug']];
     };
     $this['lib.twig'] = function ($c) {
         $options = $c['lib.twig.options'];
         $twig = new \Twig_Environment($c['lib.twig.loader_array'], $options);
         if ($options['debug'] === true) {
             $twig->addExtension(new \Twig_Extension_Debug());
         }
         return $twig;
     };
     $this['lib.embeddedComposer'] = function ($c) {
         $embeddedComposerBuilder = new EmbeddedComposerBuilder($c['spress.plugin.classLoader'], $c['spress.config.site_dir']);
         $embeddedComposer = $embeddedComposerBuilder->setComposerFilename($c['spress.config.composer_filename'])->setVendorDirectory($c['spress.config.vendor_dir'])->build();
         return $embeddedComposer;
     };
     $this['spress.io'] = function ($c) {
         return new NullIO();
     };
     $this['spress.plugin.classLoader'] = function ($c) {
         $autoloaders = spl_autoload_functions();
         return $autoloaders[0][0];
     };
     $this['spress.plugin.pluginManager'] = function ($c) {
         $pathComposerFilename = $c['spress.config.site_dir'] . '/' . $c['spress.config.composer_filename'];
         if (file_exists($pathComposerFilename) === true) {
             $embeddedComposer = $c['lib.embeddedComposer'];
             $embeddedComposer->processAdditionalAutoloads();
         }
         $excludePath = $c['spress.config.values']['plugin_manager_builder']['exclude_path'];
         $builder = new PluginManagerBuilder($c['spress.config.plugin_dir'], $c['lib.eventDispatcher'], $excludePath);
         return $builder->build();
     };
     $this['spress.dataWriter'] = function ($c) {
         $fs = new Filesystem();
         return new FilesystemDataWriter($fs, $c['spress.config.build_dir']);
     };
     $this['spress.dataSourceManager.parameters'] = function ($c) {
         return ['%site_dir%' => $c['spress.config.site_dir'], '%include%' => $c['spress.config.values']['include'], '%exclude%' => $c['spress.config.values']['exclude'], '%text_extensions%' => $c['spress.config.values']['text_extensions'], '%attribute_syntax%' => $c['spress.config.values']['attribute_syntax'], '%avoid_renderizer_path%' => $c['spress.config.values']['avoid_renderizer']['paths'], '%avoid_renderizer_extension%' => $c['spress.config.values']['avoid_renderizer']['filename_extensions']];
     };
     $this['spress.dataSourceManager'] = function ($c) {
         $parameters = $c['spress.dataSourceManager.parameters'];
         $builder = new DataSourceManagerBuilder($parameters);
         $dataSources = $c['spress.config.values']['data_sources'];
         return $builder->buildFromConfigArray($dataSources);
     };
     $this['spress.cms.generatorManager'] = function ($c) {
         $pagination = new \Yosymfony\Spress\Core\ContentManager\Generator\Pagination\PaginationGenerator();
         $taxonomy = new \Yosymfony\Spress\Core\ContentManager\Generator\Taxonomy\TaxonomyGenerator();
         $manager = new GeneratorManager();
         $manager->addGenerator('pagination', $pagination);
         $manager->addGenerator('taxonomy', $taxonomy);
         return $manager;
     };
     $this['spress.cms.converterManager.converters'] = function ($c) {
         $markdownExts = $c['spress.config.values']['markdown_ext'];
         $extensionMappingTable = $c['spress.config.values']['map_converter_extension'];
         return ['MapConverter' => new \Yosymfony\Spress\Core\ContentManager\Converter\MapConverter($extensionMappingTable), 'MichelfMarkdownConverter' => new \Yosymfony\Spress\Core\ContentManager\Converter\MichelfMarkdownConverter($markdownExts)];
     };
     $this['spress.cms.converterManager'] = function ($c) {
         $cm = new ConverterManager($c['spress.config.values']['text_extensions']);
         $converters = $c['spress.cms.converterManager.converters'];
         foreach ($converters as $converter) {
             $cm->addConverter($converter);
         }
         return $cm;
     };
     $this['spress.cms.collectionManager'] = function ($c) {
         $builder = new CollectionManagerBuilder();
         return $builder->buildFromConfigArray($c['spress.config.values']['collections']);
     };
     $this['spress.cms.permalinkGenerator'] = function ($c) {
         $permalink = $c['spress.config.values']['permalink'];
         $preservePathTitle = $c['spress.config.values']['preserve_path_title'];
         $noHtmlExtension = $c['spress.config.values']['no_html_extension'];
         return new PermalinkGenerator($permalink, $preservePathTitle, $noHtmlExtension);
     };
     $this['spress.cms.renderizer'] = function ($c) {
         $twig = $c['lib.twig'];
         $loader = $c['lib.twig.loader_array'];
         $layoutExts = $c['spress.config.values']['layout_ext'];
         return new TwigRenderizer($twig, $loader, $layoutExts);
     };
     $this['spress.cms.siteAttribute'] = function ($c) {
         return new SiteAttribute();
     };
     $this['spress.cms.contentManager'] = $this->factory(function ($c) {
         return new ContentManager($c['spress.dataSourceManager'], $c['spress.dataWriter'], $c['spress.cms.generatorManager'], $c['spress.cms.converterManager'], $c['spress.cms.collectionManager'], $c['spress.cms.permalinkGenerator'], $c['spress.cms.renderizer'], $c['spress.cms.siteAttribute'], $c['spress.plugin.pluginManager'], $c['lib.eventDispatcher'], $c['spress.io']);
     });
 }