/** * Get session bag * * @throws Exception * @throws \Rad\DependencyInjection\Exception\ServiceNotFoundException * * @return SessionBag */ public function getSessionBag() { if (null === $this->sessionBag) { if (!$this->container) { throw new Exception('A container object is required to access the \'session_bag\' service.'); } $this->sessionBag = $this->container->get('session_bag', [$this->bagName]); } return $this->sessionBag; }
/** * Initialize session bag * * @throws Exception * @throws \Rad\DependencyInjection\Exception\ServiceNotFoundException */ public function initialize() { if (false === $this->initialized) { if (!$this->container) { throw new Exception('A container object is required to access the \'session\' service.'); } $this->session = $this->container->get('session'); $this->data = $this->session->get($this->name, []); $this->initialized = true; } }
/** * Get container * * @return Container */ public function getContainer() { if (!is_object($this->container)) { return $this->container = Container::getInstance(); } return $this->container; }
protected function getFile() { $request = Container::get('request'); /** @var UploadedFile $file */ $file = $request->getUploadedFiles()['form']['csv_file']; return $file->getFile(); }
/** * Get form * * @param Category $category * * @return \Symfony\Component\Form\Form * @throws \Rad\DependencyInjection\Exception\ServiceNotFoundException */ public function getForm(Category $category = null) { $data = null; if ($category) { $data = $category->toArray(); } $action = $category ? Container::get('router')->generateUrl(['categories', $data['id']]) : Container::get('router')->generateUrl(['categories']); $formFactory = Forms::createFormFactory(); $options = ['action' => $action, 'method' => $category ? 'PUT' : 'POST']; $event = $this->getEventManager()->dispatch(self::EVENT_CATEGORIES_FORM_SCOPE, $this); /** @var CategoriesTable $categoriesTable */ $categoriesTable = TableRegistry::get('Categories.Categories'); $treeList = $categoriesTable->find('treeList'); if (!empty($category)) { $treeList->where(['id !=' => $data['id']]); } $formBuilder = $formFactory->createBuilder('form', $data, $options)->add('title', 'text', ['required' => true, 'attr' => ['class' => 'form-control']])->add('slug', 'text', ['required' => true, 'attr' => ['class' => 'form-control']])->add('parent_id', 'choice', ['choices' => $treeList->toArray(), 'empty_data' => null, 'empty_value' => 'No Parent', 'label' => 'Parent', 'required' => false]); if (!empty($event->getResult())) { $choices = $event->getResult(); if (!is_array($choices)) { $choices = [$choices]; } $formBuilder->add('scope', 'choice', ['choices' => $choices, 'label' => 'Group']); } return $formBuilder->add('description', 'textarea', ['required' => false, 'attr' => ['class' => 'form-control wysiwyg']])->add('submit', 'submit')->getForm(); }
public static function addMasterTwig($masterTwig) { /** @var Registry $registry */ $registry = Container::get('registry'); $result = $registry->get(self::MASTER_TWIG, self::TWIG_REGISTRY_SCOPE); $result[] = $masterTwig; $registry->set(self::MASTER_TWIG, $result, self::TWIG_REGISTRY_SCOPE); }
/** * Get form * * @return \Symfony\Component\Form\Form * @throws \Rad\DependencyInjection\Exception\ServiceNotFoundException */ public function getForm() { if ($this->form) { return $this->form; } /** @var FormFactory $formFactory */ $formFactory = $this->getContainer()->get('form_factory'); $options = ['action' => Container::get('router')->generateUrl(['users', 'login']), 'method' => 'POST']; return $this->form = $formFactory->createBuilder('form', null, $options)->add('username', 'text', ['required' => false, 'constraints' => new NotBlank()])->add('password', 'password', ['required' => false, 'constraints' => new NotBlank()])->add('login', 'submit')->getForm(); }
/** * @param Entity $page * * @return \Symfony\Component\Form\Form * @throws \Rad\DependencyInjection\Exception\ServiceNotFoundException */ public static function getForm($page = null) { $data = null; if ($page) { $data = $page->toArray(); } $action = $page ? Container::get('router')->generateUrl(['pages', $data['slug']]) : Container::get('router')->generateUrl(['pages']); $formFactory = Forms::createFormFactory(); $options = ['action' => $action, 'method' => $page ? 'PUT' : 'POST']; return $formFactory->createBuilder('form', $data, $options)->add('title', 'text', ['required' => true, 'attr' => ['class' => 'form-control']])->add('slug', 'text', ['required' => true, 'attr' => ['class' => 'form-control']])->add('body', 'textarea', ['required' => true, 'attr' => ['class' => 'form-control wysiwyg']])->add('submit', 'submit')->getForm(); }
/** * Run console application * * @param Event $event * * @throws \Rad\DependencyInjection\Exception */ public function runConsoleApplication(Event $event) { /** @var Router $router */ $router = Container::get('router'); if ($router->getBundle() !== 'migrations') { return; } if (!defined('PHINX_VERSION')) { define('PHINX_VERSION', 0 === strpos('@PHINX_VERSION@', '@PHINX_VERSION') ? '0.4.1' : '@PHINX_VERSION@'); } array_shift($_SERVER['argv']); if ($_SERVER['argv']) { $path = $_SERVER['argv'][0]; unset($_SERVER['argv'][0]); $_SERVER['argv'] = array_merge(explode(':', $path), $_SERVER['argv']); } $app = new ConsoleApplication('Migrations plugin, based on Phinx by Rob Morgan.', PHINX_VERSION); $app->add(new Status()); $app->add(new Create()); $app->add(new Migrate()); $app->add(new Rollback()); $app->run(); }
/** * If user has at least ONE resource of the resources, return TRUE * @param $resources * * @return bool */ private static function userHasResource($resources) { if (!is_array($resources)) { $resources = [$resources]; } $container = Container::getInstance(); /** @var Rbac $rbac */ $rbac = $container->get('rbac'); /** @var Auth $auth */ $auth = $container->get('auth'); foreach ($resources as $resource) { foreach ($auth->getStorage()->read()['roles'] as $roleName) { if (true === $rbac->isGranted($roleName, $resource)) { return true; } } } return false; }
/** * Get Event Manager * * @return EventManager * @throws DependencyInjection\Exception */ public function getEventManager() { return $this->container->get('event_manager'); }