Exemplo n.º 1
0
 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;
     });
 }
Exemplo n.º 2
0
 public function register(Container $pimple)
 {
     $pimple['files'] = function () {
         return new Filesystem();
     };
     $pimple['view.engine.resolver'] = function () use($pimple) {
         $resolver = new EngineResolver();
         foreach (['php', 'blade'] as $engine) {
             $this->{'register' . ucfirst($engine) . 'Engine'}($resolver, $pimple);
         }
         return $resolver;
     };
     $pimple['view.finder'] = function () use($pimple) {
         $paths = $pimple['config']['view.paths'];
         return new FileViewFinder($pimple['files'], $paths);
     };
     $pimple['view'] = function () use($pimple) {
         // Next we need to grab the engine resolver instance that will be used by the
         // environment. The resolver will be used by an environment to get each of
         // the various engine implementations such as plain PHP or Blade engine.
         $resolver = $pimple['view.engine.resolver'];
         $finder = $pimple['view.finder'];
         $env = new Factory($resolver, $finder, $pimple['events']);
         // We will also set the container instance on this view environment since the
         // view composers may be classes registered in the container, which allows
         // for great testable, flexible composers for the application developer.
         $env->setContainer($pimple['container']);
         $env->share('app', $pimple);
         return $env;
     };
 }
Exemplo n.º 3
0
 /**
  * Make the view content.
  *
  * @param PageInterface $page
  */
 public function make(PageInterface $page)
 {
     $type = $page->getType();
     /* @var EditorFieldType $layout */
     $layout = $type->getFieldType('layout');
     $page->setContent($this->view->make($layout->getViewPath(), compact('page'))->render());
 }
Exemplo n.º 4
0
 /**
  * Init controller.
  * @param Backend $backend
  * @param ViewFactory $view
  */
 public function init(Backend $backend, ViewFactory $view)
 {
     $backend->setActiveMenu('system.groups');
     $view->composer($this->viewName('groups.form'), function (View $view) use($backend) {
         $view->with('rules', $backend->getAclGroups());
     });
 }
Exemplo n.º 5
0
 /**
  * Bootstrap the application services
  *
  * @param ViewFactory $viewFactory
  */
 public function boot(ViewFactory $viewFactory)
 {
     if (is_dir(base_path() . '/resources/views/viktorv/lpanel')) {
         $this->loadViewsFrom(base_path() . '/resources/views/viktorv/lpanel', 'lpanel');
     } else {
         $path = realpath(__DIR__ . '/../resources/views');
         /** @var \League\Plates\Engine $platesEngine */
         $platesEngine = $this->app->make('League\\Plates\\Engine');
         $platesEngine->setDirectory($path);
         $platesEngine->addFolder('layout', $path . '/admin/layout');
         $platesEngine->addFolder('noscript', $path . '/noscript');
         $this->loadViewsFrom($path, 'lpanel');
     }
     /** @var \Illuminate\Validation\Factory $validator */
     $validator = $this->app->validator;
     $validator->resolver(function ($translator, $data, $rules, $messages) {
         return new Validator($translator, $data, $rules, $messages);
     });
     $viewFactory->share('block', new BaseBlock($this->app));
     if (is_dir(base_path() . '/resources/lang/viktorv/lpanel')) {
         $this->loadTranslationsFrom(base_path() . '/resources/lang/viktorv/lpanel', 'lpanel');
     } else {
         $this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'lpanel');
     }
 }
Exemplo n.º 6
0
 public function getReset($token = null)
 {
     if (is_null($token)) {
         $this->application->abort(404);
     }
     return $this->view->make('UserManagement::password.reset')->with('token', $token);
 }
Exemplo n.º 7
0
 public function anyUpload(InterfaceFileStorage $userFileStorage, AmqpWrapper $amqpWrapper, Server $server, UploadEntity $uploadEntity)
 {
     /* @var \App\Components\UserFileStorage $userFileStorage */
     $responseVariables = ['uploadStatus' => false, 'storageErrors' => [], 'uploadEntities' => []];
     if ($this->request->isMethod('post') && $this->request->hasFile('file') && $this->request->file('file')->isValid()) {
         $tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tmp-user-files-to-storage' . DIRECTORY_SEPARATOR;
         $tmpFilePath = $tmpDir . $this->request->file('file')->getClientOriginalName();
         $this->request->file('file')->move($tmpDir, $this->request->file('file')->getClientOriginalName());
         $userFileStorage->setValidationRules($this->config->get('storage.userfile.validation'));
         $newStorageFile = $userFileStorage->addFile($tmpFilePath);
         if ($newStorageFile && !$userFileStorage->hasErrors()) {
             /* @var \SplFileInfo $newStorageFile */
             // AMQP send $newfile, to servers
             foreach ($server->all() as $server) {
                 if (count($server->configs) > 0) {
                     foreach ($server->configs as $config) {
                         // Send server and file info to upload queue task
                         $amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $config->auth . '@' . $server->host . '/' . trim($config->path, '\\/')]));
                     }
                 } else {
                     // The server has no configuration
                     $amqpWrapper->sendMessage($this->config->get('amqp.queues.uploader.upload'), json_encode(['file' => $newStorageFile->getRealPath(), 'url' => $server->scheme . '://' . $server->host]));
                 }
             }
             $responseVariables['uploadStatus'] = true;
         } else {
             $responseVariables['storageErrors'] = $userFileStorage->getErrors();
         }
         if ($this->request->ajax()) {
             return $this->response->json($responseVariables);
         }
     }
     $responseVariables['uploadEntities'] = $uploadEntity->limit(self::UPLOAD_ENTITIES_LIMIT)->orderBy('created_at', 'DESC')->get();
     return $this->view->make('upload.index', $responseVariables);
 }
Exemplo n.º 8
0
 /**
  * Controller init.
  * @param Backend $backend
  * @param ViewFactory $view
  */
 public function init(Backend $backend, ViewFactory $view)
 {
     $backend->setActiveMenu('system.users');
     $view->composer($this->viewName('users.form'), function (View $view) {
         $view->with('groups', GroupModel::query()->get());
     });
 }
Exemplo n.º 9
0
 public function __construct(Request $request, Factory $factory)
 {
     $this->request = $request;
     $this->view_path = realpath(base_path('resources/views'));
     $this->factory = $factory;
     $this->finder = $factory->getFinder();
     $this->finder->addExtension('schema.php');
 }
Exemplo n.º 10
0
 /**
  * Displays the login form.
  */
 public function getLogin()
 {
     $viewConfig = $this->config->get('l4-lock::config.lock.views');
     if ($this->view->exists($viewConfig['foot-note'])) {
         $viewConfig['foot-note'] = $this->view->make($viewConfig['foot-note'])->render();
     }
     return $this->view->make($this->config->get('l4-lock::config.lock.views.login'), array('view' => $viewConfig))->render();
 }
Exemplo n.º 11
0
 /**
  * Parse some content.
  *
  * @param $content
  * @return string
  */
 public function parse($content)
 {
     if (!$this->files->isDirectory($path = storage_path('framework/views/asset'))) {
         $this->files->makeDirectory($path);
     }
     $this->files->put(storage_path('framework/views/asset/' . (($filename = md5($content)) . '.twig')), $content);
     return $this->views->make('root::storage/framework/views/asset/' . $filename)->render();
 }
 /**
  * Return an angular template partial.
  *
  * @param  \App\Http\Requests\Api\Angular\TemplateRequest  $request
  * @return \Illuminate\View\View
  */
 public function template(TemplateRequest $request)
 {
     $template = $request->get('template');
     if ($this->viewFactory->exists($template)) {
         return $this->viewFactory->make($template);
     }
     return $this->response()->errorNotFound();
 }
 /**
  * Handle incoming requests.
  * @param Request $request
  * @param \Closure $next
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handle($request, Closure $next)
 {
     if ($this->maintenance->isDownMode()) {
         if ($this->view->exists('errors.503')) {
             return new Response($this->view->make('errors.503'), 503);
         }
         return $this->app->abort(503, 'The application is down for maintenance.');
     }
     return $next($request);
 }
Exemplo n.º 14
0
 /**
  * Composes a message.
  *
  * @return \Illuminate\View\Factory
  */
 public function composeMessage()
 {
     // Attempts to make a view.
     // If a view can not be created; it is assumed that simple message is passed through.
     try {
         return $this->views->make($this->view, $this->data)->render();
     } catch (\InvalidArgumentException $e) {
         return $this->view;
     }
 }
Exemplo n.º 15
0
 /**
  * Plant a new bonsai collection!
  *
  * @param  string  $namespace
  * @param  string  $path
  * @return null
  */
 public function plant($callback = null)
 {
     $assets = new Assets();
     if (is_callable($callback)) {
         call_user_func($callback, $assets);
     }
     $this->collection->put('bonsai', $assets);
     $this->view->share('bonsai', $assets);
     return $assets;
 }
Exemplo n.º 16
0
 /**
  * Returns all social sharing buttons.
  *
  * @return string
  */
 public function all()
 {
     $defaultButtons = Config::get('shareable::default_buttons', array());
     $buttons = array();
     $output = '';
     foreach ($defaultButtons as $button) {
         $buttons[] = call_user_func(array($this, $button));
     }
     return $this->view->make('shareable::all', array('buttons' => $buttons));
 }
Exemplo n.º 17
0
Arquivo: Menu.php Projeto: tok3/menus
 /**
  * Create a new menu instance.
  *
  * @param  string    $name
  * @param  callable  $callback
  * @return \Caffeinated\Menus\Builder
  */
 public function make($name, $callback)
 {
     if (is_callable($callback)) {
         $menu = new Builder($name, $this->loadConfig($name), $this->html, $this->url);
         call_user_func($callback, $menu);
         $this->collection->put($name, $menu);
         $this->view->share('menu_' . $name, $menu);
         return $menu;
     }
 }
Exemplo n.º 18
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $data = ['table' => $this->argument('table'), 'attachment' => $this->argument('attachment'), 'after' => $this->argument('after')];
     // Create filename
     $file = base_path("database/migrations/" . date('Y_m_d_His') . "_add_{$data['attachment']}_fields_to_{$data['table']}_table.php");
     // Save the new migration to disk using the MediaSort migration view.
     $migration = $this->view->file(realpath(__DIR__ . '/../../resources/views/migration.blade.php'), $data)->render();
     $this->file->put($file, $migration);
     // Print a created migration message to the console.
     $this->info("Created migration: {$file}");
 }
Exemplo n.º 19
0
 /**
  * Generate the target file from a stub.
  *
  * @param $stub
  * @param $targetLocation
  */
 protected function compile($stub, $targetLocation)
 {
     $view = $this->view->make("generator.stubs::{$stub}", $this->context->toArray());
     $contents = "<?php\r\n\r\n" . $view->render();
     $targetDir = base_path('/SocialiteProviders/' . $this->context->nameStudlyCase());
     if (!$this->files->isDirectory($targetDir)) {
         $this->files->makeDirectory($targetDir, 0755, true, true);
         $this->files->makeDirectory($targetDir . '/src', 0755, true, true);
     }
     $this->files->put($targetDir . '/' . $targetLocation, $contents);
 }
Exemplo n.º 20
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $this->app->setLocale($this->settings->get('user.language', 'en'));
     $langDir = ['left' => 'left', 'right' => 'right'];
     if (trans('general.direction') == 'rtl') {
         $langDir['left'] = 'right';
         $langDir['right'] = 'left';
     }
     $this->viewFactory->share('langDir', $langDir);
     return $next($request);
 }
Exemplo n.º 21
0
 public function __construct(Request $request, Factory $factory, array $data, $sources = [], $meta = [])
 {
     $this->request = $request;
     $this->data = $data;
     $this->sources = $sources;
     $this->factory = $factory;
     $this->finder = $factory->getFinder();
     if ($meta) {
         $this->data['jsonapi'] = array_filter($meta);
     }
 }
Exemplo n.º 22
0
 /**
  * Return true if compilation expired.
  *
  * @param \Bladerunner\Blade       $blade
  * @param \Illuminate\View\Factory $view
  * @param string                   $path
  */
 public static function expired($blade, $view, $path)
 {
     $result = false;
     $wp_debug = (bool) defined('WP_DEBUG') && true === WP_DEBUG;
     if ($wp_debug) {
         return true;
     }
     $result = $wp_debug || $result;
     $result = !file_exists($path) || $result;
     $result = $blade->getCompiler()->isExpired($view->getPath()) || $result;
     return $result;
 }
Exemplo n.º 23
0
 /**
  * Get the normalized name, for creator/composer events
  *
  * @param  \Illuminate\View\Factory $viewEnvironment
  * @return string
  */
 protected function getNormalizedName($viewEnvironment)
 {
     $paths = $viewEnvironment->getFinder()->getPaths();
     $name = $this->getTemplateName();
     // Replace absolute paths, trim slashes, remove extension
     $name = str_replace($paths, '', $name);
     $name = ltrim($name, '/');
     if (substr($name, -5, 5) === '.twig') {
         $name = substr($name, 0, -5);
     }
     return $name;
 }
Exemplo n.º 24
0
 public function __construct(Store $session, Factory $view)
 {
     $this->session = $session;
     $view->share('flash', $this);
     if ($this->session->has($this->namespace)) {
         $flashed = $this->session->get($this->namespace);
         $this->message = $flashed['message'];
         $this->title = $flashed['title'];
         $this->type = $flashed['type'];
         $this->exists = true;
     }
 }
Exemplo n.º 25
0
 /**
  * Create a new menu instance.
  *
  * @param string   $name
  * @param callable $callback
  *
  * @return \Kiwina\Menu\Menu
  */
 public function make($name, $callback)
 {
     if (is_callable($callback)) {
         $menu = new Builder($name, $this->loadConf($name), $this->html, $this->url);
         // Registering the items
         call_user_func($callback, $menu);
         // Storing each menu instance in the collection
         $this->collection->put($name, $menu);
         // Make the instance available in all views
         $this->view->share($name, $menu);
         return $menu;
     }
 }
Exemplo n.º 26
0
 public function testAddRenderTemplate()
 {
     $this->templateMock2->expects($this->any())->method('setArguments')->will($this->returnValue($this->templateMock2));
     $this->testInstance->add($this->templateMock1, 'first');
     $this->testInstance->add($this->templateMock2, 'second');
     $this->templateMock1->expects($this->once())->method('render')->will($this->returnValue($mock1Val = uniqid()));
     $this->templateMock2->expects($this->any())->method('render')->will($this->returnValue($mock2Val = uniqid()));
     $fakeArgs = ['varName' => uniqid('varName')];
     $this->assertSame($mock1Val, $this->testInstance->straightRender($this->templateMock1));
     $this->assertSame($mock2Val, $this->testInstance->render('second', $fakeArgs));
     $this->viewFactoryMock->expects($this->any())->method('make')->with($viewName = uniqid('viewName'))->will($this->returnValue($this->viewMock));
     $this->assertSame($mock2Val, $this->testInstance->renderOnce('second', $fakeArgs, $viewName));
 }
 /**
  * Send a reset link to the given user.
  *
  * @param  EmailPasswordLinkRequest  $request
  * @param  Illuminate\View\Factory $view
  * @return Response
  */
 public function postEmail(EmailPasswordLinkRequest $request, Factory $view)
 {
     $view->composer('emails.auth.password', function ($view) {
         $view->with(['title' => trans('front/password.email-title'), 'intro' => trans('front/password.email-intro'), 'link' => trans('front/password.email-link'), 'expire' => trans('front/password.email-expire'), 'minutes' => trans('front/password.minutes')]);
     });
     switch ($response = $this->passwords->sendResetLink($request->only('email'), function ($message) {
         $message->subject(trans('front/password.reset'));
     })) {
         case PasswordBroker::RESET_LINK_SENT:
             return redirect()->back()->with('status', trans($response));
         case PasswordBroker::INVALID_USER:
             return redirect()->back()->with('error', trans($response));
     }
 }
Exemplo n.º 28
0
 /**
  * Handle the command.
  *
  * @param PageRepositoryInterface $pages
  * @return null|PageInterface
  */
 public function handle(PageRepositoryInterface $pages, Factory $view)
 {
     $options = $this->options;
     /* @var PageCollection $pages */
     $pages = $pages->sorted();
     $pages = $pages->visible();
     $this->dispatch(new SetParentRelations($pages));
     $this->dispatch(new RemoveRestrictedPages($pages));
     if ($root = $options->get('root')) {
         if ($page = $this->dispatch(new GetPage($root))) {
             $options->put('parent', $page);
         }
     }
     return $view->make($options->get('view', 'anomaly.module.pages::nav'), compact('pages', 'options'))->render();
 }
Exemplo n.º 29
0
 /**
  * Compile the view at the given path.
  *
  * @param  string  $path
  * @return void
  */
 public function compile($path)
 {
     // View finder.
     $finder = $this->view->getFinder();
     // Get the list of view paths from the app.
     $paths = $finder->getPaths();
     // Get hints.
     $hints = $finder->getHints();
     // Get current theme uses.
     $currentThemeUses = \Theme::getThemeNamespace();
     if (isset($hints[$currentThemeUses])) {
         $paths = array_merge($paths, $hints[$currentThemeUses]);
     }
     // Get the directory the requested view sits in.
     $viewdir = dirname($path);
     // Match it to a view path registered in config::view.paths
     foreach ($paths as $dir) {
         if (stristr($viewdir, $dir)) {
             $path = str_replace($dir . '/', '', $path);
             break;
         }
     }
     // Create a loader for this template.
     $loader = new Twig_Loader_Filesystem($paths);
     // Instance compiler.
     $twig = $this->getTwigCompiler($loader);
     return $twig->render($path, $this->data);
 }
Exemplo n.º 30
0
 /**
  * Flush all of the section contents if done rendering.
  *
  * @return SectionsTrait
  */
 public function flushSectionsIfDoneRendering()
 {
     if ($this->viewFactory->doneRendering()) {
         $this->flushSections();
         return $this;
     }
 }