public function onInstantiate(Component &$component) { $strategy = PiconApplication::get()->getSecuritySettings()->getAuthorisationStrategy(); if (!$strategy->isComponentInstantiationAuthorised($component)) { PiconApplication::get()->getSecuritySettings()->getComponentNotAuthorisedListener()->onNotAuthorised($component); } }
public function process() { $target = $this->resolver->resolve($this->request); if ($target != null) { $this->addTarget($target); } if (count($this->targetStack) == 0) { $this->addTarget(new PageNotFoundRequestTarget()); } $iterator = $this->targetStack->getIterator(); while ($iterator->valid()) { try { if (PiconApplication::get()->getProfile()->isCleanBeforeOutput()) { ob_clean(); $this->response->clean(); } $iterator->current()->respond($this->response); } catch (RestartRequestOnPageException $restartEx) { $iterator->rewind(); $this->targetStack->exchangeArray(array()); $this->addTarget(new PageRequestTarget($restartEx->getPageIdentifier())); } catch (\Exception $ex) { $iterator->rewind(); $this->targetStack->exchangeArray(array()); $this->addTarget(new ExceptionPageRequestTarget($ex)); } $iterator->next(); } }
public function __construct(Identifier $pageIdentifier, Identifier $loginPage) { Args::identifierOf($pageIdentifier, WebPage::getIdentifier(), 'pageIdentifier'); Args::identifierOf($loginPage, WebPage::getIdentifier(), 'loginPage'); $this->pageAuthIdentifier = $pageIdentifier; $this->loginPageIdentifier = $loginPage; PiconApplication::get()->getSecuritySettings()->setComponentNotAuthorisedListener(new DirectToPageComponentNotAuthorisedListener($loginPage)); }
public function resolve(Request $request) { if ($this->isHomePage($request)) { $homepage = PiconApplication::get()->getHomePage(); return new PageRequestTarget($homepage::getIdentifier()); } else { return new PageRequestTarget($this->getPageClassForPath($request)); } }
/** * Load the application config * @return Config */ protected function loadConfig() { $config = null; if (CacheManager::resourceExists(self::CONFIG_RESOURCE_NAME, CacheManager::APPLICATION_SCOPE)) { $config = CacheManager::loadResource(self::CONFIG_RESOURCE_NAME, CacheManager::APPLICATION_SCOPE); } else { $config = ConfigLoader::load(CONFIG_FILE); CacheManager::saveResource(self::CONFIG_RESOURCE_NAME, $config, CacheManager::APPLICATION_SCOPE); } PiconApplication::get()->getConfigLoadListener()->onConfigLoaded($config); return $config; }
protected function setup() { PiconApplication::get()->addComponentRenderHeadListener(new JQueryRenderHeadListener()); $view = new RepeatingView(TabPanel::PANEL_ID); $this->add($view); foreach ($this->getCollection()->tabs as $index => $tabItem) { $panel = $tabItem->newTab($view->getNextChildId()); $panel->setOutputMarkupId(true); $this->indexes[$index] = $panel->getMarkupId(); $panel->add(new AttributeModifier('style', new BasicModel('display:none;'))); $view->add($panel); } }
/** * Load the application context * @return ApplicationContext */ protected function loadContext($config) { $loader = ContextLoaderFactory::getLoader($config); $context = $loader->load($config); $injector = new Injector($context); foreach ($context->getResources() as $resource) { $injector->inject($resource); } foreach ($context->getResources() as $resource) { if ($resource instanceof InitializingBean) { $resource->afterPropertiesSet(); } } PiconApplication::get()->getContextLoadListener()->onContextLoaded($context); }
protected function onComponentTagBody(ComponentTag $tag) { $this->getResponse()->write('<head>'); parent::onComponentTagBody($tag); $page = $this->getPage(); $headerResponse = new HeaderResponse($this->getResponse()); PiconApplication::get()->getComponentRenderHeadListener()->onHeadRendering($this, $headerResponse); $page->renderHead($headerResponse); $self = $this; $callback = function (Component &$component) use($headerResponse, $self) { $component->renderHeadContainer($self, $headerResponse); return Component::VISITOR_CONTINUE_TRAVERSAL; }; $page->visitChildren(Component::getIdentifier(), $callback); $this->getResponse()->write('</head>'); }
private function renderComponentHeader(Component $component, Response $response, $headerResponse) { $header = new HeaderContainer(HeaderResolver::HEADER_ID); $page = $component->getPage(); $page->addOrReplace($header); PiconApplication::get()->getComponentRenderHeadListener()->onHeadRendering($component, $headerResponse); $page->renderHead($headerResponse); $component->renderHeadContainer($header, $headerResponse); $callback = function (Component &$component) use($headerResponse, $header) { $component->renderHeadContainer($header, $headerResponse); return Component::VISITOR_CONTINUE_TRAVERSAL; }; if ($component instanceof MarkupContainer) { $component->visitChildren(Component::getIdentifier(), $callback); } }
/** * Load the associated markup file for a component * @param Component $component * @return MarkupElement The root markup tag, populated with child tags */ public function loadMarkup(Component $component) { $name = get_class($component); $fileSafeName = str_replace('\\', '_', $name); if (PiconApplication::get()->getProfile()->isCacheMarkup()) { if (CacheManager::resourceExists(self::MARKUP_RESOURCE_PREFIX . $fileSafeName, CacheManager::APPLICATION_SCOPE)) { return CacheManager::loadResource(self::MARKUP_RESOURCE_PREFIX . $fileSafeName, CacheManager::APPLICATION_SCOPE); } else { $markup = $this->internalLoadMarkup($name); CacheManager::saveResource(self::MARKUP_RESOURCE_PREFIX . $fileSafeName, $markup, CacheManager::APPLICATION_SCOPE); return $markup; } } else { return $this->internalLoadMarkup($name); } }
protected final function internalInit() { parent::internalInit(); $this->addContextLoaderListener(new ApplicationContextLoadListener(function ($createdContext) { session_start(); })); $this->securitySettings = new WebApplicationSecuritySettings(); $this->pageMapInitializationListener = new PageMapInitializationListenerCollection(); $this->componentInstantiationListeners = new ComponentInstantiationListenerCollection(); $this->addComponentInstantiationListener(new ComponentInjector()); $this->addComponentInstantiationListener(new ComponentAuthorisationListener()); $this->componentInitializationListeners = new ComponentInitializationListenerCollection(); $this->componentBeforeRenderListeners = new ComponentBeforeRenderListenerCollection(); $this->componentAfterRenderListeners = new ComponentAfterRenderListenerCollection(); $this->componentRenderHeadListener = new ComponentRenderHeadListenerCollection(); $this->init(); }
private function scanPages() { ApplicationInitializer::loadAssets(ASSETS_DIRECTORY); $this->pages = array(); $scanner = new ClassScanner(array(new SubClassRule('\\picon\\WebPage'))); $pages = $scanner->scanForName(); foreach ($pages as $pageName) { $this->addToPath($pageName, $pageName); } $pathScanner = new ClassScanner(array(new AnnotationRule('Path'))); foreach ($pathScanner->scanForReflection($pages) as $reflection) { $pathAnnoation = $reflection->getAnnotation('Path'); $path = $pathAnnoation->path; if (empty($path)) { throw new \UnexpectedValueException(sprintf("Expecting path annoation to have a path value for class %s", $reflection->getName())); } $this->addToPath($path, $reflection->getNamespaceName() . '\\' . $reflection->getName()); } PiconApplication::get()->getPageMapInitializationListener()->onInitialize($this); }
/** * @todo This is a bad way of forcing listeners to re register */ public function __wakeup() { parent::__wakeup(); PiconApplication::get()->addComponentRenderHeadListener(new JQueryUIRenderHeadListener()); }
/** * Called just after the component is rendered */ public function afterComponentRender() { if ($this->afterComponentRenderCallback != null) { $callable = $this->afterComponentRender; $callable($this); } $this->rendered = true; PiconApplication::get()->getComponentAfterRenderListenersr()->onAfterRender($this); $this->notifyBehavioursAfterRender(); if ($this instanceof MarkupContainer && $this->visible) { foreach ($this->getChildren() as $child) { /** * If the child component has not been rendered it must * not have been present in the markup * @todo move this into another non component parent calling method * so that all children may have internalAfterRender */ if (!$child->rendered) { throw new \RuntimeException(sprintf("Component %s was not rendered because there was no corrisponding picon:id in the markup.", $child->id)); } } } }
public function __construct() { PiconApplication::get()->addComponentRenderHeadListener(new JQueryRenderHeadListener()); }