/** * Template constructor. * * @param Container $container */ public function __construct(Container $container) { $settings = $container->get('settings'); $compiledPath = $settings['storagePath'] . DIRECTORY_SEPARATOR . 'views'; $resolver = new EngineResolver(); $resolver->register('blade', function () use($compiledPath, &$settings) { $bladeCompiler = new BladeCompiler(new Filesystem(), $compiledPath); // Add the @webroot directive. $bladeCompiler->directive('webroot', function ($expression) use(&$settings) { $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression)); $path = rtrim($settings['webrootBasePath'], '/') . '/' . ltrim($segments[0], '/'); $path = str_replace("'", "\\'", $path); return "<?= e('{$path}') ?>"; }); // Add the @route directive. $bladeCompiler->directive('route', function ($expression) use(&$settings) { $segments = explode(',', preg_replace("/[\\(\\)\\\"\\']/", '', $expression)); $path = rtrim($settings['routeBasePath'], '/') . '/' . ltrim($segments[0], '/'); $path = str_replace("'", "\\'", $path); return "<?= e('{$path}') ?>"; }); return new CompilerEngine($bladeCompiler); }); $finder = new FileViewFinder(new Filesystem(), [$settings['templatePath']]); $factory = new ViewFactory($resolver, $finder, new Dispatcher()); $this->factory = $factory; $this->container = $container; }
public function __construct() { $this->instance('container', $this); $this->singleton('events', function () { return new Dispatcher(); }); $this->singleton('files', function () { return new Filesystem(); }); $this->singleton('blade.compiler', function () { return new BladeCompiler($this['files'], $this['view.compiled']); }); $this->singleton('view.engine.resolver', function () { $resolver = new EngineResolver(); $resolver->register('blade', function () { return new CompilerEngine($this['blade.compiler'], $this['files']); }); $resolver->register('php', function () { return new PhpEngine(); }); return $resolver; }); $this->singleton('view.finder', function () { return new FileViewFinder($this['files'], $this['view.paths']); }); $this->singleton('view', function () { $env = new Factory($this['view.engine.resolver'], $this['view.finder'], $this['events']); $env->setContainer($this['container']); return $env; }); }
/** * Register the Twig engine to the EngineResolver. * * @param string $engine * @param EngineResolver $resolver */ protected function registerTwigEngine($engine, EngineResolver $resolver) { $container = $this->app; $resolver->register($engine, function () use($container) { // Set the loader main namespace (paths). $container['twig.loader']->setPaths($container['view.finder']->getPaths()); return new TwigEngine($container['twig'], $container['view.finder']); }); }
protected function setUp() { parent::setUp(); $this->mock_view_finder = Mockery::mock('Illuminate\\View\\ViewFinderInterface')->shouldIgnoreMissing(); $this->mock_engine_resolver = Mockery::mock('Illuminate\\View\\Engines\\EngineResolver')->shouldIgnoreMissing(); $this->mock_translator = Mockery::mock('\\Illuminate\\Translation\\Translator')->shouldIgnoreMissing(); $this->mock_session = Mockery::mock('\\Illuminate\\Session\\Store')->shouldIgnoreMissing(); $this->mock_dispatcher = Mockery::mock('\\Illuminate\\Contracts\\Events\\Dispatcher')->shouldIgnoreMissing(); $this->mock_engine_resolver->shouldReceive('resolve')->andReturn(Mockery::mock('\\Illuminate\\View\\Engines\\EngineInterface')->shouldIgnoreMissing()); $this->factory = new Factory($this->mock_engine_resolver, $this->mock_view_finder, $this->mock_dispatcher, $this->mock_translator); $this->factory->setSession($this->mock_session); }
/** * Register the Jade engine implementation. * * @param \Illuminate\View\Engines\EngineResolver $resolver */ public function registerJadeEngine(EngineResolver $resolver) { $app = $this->app; $app->singleton('jade.compiler', function ($app) { $cache = $app['config']['view.compiled']; return new JadeCompiler($app['files'], $cache); }); $resolver->register('jade', function () use($app) { return new CompilerEngine($app['jade.compiler'], $app['files']); }); $app['view']->addExtension('jade.php', 'jade'); }
public function __construct($viewsDir, $cacheDir) { $filesystem = new Filesystem(); $engineResolver = new EngineResolver(); $engineResolver->register('blade', function () use($filesystem, $cacheDir) { return new CompilerEngine(new BladeCompiler($filesystem, $cacheDir)); }); $factory = new Factory($engineResolver, new FileViewFinder($filesystem, [$viewsDir]), new Dispatcher()); $this->factory = $factory; $this->viewsDir = $viewsDir; $this->filesystem = $filesystem; }
/** * Constructor. * * @param Factory $renderer Rendering engine * * @since __DEPLOY_VERSION__ */ public function __construct(Factory $renderer = null) { if (!$renderer) { $filesystem = new Filesystem(); $resolver = new EngineResolver(); $resolver->register('blade', function () use($filesystem) { return new CompilerEngine(new BladeCompiler($filesystem, getcwd() . '/cache')); }); $renderer = new Factory($resolver, new FileViewFinder($filesystem, []), new Dispatcher()); } $this->renderer = $renderer; }
/** * Register the Blade engine implementation. * * @param \Illuminate\View\Engines\EngineResolver $resolver * @return void */ public function registerBladeEngine($resolver) { $app = $this->app; $resolver->register('blade', function () use($app) { $cache = $app['path.storage'] . '/views'; // The Compiler engine requires an instance of the CompilerInterface, which in // this case will be the Blade compiler, so we'll first create the compiler // instance to pass into the engine so it can compile the views properly. $compiler = new BladeCompiler($app['files'], $cache); return new CompilerEngine($compiler, $app['files']); }); }
/** * Register the Markdown engine implementation. * * @param EngineResolver $resolver * @return void */ public function registerMarkdownEngine($resolver) { $app = $this->app; $resolver->register('markdown', function () use($app) { $cache = storage_path() . '/markdown'; if (!File::isDirectory($cache)) { File::makeDirectory($cache); } $compiler = new MarkdownCompiler($app['files'], $cache); $compiler->setOptions(Config::get('markdown.options')); return new CompilerEngine($compiler, $app['files']); }); }
/** * Register the application services. * * @return void */ public function register() { $this->app->bind('minit', function () { return new \Minit\Engine(); }); $this->app->singleton('view.engine.resolver', function () { $resolver = new EngineResolver(); $resolver->register('php', function () { return new \Minit\Engine(); }); return $resolver; }); }
/** * Register the Blade engine implementation. * * @param \Illuminate\View\Engines\EngineResolver $resolver * @return void */ public function registerBladeEngine($resolver) { $app = $this->app; // The Compiler engine requires an instance of the CompilerInterface, which in // this case will be the Blade compiler, so we'll first create the compiler // instance to pass into the engine so it can compile the views properly. $app->singleton('blade.compiler', function ($app) { $cache = $app['config']['view.compiled']; return new BladeCompiler($app['files'], $cache); }); $resolver->register('blade', function () use($app) { return new CompilerEngine($app['blade.compiler']); }); }
/** * Register the engine resolver instance. * * @return EngineResolver */ public function getEngineResolver() { $resolver = new EngineResolver(); // Add PhpEngine $resolver->register('php', function () { return new PhpEngine(); }); // Add Blade compiler engine $resolver->register('blade', function () { $compiler = new BladeCompiler($this->files, $this->cachePath); return new CompilerEngine($compiler); }); return $resolver; }
/** * Create a new Blade Factory instance * * @param array $view_paths * @param mixed $view_cache_path */ public function __construct(array $view_paths, $view_cache_path = null) { $resolver = new EngineResolver(); $finder = new FileViewFinder(new Filesystem(), $view_paths); $dispatcher = new Dispatcher(); $resolver->register("blade", function () use($view_cache_path) { if (!is_dir($view_cache_path)) { mkdir($view_cache_path, 0777, true); } $blade = new BladeCompiler(new Filesystem(), $view_cache_path); return new CompilerEngine($blade); }); parent::__construct($resolver, $finder, $dispatcher); }
protected function makeView() { $app = new Container(); $resolver = new EngineResolver(); $resolver->register('php', function () { return new PhpEngine(); }); $finder = new FileViewFinder(new Filesystem(), [realpath(__DIR__)]); $dispatcher = (new Dispatcher($app))->setQueueResolver(function () use($app) { return $app->make('Illuminate\\Contracts\\Queue\\Factory'); }); $env = new Factory($resolver, $finder, $dispatcher); $env->setContainer($app); $env->share('app', $app); return new Illuminate($env); }
/** * Register a valid Markdown extension and its engine. * * @param string $extension * @param string $engine * @param Closure $resolver * @return void */ public function addExtension($extension, $engine, $resolver = null) { $this->finder->addExtension($extension); if (isset($resolver)) { $this->engines->register($engine, $resolver); } $this->extensions[$extension] = $engine; }
/** * Get the laravel view factory. * * @return Factory */ protected function getViewFactory() { if ($this->factory) { return $this->factory; } $resolver = new EngineResolver(); $resolver->register("blade", function () { if (!is_dir($this->cache)) { mkdir($this->cache, 0777, true); } $blade = new BladeCompiler(new Filesystem(), $this->cache); Blade::registerDirectives($blade); return new CompilerEngine($blade); }); $this->factory = new Factory($resolver, $this->getViewFinder(), new Dispatcher()); return $this->factory; }
/** * Register the mustache engine implementation. * * @param \Illuminate\View\Engines\EngineResolver $resolver * @return void */ public function registerHandlebarsEngine($resolver) { $app = $this->app; // The Compiler engine requires an instance of the CompilerInterface, which in // this case will be the Handlebars compiler, so we'll first create the compiler // instance to pass into the engine so it can compile the views properly. $app->singleton('handlebars.lightncandy', function ($app) { return new LightnCandy(); }); $app->singleton('handlebars.compiler', function ($app) { $cache = $app['config']['view.compiled']; return new HandlebarsCompiler($app['files'], $app['handlebars.lightncandy'], $cache); }); $resolver->register('handlebars', function () use($app) { return new HandlebarsEngine($app['handlebars.compiler']); }); }
/** * Create the view factory with a Blade Compiler. * * @return Factory */ private function createViewFactory() { $resolver = new EngineResolver(); $bladeCompiler = $this->createBladeCompiler(); $resolver->register('blade', function () use($bladeCompiler) { return new CompilerEngine($bladeCompiler); }); $dispatcher = new Dispatcher(); $dispatcher->listen('creating: *', function () { /** * On rendering Blade views we will mute error reporting as * we don't care about undefined variables or type * mistakes during compilation. */ error_reporting(error_reporting() & ~E_NOTICE & ~E_WARNING); }); return new Factory($resolver, new FileViewFinder($this->filesystem, [KATANA_CONTENT_DIR]), $dispatcher); }
/** * Register a valid view extension and its engine. * * @param string $extension * @param string $engine * @param \Closure $resolver * @return void */ public function addExtension($extension, $engine, $resolver = null) { $this->finder->addExtension($extension); if (isset($resolver)) { $this->engines->register($engine, $resolver); } unset($this->extensions[$extension]); $this->extensions = array_merge([$extension => $engine], $this->extensions); }
/** * Method to get property Resolver * * @return EngineResolver */ public function getResolver() { if (!$this->resolver) { $self = $this; $this->resolver = new EngineResolver(); $this->resolver->register('blade', function () use($self) { return $self->getCompiler(); }); } return $this->resolver; }
/** * Register the LESS engine implementation. * * @param Illuminate\View\Engines\EngineResolver $resolver * @return void */ public function registerLessEngine($resolver) { $app = $this->app; $resolver->register('less', function () use($app) { $cache = storage_path() . '/less'; if (!File::isDirectory($cache)) { File::makeDirectory($cache); } $compiler = new LessCompiler(app('files'), $cache); return new CompilerEngine($compiler, app('files')); }); }
/** * @return \Illuminate\View\Factory */ protected function createViewFactory() { $FileViewFinder = new FileViewFinder(new Filesystem(), [realpath(__DIR__ . '/ConfigMigrations/templates')]); $dispatcher = new Dispatcher(new Container()); $compiler = new BladeCompiler(new Filesystem(), storage_path() . '/framework/views'); $bladeEngine = new CompilerEngine($compiler); $engineResolver = new EngineResolver(); $engineResolver->register('blade', function () use(&$bladeEngine) { return $bladeEngine; }); $viewFactory = new \Illuminate\View\Factory($engineResolver, $FileViewFinder, $dispatcher); return $viewFactory; }
/** * Registers services on the given container. * * This method should only be used to configure services and parameters. * It should not get services. * * @param Container $pimple A container instance */ public function register() { /* * application default view * * @param $c container * @return Factory view Factory */ $this->app['view'] = function ($c) { $viewResolver = new EngineResolver(); $compiler = new BladeCompiler($c['filesystem'], $this->app->basePath() . '/storage/view'); $filesystem = $c['filesystem']; $viewResolver->register('blade', function () use($compiler, $filesystem) { return new CompilerEngine($compiler, $filesystem); }); $viewResolver->register('php', function () { return new PhpEngine(); }); $viewFinder = new FileViewFinder($filesystem, [$this->app->path . '/View']); $viewFactory = new Factory($viewResolver, $viewFinder, new Dispatcher()); return $viewFactory; }; }
/** * @param Container $app */ public function register(Container $app) { // we only need to do this if Blade views are enabled. if ($app['config']['view.blade.enabled']) { $app['blade.settings'] = $app['config']['view.blade.defaults']; $app['blade.template.paths'] = $app['blade.settings']['template_paths']; $app['files'] = function () { return new Filesystem(); }; $app['view.finder'] = function ($app) { return new FileViewFinder(new Filesystem(), $app['blade.template.paths']); }; // create the Blade compiler using Filesystem and cache directory $app['blade.compiler'] = function ($app) { return new BladeCompiler(new Filesystem(), $app['blade.settings']['cache']); }; // get a blade compiler engine instance $app['blade.engine'] = function ($app) { return new CompilerEngine($app['blade.compiler']); }; $app['view.engine.resolver'] = function ($app) { $resolver = new EngineResolver(); $resolver->register('php', function () { return new PhpEngine(); }); $resolver->register('blade', function () use($app) { return new CompilerEngine($app['blade.compiler'], $app['files']); }); return $resolver; }; $app['blade.factory'] = function ($app) { $view_factory = new IlluminateViewFactory($app['view.engine.resolver'], $app['view.finder'], $app['illuminate.events']); $view_factory->setContainer($app['nine.container']); return $view_factory; }; } }
/** * Register the service provider. * * @return void */ public function register() { $app = $this->app; $this->mergeConfigFrom($this->configPath(), 'view-docblock'); if ($this->app->environment() === 'production' && !$app['config']['view-docblock.enable_production']) { return; } $app->bind(TokenParserInterface::class, TokenParser::class); # Support additional types via configuration $app->singleton(ArgumentValidation::class, function ($app) { $validator = new ArgumentValidation(TypeDescriptionParser::class, $app['config']['view-docblock.report_missing_arguments']); foreach ($app['config']['view-docblock.additional_types'] as $typeClass => $aliases) { $type = $app[$typeClass]; if (empty($aliases)) { $validator->registerType($type); } else { $aliases = !is_array($aliases) ? [$aliases] : $aliases; foreach ($aliases as $alias) { $validator->registerTypeAs($type, $alias); } } } return $validator; }); # From here on mimic behaviour of # \Illuminate\View\ViewServiceProvider $app->singleton('blade.compiler', function ($app) { $cache = $app['config']['view.compiled']; return new BladeCompiler($app['files'], $cache); }); # Override default engines $app->singleton('view.engine.resolver', function ($app) { $resolver = new EngineResolver(); $resolver->register('php', function () use($app) { return new PhpEngine($app[Parser::class], $app[ExtractFromDocblock::class], $app[ArgumentValidation::class], $app['config']->get('view-docblock.require_docblock_on_data'), $app['config']->get('view-docblock.argument_blacklist')); }); $resolver->register('blade', function () use($app) { return new CompilerEngine($app['blade.compiler'], $app[Parser::class], $app[ExtractFromDocblock::class], $app[ArgumentValidation::class], $app['config']->get('view-docblock.require_docblock_on_data'), $app['config']->get('view-docblock.argument_blacklist')); }); return $resolver; }); }
/** * Register the Blade engine implementation. * * @param EngineResolver $resolver * * @return void */ public function registerBladeEngine($resolver) { $me = $this; $app = $this->container; $this->container->singleton('blade.compiler', function ($app) use($me) { $cache = $me->cachePath; return new BladeCompiler($app['files'], $cache); }); $resolver->register('blade', function () use($app) { return new CompilerEngine($app['blade.compiler'], $app['files']); }); }
public static function blade(array $data, $debug = true) { $resolver = new EngineResolver(); $files = new Filesystem(); $compiler = new BladeCompiler($files, static::$cacheDirectory); $engine = new CompilerEngine($compiler); $resolver->register('blade', function () use($engine) { return $engine; }); /** @var Restler $restler */ $restler = Scope::get('Restler'); //Lets expose shortcuts for our classes spl_autoload_register(function ($className) use($restler) { if (isset($restler->apiMethodInfo->metadata['scope'][$className])) { return class_alias($restler->apiMethodInfo->metadata['scope'][$className], $className); } if (isset(Scope::$classAliases[$className])) { return class_alias(Scope::$classAliases[$className], $className); } return false; }, true, true); $viewFinder = new FileViewFinder($files, array(static::$viewPath)); $factory = new Factory($resolver, $viewFinder, new Dispatcher()); $path = $viewFinder->find(self::$view); $view = new View($factory, $engine, self::$view, $path, $data); $factory->callCreator($view); return $view->render(); }
/** * Register the Blade engine implementation. * * @param \Illuminate\View\Engines\EngineResolver $resolver * @return void */ public function registerBladeEngine(EngineResolver $resolver) { $container = $this->getContainer(); $container->bindShared('blade.compiler', function () { return new BladeCompiler($this->getFilesystem(), $this->getStoragePath()); }); $resolver->register('blade', function () use($container) { return new CompilerEngine($container['blade.compiler'], $this->getFilesystem()); }); }
/** * Register the Blade engine implementation. * * @param \Illuminate\View\Engines\EngineResolver $resolver * @return void */ public function registerBladeEngine($resolver) { $me = $this; $app = $this->container; // The Compiler engine requires an instance of the CompilerInterface, which in // this case will be the Blade compiler, so we'll first create the compiler // instance to pass into the engine so it can compile the views properly. $this->container->bindShared('blade.compiler', function ($app) use($me) { $cache = $me->cachePath; return new BladeCompiler($app['files'], $cache); }); $resolver->register('blade', function () use($app) { return new CompilerEngine($app['blade.compiler'], $app['files']); }); }
public function configView() { $engineResolver = new EngineResolver(); $engineResolver->register('php', function () { return new PhpEngine(); }); $this->app->singleton('blade.compiler', function ($app) { $cachePath = $this->basePath . "/storage/framework/views"; return new BladeCompiler(new Filesystem(), $cachePath); }); $engineResolver->register('blade', function () { return new CompilerEngine($this->app['blade.compiler']); }); $fileViewFinder = new FileViewFinder(new Filesystem(), [], null); $this->viewFactory = new Factory($engineResolver, $fileViewFinder, new Dispatcher()); $fileViewFinder->addLocation($this->basePath . "/resources/views"); }