/** * Creates new presenter instance. * @param string presenter name * @return IPresenter */ public function createPresenter($name) { $presenter = $this->container->createInstance($this->getPresenterClass($name)); if (method_exists($presenter, 'setContext')) { $this->container->callMethod(array($presenter, 'setContext')); } foreach (array_reverse(get_class_methods($presenter)) as $method) { if (substr($method, 0, 6) === 'inject') { $this->container->callMethod(array($presenter, $method)); } } if ($presenter instanceof NPresenter && $presenter->invalidLinkMode === NULL) { $presenter->invalidLinkMode = $this->container->parameters['debugMode'] ? NPresenter::INVALID_LINK_WARNING : NPresenter::INVALID_LINK_SILENT; } return $presenter; }
/** * @return IPresenterResponse */ public function run(NPresenterRequest $request) { $this->request = $request; $httpRequest = $this->context->getByType('IHttpRequest'); if (!$httpRequest->isAjax() && ($request->isMethod('get') || $request->isMethod('head'))) { $refUrl = clone $httpRequest->getUrl(); $url = $this->context->getService('router')->constructUrl($request, $refUrl->setPath($refUrl->getScriptPath())); if ($url !== NULL && !$httpRequest->getUrl()->isEqual($url)) { return new NRedirectResponse($url, IHttpResponse::S301_MOVED_PERMANENTLY); } } $params = $request->getParameters(); if (!isset($params['callback'])) { throw new NBadRequestException("Parameter callback is missing."); } $params['presenter'] = $this; $callback = new NCallback($params['callback']); $response = $callback->invokeArgs(NPresenterComponentReflection::combineArgs($callback->toReflection(), $params)); if (is_string($response)) { $response = array($response, array()); } if (is_array($response)) { if ($response[0] instanceof SplFileInfo) { $response = $this->createTemplate('NFileTemplate') ->setParameters($response[1])->setFile($response[0]); } else { $response = $this->createTemplate('NTemplate') ->setParameters($response[1])->setSource($response[0]); } } if ($response instanceof ITemplate) { return new NTextResponse($response); } else { return $response; } }
public function processServices() { $this->parseServices($this->container, $this->config); foreach ($this->extensions as $name => $extension) { $this->container->addDefinition($name) ->setClass('NDINestedAccessor', array('@container', $name)) ->setAutowired(FALSE); if (isset($this->config[$name])) { $this->parseServices($this->container, $this->config[$name], $name); } } foreach ($this->container->getDefinitions() as $name => $def) { $factory = $name . 'Factory'; if (!$def->shared && !$def->internal && !$this->container->hasDefinition($factory)) { $this->container->addDefinition($factory) ->setClass('NCallback', array('@container', NDIContainer::getMethodName($name, FALSE))) ->setAutowired(FALSE) ->tags = $def->tags; } } }
/** * @return NUser */ public function getUser() { return $this->context->getByType('NUser'); }
public function __construct() { parent::__construct(array( 'appDir' => '/home/svn/repos/gymfed/trunk/app', 'wwwDir' => '/home/svn/repos/gymfed/trunk/www', 'debugMode' => TRUE, 'productionMode' => FALSE, 'environment' => 'development', 'consoleMode' => FALSE, 'container' => array( 'class' => 'SystemContainer', 'parent' => 'NDIContainer', ), 'tempDir' => '/home/svn/repos/gymfed/trunk/app/../temp', 'mail' => array( 'from' => '*****@*****.**', 'reply_to' => '*****@*****.**', 'subj' => 'development mode', ), 'debug' => array( 'compatibility' => TRUE, ), 'logger' => array( 'file' => '../log/gis.log', 'ident' => 'auto', 'date' => 'auto', 'conv' => 'auto', ), 'config' => array( 'debug' => '`($_SERVER["HTTP_HOST"] == "gis.drino.net" || $_SERVER["HTTP_HOST"]=="gymfed.drino.net")`', ), 'prihlasovaci_stranka' => 'https://gis.drino.net/login/', 'mesic_otevreni_registraci_pro_pristi_rok' => 6, 'admin_nove_registrace' => 'sritter@satoya.cz,jana@satoya.cz', 'admin_duplicitni_registrace' => 'sritter@satoya.cz,jana@satoya.cz', 'admin_databaze' => '*****@*****.**', 'admin_nova_akce' => 'jana@satoya.cz,sritter@satoya.cz', 'adresa' => 'gis.drino.net', 'update' => array( 'rand' => 0, 'files' => '__/logger.php __/config.php __/design.php __/auth.php __/supermail.php __/database.php __/cs.php', 'mail' => '*****@*****.**', ), 'rubriky' => array( 'SGM' => 35, 'SGZ' => 34, 'TG' => 33, 'AE' => 59, 'AG' => 50, 'TR' => 51, 'OS' => 52, 'VG' => 53, 'podrubrika' => array( 'a' => 15, 'b' => 14, ), ), 'adresa2' => 'gis.gymfed.cz # a', )); }
public function __construct() { parent::__construct(array( 'appDir' => '/home/svn/repos/gymfed/trunk/app', 'wwwDir' => '/home/svn/repos/gymfed/trunk/www', 'debugMode' => FALSE, 'productionMode' => TRUE, 'environment' => 'production', 'consoleMode' => FALSE, 'container' => array( 'class' => 'SystemContainer', 'parent' => 'NDIContainer', ), 'tempDir' => '/home/svn/repos/gymfed/trunk/app/../temp', 'mail' => array( 'from' => '*****@*****.**', 'reply_to' => '*****@*****.**', ), 'debug' => array( 'compatibility' => TRUE, ), 'logger' => array( 'file' => '../log/gis.log', 'ident' => 'auto', 'date' => 'auto', 'conv' => 'auto', ), 'config' => array( 'debug' => '`($_SERVER["HTTP_HOST"] == "gis.drino.net" || $_SERVER["HTTP_HOST"]=="gymfed.drino.net")`', ), 'prihlasovaci_stranka' => 'https://gis.gymfed.cz/login/', 'mesic_otevreni_registraci_pro_pristi_rok' => 12, 'admin_nove_registrace' => 'vojackova@gymfed.cz,sarichev@gymfed.cz,jana@satoya.cz', 'admin_duplicitni_registrace' => 'churavy@gymfed.cz,jana@satoya.cz', 'admin_databaze' => '*****@*****.**', 'admin_nova_akce' => '*****@*****.**', 'adresa' => 'gis.gymfed.cz', 'rubriky' => array( 'SGM' => 2, 'SGZ' => 3, 'TG' => 4, 'AE' => 5, 'AG' => 6, 'TR' => 7, 'OS' => 8, 'VG' => 9, ), )); }
/** * Returns current authorization handler. * @return IAuthorizator */ final public function getAuthorizator() { return ($tmp=$this->authorizator) ? $tmp : $this->context->getByType('IAuthorizator'); }
/** * @return bool */ public function __isset($name) { return $this->container->hasService($this->namespace . $name); }
/** * Formats PHP code for class instantiating, function calling or property setting in PHP. * @return string * @internal */ public function formatStatement(NDIStatement $statement, $self = NULL) { $entity = $this->normalizeEntity($statement->entity); $arguments = $statement->arguments; if (is_string($entity) && NStrings::contains($entity, '?')) { // PHP literal return $this->formatPhp($entity, $arguments, $self); } elseif ($service = $this->getServiceName($entity)) { // factory calling or service retrieving if ($this->definitions[$service]->shared) { if ($arguments) { throw new NServiceCreationException("Unable to call service '$entity'."); } return $this->formatPhp('$this->getService(?)', array($service)); } $params = array(); foreach ($this->definitions[$service]->parameters as $k => $v) { $params[] = preg_replace('#\w+\z#', '\$$0', (is_int($k) ? $v : $k)) . (is_int($k) ? '' : ' = ' . NPhpHelpers::dump($v)); } $rm = new NFunctionReflection(create_function(implode(', ', $params), '')); $arguments = NDIHelpers::autowireArguments($rm, $arguments, $this); return $this->formatPhp('$this->?(?*)', array(NDIContainer::getMethodName($service, FALSE), $arguments), $self); } elseif ($entity === 'not') { // operator return $this->formatPhp('!?', array($arguments[0])); } elseif (is_string($entity)) { // class name if ($constructor = NClassReflection::from($entity)->getConstructor()) { $this->addDependency($constructor->getFileName()); $arguments = NDIHelpers::autowireArguments($constructor, $arguments, $this); } elseif ($arguments) { throw new NServiceCreationException("Unable to pass arguments, class $entity has no constructor."); } return $this->formatPhp("new $entity" . ($arguments ? '(?*)' : ''), array($arguments), $self); } elseif (!NValidators::isList($entity) || count($entity) !== 2) { throw new InvalidStateException("Expected class, method or property, " . NPhpHelpers::dump($entity) . " given."); } elseif ($entity[0] === '') { // globalFunc return $this->formatPhp("$entity[1](?*)", array($arguments), $self); } elseif (NStrings::contains($entity[1], '$')) { // property setter NValidators::assert($arguments, 'list:1', "setup arguments for '" . NCallback::create($entity) . "'"); if ($this->getServiceName($entity[0], $self)) { return $this->formatPhp('?->? = ?', array($entity[0], substr($entity[1], 1), $arguments[0]), $self); } else { return $this->formatPhp($entity[0] . '::$? = ?', array(substr($entity[1], 1), $arguments[0]), $self); } } elseif ($service = $this->getServiceName($entity[0], $self)) { // service method if ($this->definitions[$service]->class) { $arguments = $this->autowireArguments($this->definitions[$service]->class, $entity[1], $arguments); } return $this->formatPhp('?->?(?*)', array($entity[0], $entity[1], $arguments), $self); } else { // static method $arguments = $this->autowireArguments($entity[0], $entity[1], $arguments); return $this->formatPhp("$entity[0]::$entity[1](?*)", array($arguments), $self); } }
public function __construct() { parent::__construct(array( 'appDir' => 'D:\\xampp\\htdocs\\redakcni_system\\app', 'wwwDir' => 'D:/xampp/htdocs/redakcni_system/www', 'debugMode' => TRUE, 'productionMode' => FALSE, 'environment' => 'development', 'consoleMode' => FALSE, 'container' => array( 'class' => 'SystemContainer', 'parent' => 'NDIContainer', ), 'tempDir' => 'D:\\xampp\\htdocs\\redakcni_system\\app/../temp', 'mail' => array( 'from' => '*****@*****.**', 'reply_to' => '*****@*****.**', 'subj' => 'development mode', ), 'debug' => array( 'compatibility' => TRUE, ), 'logger' => array( 'file' => '../log/gis.log', 'ident' => 'auto', 'date' => 'auto', 'conv' => 'auto', ), 'prihlasovaci_stranka' => 'https://gis.drino.net/login/', 'adresa' => 'gis.drino.net', )); }
/** * Does the service exist? * @param string service name * @return bool */ public function hasService($name) { return isset($this->registry[$name]) || isset($this->factories[$name]) || method_exists($this, $method = NDIContainer::getMethodName($name)) && $this->getReflection()->getMethod($method)->getName() === $method; }