示例#1
0
 /**
  * Renderer for Index.
  *
  * This demo implementation shows how the render method can be used to intercept the render process (hook)
  * and transform the input so the data is bound to a fingerprint (Should be unique for your case // UUID).
  * In this demonstration we make use of our really strong user bound session identifier to cache data for
  * a specific user.
  *
  * @param array $data The data to render
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return bool
  */
 protected function __renderIndex(array $data)
 {
     /* @var $session \Doozr_Session_Service */
     $session = \Doozr_Loader_Serviceloader::load('session');
     /**
      * A user specific view would pass a user specific value in here for group pages a group id and so on ...
      * Use this as fingerprint only if you also use an unique session identifier for each user (Doozr default).
      */
     $fingerprint = $session->getIdentifier();
     // Get I18n service instance
     $i18nService = \Doozr_Loader_Serviceloader::load('i18n');
     // Render data from model
     return $this->render($data, $fingerprint, $i18nService);
 }
示例#2
0
 /**
  * Returns an instance of Doozr's internal Config-Reader for reading INI-Configurations.
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return Doozr_Configuration_Reader_Ini
  *
  * @throws Doozr_Di_Exception
  */
 protected function getConfigurationReader()
 {
     // Add required dependencies
     self::$registry->getContainer()->getMap()->wire(['doozr.filesystem.service' => Doozr_Loader_Serviceloader::load('filesystem'), 'doozr.cache.service' => Doozr_Loader_Serviceloader::load('cache', DOOZR_CACHING_CONTAINER, DOOZR_NAMESPACE_FLAT . '.cache.i18n', [], DOOZR_UNIX, DOOZR_CACHING)]);
     /* @var Doozr_Configuration_Reader_Ini $config */
     $config = self::$registry->getContainer()->build('doozr.configuration.reader.ini', [DOOZR_CACHING]);
     return $config;
 }
示例#3
0
 /**
  * Returns an instance of the Session-Service.
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return Doozr_Session_Service Instance of service Session
  */
 protected function getSession()
 {
     if (!self::$session) {
         self::$session = Doozr_Loader_Serviceloader::load('session');
     }
     return self::$session;
 }
示例#4
0
 /**
  * Constructor.
  *
  * @param Doozr_Datetime_Service $datetime    Datetime Service of Doozr
  * @param int                    $level       Loglevel of the logging extending this class
  * @param string                 $fingerprint Fingerprint of the client
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return \Doozr_Logging_File
  */
 public function __construct(Doozr_Datetime_Service $datetime, $level = null, $fingerprint = null)
 {
     // call parents constructor
     parent::__construct($datetime, $level, $fingerprint);
     // get registry
     $registry = Doozr_Registry::getInstance();
     // store path-manager
     $this->setPath($registry->path);
     // set logfile-name (+path)
     $this->setLogfile($_SERVER['PHP_SELF']);
     // set filesystem service
     $this->setFilesystem(Doozr_Loader_Serviceloader::load('filesystem'));
 }
示例#5
0
 /**
  * This method is intend to render the current state of the view as html. For this it makes use of the base
  * template engine, and html5 template files. If you need another output or something like this, you must
  * overwrite this method.
  *
  * @param array                        $data        The data as override for internal stored data
  * @param string                       $fingerprint Optional fingerprint used as cache identifier for front- and
  *                                                  backend! Hint: Rendering user specific data an user identifier
  *                                                  MUST be used as salt when generating the fingerprint!!!
  *                                                  Otherwise user specific data can and will be sent to another
  *                                                  user!. So the following rule should be followed:
  *                                                  - generic view/template no user data = fingerprint by
  *                                                  content/path/url
  *                                                  - user specific view/template with user data = use
  *                                                  session-id or user-id!
  * @param Doozr_I18n_Service_Interface $i18n        An instance of a Doozr I18n service
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return bool TRUE if successful, otherwise FALSE
  *
  * @throws Doozr_Cache_Service_Exception
  * @throws Doozr_Base_View_Exception
  * @throws Doozr_Exception
  * @throws PHPTAL_ConfigurationException
  */
 protected function render(array $data = [], $fingerprint = null, Doozr_I18n_Service_Interface $i18n = null)
 {
     $this->setFingerprint($this->generateFingerprint($fingerprint, $data));
     $html = null;
     if (false === $this->getConfiguration()->kernel->debugging->enabled) {
         // We try to receive data for rendering from cache :) this is much faster
         try {
             $html = $this->cache->read($this->getFingerprint());
         } catch (Doozr_Cache_Service_Exception $e) {
             $html = null;
         }
     }
     // If data was/could not be retrieved we get it fresh here ...
     if ($html === null) {
         // Get name of template file
         $templateFile = $this->configuration->kernel->view->template->path . $this->translateToTemplateFilename() . '.' . $this->getTemplateExtension();
         if (false === $this->getRegistry()->getFilesystem()->exists($templateFile)) {
             throw new Doozr_Base_View_Exception(sprintf('The template file "%s" is required for rendering but it does not exist.', $templateFile));
         }
         /* @var $template PHPTAL */
         $template = Doozr_Loader_Serviceloader::load('template', $templateFile);
         // Set output runtimeEnvironment ...
         $template->setOutputMode($this->getOutputMode());
         // if I18n passed -> forward to template engine (e.g. PHPTAL)
         if (null !== $i18n) {
             $i18n->useDomain($this->translateToTextdomain());
             $template->setTranslator($i18n);
             $template->{'doozr_locale'} = $i18n->getLocale();
         }
         // Assign data from passed in array to template (for use as a template variable)
         foreach ($data as $key => $value) {
             $template->{$key} = $value;
         }
         // setup template compile output dir
         $template->setPhpCodeDestination($this->configuration->kernel->view->directories->compiled);
         // set the encoding of output
         $template->setEncoding($this->configuration->kernel->localization->encoding);
         // Output XHTML or HTML5 ... ?
         $template->setOutputMode($this->configuration->kernel->view->settings->outputmode);
         // execute = get result
         $html = $template->execute();
         if (true === $this->isDebugging()) {
             $renderer = $this->getRegistry()->getDebugbar()->getJavascriptRenderer();
             $renderer->setBaseUrl('/assets');
             $head = $renderer->renderHead();
             $body = $renderer->render();
             $html = str_replace('</head>', $head . '</head>', $html);
             $html = str_replace('</body>', $body . '</body>', $html);
         }
         // finally store in cache
         try {
             $this->cache->create($html, $this->getFingerprint());
         } catch (Doozr_Cache_Service_Exception $e) {
             pred($e);
         }
     }
     return $html;
 }
示例#6
0
 /**
  * Test: If instance fails with Exception due to a invalid encoding passed to constructor
  *
  * @expectedException Doozr_Crypt_Service_Exception
  * @expectedExceptionCode 5200
  */
 public function testExceptionOnInvalidEncoding()
 {
     Doozr_Loader_Serviceloader::load(self::$serviceName, null, self::ENCODING_INVALID);
 }
示例#7
0
 /**
  * Purges content from cache.
  *
  * @param array $scopes  The scope to purge content for.
  * @param array $argumentBag The arguments bag
  *
  * @author Benjamin Carl <*****@*****.**>
  * @return int The number of elements purged
  * @access protected
  * @throws Doozr_Exception
  */
 protected function purge(array $scopes = [self::SCOPE_EVERYTHING], array $argumentBag = [])
 {
     $result = 0;
     // Iterate the scopes passed ...
     foreach ($scopes as $scope) {
         // Build scope for cache
         if (false === in_array($scope, $this->validScopes)) {
             throw new Doozr_Exception(sprintf('Scope %s not allowed!', $scope));
         }
         // Check for multi scope
         if (self::SCOPE_EVERYTHING === $scope) {
             $scope = $this->validScopes;
             array_shift($scope);
         } else {
             $scope = [$scope];
         }
         $app = Doozr_Kernel_App::boot(DOOZR_APP_ENVIRONMENT, DOOZR_RUNTIME_ENVIRONMENT, DOOZR_UNIX, DOOZR_DEBUGGING, DOOZR_CACHING, DOOZR_CACHING_CONTAINER, DOOZR_LOGGING, DOOZR_PROFILING, DOOZR_APP_ROOT, DOOZR_APP_NAMESPACE, DOOZR_DIRECTORY_TEMP, DOOZR_DOCUMENT_ROOT, DOOZR_NAMESPACE, DOOZR_NAMESPACE_FLAT);
         // Scope
         foreach ($scope as $singleScope) {
             /* @var Doozr_Cache_Service $cache */
             $cache = Doozr_Loader_Serviceloader::load('cache', DOOZR_CACHING_CONTAINER, $singleScope, [], DOOZR_UNIX, DOOZR_CACHING);
             // We can purge simply everything from passed scope!
             try {
                 $result += $cache->garbageCollection($singleScope, -1, true);
             } catch (Exception $exception) {
                 break;
             }
         }
     }
     return $result;
 }
示例#8
0
 /**
  * Prepares setup for Tests of "Form".
  *
  * @author Benjamin Carl <*****@*****.**>
  */
 public function setUp()
 {
     self::$serviceName = 'Form';
     /** INIT */
     static $status;
     // Function has already run
     if (null === $status) {
         // Get container instance from registry
         $map = self::$registry->getContainer()->getMap();
         // File containing mappings
         $file = Doozr_Loader_Serviceloader::getServicePath('form') . DIRECTORY_SEPARATOR . '.map.json';
         // Generate map from static JSON map of Doozr
         $map->generate($file);
         // Get container instance from registry
         $container = self::$registry->getContainer();
         // Add map to existing maps in container
         $container->addToMap($map);
         // Create container and set factory and map
         $container->getMap()->wire(['doozr.i18n.service' => Doozr_Loader_Serviceloader::load('i18n'), 'doozr.form.service.store' => new Doozr_Form_Service_Store_UnitTest(), 'doozr.form.service.renderer' => new Doozr_Form_Service_Renderer_Html()]);
         self::$registry->setContainer($container);
         $status = 1;
     }
     /** END INIT */
     parent::setUp();
     // Get a faker instance with Doozr's default locale
     self::$faker = FakerFactory::create($this->convertLocale(self::$registry->getConfiguration()->i18n->default->locale));
 }
示例#9
0
 /**
  * Returns instance of Datetime module.
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return Doozr_Datetime_Service An instance of module Datetime
  * @static
  */
 protected static function getDateTime()
 {
     // Lazyload
     if (null === self::$dateTime) {
         /* @var Doozr_Datetime_Service self::$dateTime */
         self::$dateTime = Doozr_Loader_Serviceloader::load('datetime');
     }
     return self::$dateTime;
 }
示例#10
0
 /**
  * Enables encryption.
  * This method is intend to enable the encryption for this instance including cipher and encoding.
  *
  * @param string $cipher   The algorithm (container of Service crypt) used for encryption
  * @param string $encoding The encoding to use for safety handable encrypted value
  *                         (can be either "uuencode" or "base64")
  *
  * @author Benjamin Carl <*****@*****.**>
  */
 public function enableEncryption($cipher = self::DEFAULT_ENCRYPT_CIPHER, $encoding = self::DEFAULT_ENCRYPT_ENCODING)
 {
     /* @var $this->cryptService Doozr_Crypt_Service */
     $this->cryptService(Doozr_Loader_Serviceloader::load('crypt', $cipher, $encoding))->security(self::getRegistry()->getSecurity());
     $this->encrypt = true;
 }
示例#11
0
 /**
  * Initializes the template engine
  * This method is intend to load the configured template-engine via Doozr::module().
  *
  * @author Benjamin Carl <*****@*****.**>
  * @return void
  * @access private
  */
 private function _init()
 {
     // TODO: check if self::$instance is required here or if we can only set
     // decorated object
     // initialize and store the instance of template engine for further access
     self::$instance = Doozr_Loader_Serviceloader::load($this->library, $this->resource);
     // set this instance as decorated object of our generic Facade and
     // so we can access all the base methods of any lib easily!
     $this->setDecoratedObject(self::$instance);
 }
示例#12
0
 /**
  * This method is intend to render the current state of the view as html. For this it makes use of the base
  * template engine, and html5 template files. If you need another output or something like this, you must
  * overwrite this method.
  *
  * @param array                        $data        The data as override for internal stored data
  * @param string                       $fingerprint Optional fingerprint used as cache identifier for front- and
  *                                                  backend! Hint: Rendering user specific data an user identifier
  *                                                  MUST be used as salt when generating the fingerprint!!!
  *                                                  Otherwise user specific data can and will be sent to another
  *                                                  user!. So the following rule should be followed:
  *                                                  - generic view/template no user data = fingerprint by
  *                                                  content/path/url
  *                                                  - user specific view/template with user data = use
  *                                                  session-id or user-id!
  * @param Doozr_I18n_Service_Interface $i18n        An instance of a Doozr I18n service
  *
  * @author Benjamin Carl <*****@*****.**>
  *
  * @return bool TRUE if successful, otherwise FALSE
  *
  * @throws \Doozr_Base_View_Exception
  */
 protected function render(array $data = [], $fingerprint = null, Doozr_I18n_Service_Interface $i18n = null)
 {
     $this->setFingerprint($this->generateFingerprint($fingerprint, $data));
     $html = null;
     // We try to receive data for rendering from cache :) this is much faster
     if (true === $this->getCaching()) {
         try {
             $html = $this->cache->read($this->getFingerprint());
         } catch (Doozr_Cache_Service_Exception $exception) {
             $html = null;
         }
     }
     // If data was/could not be retrieved we get it fresh here ...
     if (null === $html) {
         // Get name of template file
         $templateFile = $this->configuration->kernel->view->template->path . $this->translateToTemplateFilename() . '.' . $this->getTemplateExtension();
         if (false === $this->getRegistry()->getFilesystem()->exists($templateFile)) {
             throw new Doozr_Base_View_Exception(sprintf('The template file "%s" is required for rendering but it does not exist.', $templateFile));
         }
         /* @var $template PHPTAL */
         $template = Doozr_Loader_Serviceloader::load('template', $templateFile);
         $template->setForceReparse(true);
         $template->setCacheLifetime(-1);
         // Set output runtimeEnvironment ...
         $template->setOutputMode($this->getOutputMode());
         // If I18n passed -> forward to template engine (e.g. PHPTAL)
         if (null !== $i18n) {
             // Try to load specific namespace/textdomain for PRESENTER+ACTION
             try {
                 $i18n->useDomain($this->translateToTextdomain());
             } catch (Doozr_I18n_Service_Exception $e) {
                 // We don't care but we log for developing purposes
                 $this->getRegistry()->getLogging()->debug($e->getMessage());
                 // Try to load specific namespace/textdomain for PRESENTER
                 try {
                     $i18n->useDomain($this->translateToTextdomain(true));
                 } catch (Doozr_I18n_Service_Exception $e) {
                     // We don't care but we log for developing purposes
                     $this->getRegistry()->getLogging()->debug($e->getMessage());
                     // Try to load default namespace/textdomain
                     try {
                         $i18n->useDomain($this->getConfiguration()->i18n->default->namespace);
                     } catch (Doozr_I18n_Service_Exception $e) {
                         // We don't care but we log for developing purposes
                         $this->getRegistry()->getLogging()->debug($e->getMessage());
                     }
                 }
             }
             $template->setTranslator($i18n);
             $template->{'doozr_locale'} = $i18n->getLocale();
         }
         // Assign data from passed in array to template (for use as a template variable)
         foreach ($data as $key => $value) {
             $template->{$key} = $value;
         }
         // setup template compile output dir
         $template->setPhpCodeDestination($this->configuration->kernel->view->directories->compiled);
         // set the encoding of output
         $template->setEncoding($this->configuration->kernel->localization->encoding);
         // Output XHTML or HTML5 ... ?
         $template->setOutputMode($this->configuration->kernel->view->settings->outputmode);
         $html = $template->execute();
         // Inject Debugbar?
         if (true === $this->isDebugging()) {
             $html = $this->injectDebugbar($html);
         }
         // Cache result?
         if (true === $this->getCaching()) {
             $this->cache->create($html, $this->getFingerprint());
         }
     }
     return $html;
 }
示例#13
0
 /**
  * Prepares setup for Tests.
  *
  * @author Benjamin Carl <*****@*****.**>
  */
 protected function setUp()
 {
     /* @var $app Doozr_Kernel_App Get kernel instance */
     self::$kernel = Doozr_Kernel_App::boot(DOOZR_APP_ENVIRONMENT, DOOZR_RUNTIME_ENVIRONMENT, DOOZR_UNIX, DOOZR_DEBUGGING, DOOZR_CACHING, DOOZR_CACHING_CONTAINER, DOOZR_LOGGING, DOOZR_PROFILING, DOOZR_APP_ROOT, DOOZR_DIRECTORY_TEMP, DOOZR_DOCUMENT_ROOT, DOOZR_NAMESPACE, DOOZR_NAMESPACE_FLAT);
     // Store className
     self::$serviceClassName = 'Doozr_' . self::$serviceName . '_Service';
     // Get registry
     self::$registry = Doozr_Registry::getInstance();
     // Load service
     self::$service = Doozr_Loader_Serviceloader::load(self::$serviceName);
 }
示例#14
0
 /**
  * Initializes the dependency injection path' parser, map, ...
  *
  * @author Benjamin Carl <*****@*****.**>
  * @static
  */
 protected static function initDependencyInjection()
 {
     // Get required dependency container for annotations!
     include_once DOOZR_DOCUMENT_ROOT . 'Doozr/Di/Map/Annotation.php';
     include_once DOOZR_DOCUMENT_ROOT . 'Doozr/Di/Parser/Annotation.php';
     include_once DOOZR_DOCUMENT_ROOT . 'Doozr/Di/Dependency.php';
     $collection = new Doozr_Di_Collection();
     $parser = new Doozr_Di_Parser_Annotation();
     $dependency = new Doozr_Di_Dependency();
     self::$map = new Doozr_Di_Map_Annotation($collection, $parser, $dependency);
     #self::$container = Doozr_Di_Container::getInstance();
     #self::$container->setFactory(new Doozr_Di_Factory(self::$registry));
 }
示例#15
0
 /**
  * Constructor.
  *
  * @param \stdClass $config The configuration for this type of interface
  *
  * @author Benjamin Carl <*****@*****.**>
  */
 protected function __construct(\stdClass $config)
 {
     // Check if requirements fulfilled
     self::checkRequirements();
     // Store the path to translation files
     $this->path($config->path)->cacheEnabled($this->getCacheEnabled() && $config->cache->enabled)->cacheLifetime($config->cache->lifetime)->encoding($config->encoding);
     // If cache enabled - get service cache and setup
     if (!self::$cache && true === $this->getCacheEnabled()) {
         if (true === isset($config->cache->container)) {
             $container = $config->cache->container;
         } else {
             $container = DOOZR_CACHING_CONTAINER;
         }
         if (false === isset($config->cache->namespace)) {
             $namespace = 'doozr.cache.i18n';
         } else {
             $namespace = $config->cache->namespace;
         }
         // Get cache service
         self::$cache = Doozr_Loader_Serviceloader::load('cache', $container, $namespace, [], DOOZR_UNIX, DOOZR_CACHING);
     }
 }
示例#16
0
 /**
  * Service entry point.
  *
  * This method is intend as replacement for __construct
  * PLEASE DO NOT USE __construct() - make always use of __tearup()!
  *
  * @param bool $virtual True to mock a filesystem (vfs = virtual filesystem)
  *
  * @author Benjamin Carl <*****@*****.**>
  * @return void
  * @access public
  */
 public function __tearup($virtual = false)
 {
     // is virtual?
     if ($virtual !== false) {
         // store information that this instance is virtual (fs)
         $this->isVirtual = true;
         // get vfs instance
         $this->vfs = Doozr_Loader_Serviceloader::load('virtualfilesystem');
     }
 }