コード例 #1
0
ファイル: Session.php プロジェクト: zenmagick/zenmagick
 /**
  * {@inheritDoc}
  *
  * modified to set session cookie name dynamically so admin and storefront
  * cookies are separated. It should be closer to native session storage,
  * but it is not worth it to extend/modify another class yet.
  */
 public function __construct(SessionStorageInterface $storage = null, AttributeBagInterface $attributes = null, FlashBagInterface $flashes = null)
 {
     parent::__construct($storage, $attributes, $flashes);
     if (null !== ($context = Runtime::getContext())) {
         $this->storage->setOptions(array('name' => 'zm-' . $context));
     }
 }
コード例 #2
0
ファイル: AppKernel.php プロジェクト: zenmagick/zenmagick
 /**
  * Create new application
  *
  * @param string  environment The environment
  * @param boolean debug Whether to enable debugging or not
  * @param array config Optional config settings.
  */
 public function __construct($environment = 'prod', $debug = false, $context = null)
 {
     $this->context = $context;
     // @todo FIXME: Only save it the first time. this gets called again via ConfigCache
     if (null === Runtime::getContext()) {
         Runtime::setContext($context);
     }
     parent::__construct($environment, $debug);
 }
コード例 #3
0
ファイル: SacsManager.php プロジェクト: zenmagick/zenmagick
 /**
  * Reset all internal data structures.
  */
 public function reset()
 {
     $this->mappings = array('default' => array(), 'mappings' => array());
     $this->handlers = array();
     $this->permissionProviders = array();
     $context = Runtime::getContext();
     if ('admin' == $context) {
         $def = 'ZenMagick\\Http\\Sacs\\Handler\\UserRoleSacsHandler';
     }
     if (empty($def) || !class_exists($def)) {
         return;
     }
     if (null != ($handler = new $def())) {
         $handler->setContainer($this->container);
         $this->handlers[$handler->getName()] = $handler;
     }
 }
コード例 #4
0
 public function boot()
 {
     $parameterBag = $this->container->getParameterBag();
     $settingsService = $this->container->get('settingsService');
     $rootDir = $parameterBag->get('zenmagick.root_dir');
     $context = \ZenMagick\Base\Runtime::getContext();
     $settingsFiles = array();
     $settingsFiles[] = $rootDir . '/src/ZenMagick/StoreBundle/config/config.yaml';
     $settingsFiles[] = sprintf('%s/src/ZenMagick/%sBundle/config/config.yaml', $rootDir, ucfirst($context));
     foreach ($settingsFiles as $config) {
         if (file_exists($config)) {
             $settingsService->load($config);
         }
     }
     // @todo never do this
     \Zenmagick\Base\Runtime::setContainer($this->container);
     if ('install' == $parameterBag->get('kernel.environment')) {
         return;
     }
     // @todo don't just exit if no plugins
     $pluginsEnabled = $parameterBag->get('zenmagick.plugins.enabled');
     if (!$this->container->has('pluginService') && $pluginsEnabled) {
         return;
     }
     if ($this->container->has('configService')) {
         foreach ($this->container->get('configService')->loadAll() as $key => $value) {
             if (!defined($key)) {
                 define($key, $value);
             }
         }
         $defaults = $rootDir . '/src/ZenMagick/StoreBundle/config/defaults.php';
         if (file_exists($defaults)) {
             include $defaults;
         }
     }
     // @todo switch to using tagged services for events.
     $settingsService = $this->container->get('settingsService');
     $listeners = array(sprintf('ZenMagick\\%sBundle\\EventListener\\%sListener', ucfirst($context), ucfirst($context)));
     if ($this->container->has('pluginService') && $pluginsEnabled) {
         $plugins = $this->container->get('pluginService')->getPluginsForContext($context, true);
         foreach ($plugins as $plugin) {
             // @todo the plugin list will continue disabled plugins on the requests that build the cache.
             if (!$plugin->isEnabled()) {
                 continue;
             }
             $listeners[] = $plugin;
         }
     }
     if ('storefront' == $context) {
         $listeners[] = sprintf('ZenMagick\\themes\\%s\\EventListener', $this->container->get('themeService')->getActiveThemeId());
     }
     // @todo switch to using tagged services for events.
     $dispatcher = $this->container->get('event_dispatcher');
     foreach ($listeners as $eventListener) {
         if (is_string($eventListener)) {
             if (!class_exists($eventListener)) {
                 continue;
             }
             if (null != ($eventListener = new $eventListener())) {
                 $eventListener->setContainer($this->container);
             }
         }
         if (is_object($eventListener)) {
             $events = array();
             foreach (get_class_methods($eventListener) as $method) {
                 if (0 === strpos($method, 'on')) {
                     $eventName = Container::underscore(substr($method, 2));
                     $dispatcher->addListener($eventName, array($eventListener, $method));
                 }
             }
         }
     }
 }
コード例 #5
0
ファイル: RouteResolver.php プロジェクト: zenmagick/zenmagick
 /**
  * Get a view for the given request and view id.
  *
  * @param string viewId The view id.
  * @param ZenMagick\Http\Request request The current request.
  * @param array Optional view data; default is an empty array.
  * @return View A view.
  * @todo: move into dispatcher and fix controller to return just string/string/data from process
  */
 public function getViewForId($viewId, $request, array $data = array())
 {
     $view = null;
     // build list of routes to look at
     $routeIds = array();
     $routeIds[] = $viewId;
     $routeIds[] = $request->attributes->get('_route');
     $routeIds[] = self::GLOBAL_ROUTING_KEY;
     $controller = $request->attributes->get('_controller');
     $base = '::';
     $pieces = explode('\\', $controller);
     if ('ZenMagick' == $pieces[0]) {
         $context = $pieces[1];
         if ('ZenMagickBundle' == $context) {
             $base = ucfirst(\ZenMagick\Base\Runtime::getContext()) . 'Bundle::';
         } else {
             $base = $context . '::';
         }
     }
     // check until match or we run out of routeIds
     //$base = '';
     $settingsService = $this->container->get('settingsService');
     $layoutName = $settingsService->get('zenmagick.http.view.defaultLayout', null);
     foreach ($routeIds as $routeId) {
         if (null != ($route = $this->container->get('router')->getRouteCollection()->get($routeId))) {
             $viewKey = null == $viewId ? 'view' : sprintf('view:%s', $viewId);
             $options = $route->getOptions();
             if (array_key_exists($viewKey, $options)) {
                 $viewDefinition = null;
                 $bundle = (string) strtok($options[$viewKey], '::');
                 $token = parse_url(str_replace('%routeId%', $request->getRequestId(), str_replace($bundle . '::', '', $options[$viewKey])));
                 if (!array_key_exists('query', $token)) {
                     $token['query'] = '';
                 }
                 // merge in layout if set
                 if (null != $layoutName) {
                     parse_str($token['query'], $query);
                     if (!array_key_exists('layout', $query)) {
                         $query['layout'] = $layoutName;
                     }
                     // also allow layout as option
                     if (array_key_exists('layout', $options)) {
                         $query['layout'] = $options['layout'];
                     }
                     $token['query'] = http_build_query($query);
                 }
                 if (array_key_exists('scheme', $token)) {
                     // default to same page if nothing set
                     if (!array_key_exists('host', $token)) {
                         $token['host'] = $request->getRequestId();
                     }
                     $viewDefinition = sprintf('%s#requestId=%s&%s', $token['scheme'], $token['host'], $token['query']);
                 } else {
                     if ($bundle) {
                         $token['path'] = $bundle . '::' . $token['path'];
                     }
                     $viewDefinition = sprintf('%s#template=%s&%s', 'defaultView', $token['path'], $token['query']);
                 }
                 $view = Beans::getBean($viewDefinition);
                 break;
             }
         }
     }
     if (!$view) {
         // use conventions and defaults
         $ext = $settingsService->get('zenmagick.http.templates.ext');
         $templateName = sprintf('%s%s%s', $base, $request->getRequestId(), $ext);
         $view = Beans::getBean('defaultView');
         $view->setTemplate($templateName);
         //$view->setLayout($layoutName);
     }
     if ($view instanceof TemplateView && $data) {
         $view->setVariables($data);
     }
     return $view;
 }