/**
  * @param \Janeiro\Request\AbstractRequest $request
  * @throws \Janeiro\Exception
  * @return \Janeiro\Response
  */
 public function indexAction(AbstractRequest $request)
 {
     $response = null;
     if (1 === preg_match('/^[\\/A-Za-z]+$/', $request->getParameter('uri'), $uri)) {
         $namespaces = (array) $this->registry->get('routing.namespace');
         $segments = explode('/', $uri[0]);
         $file = array_pop($segments) . '.js';
         foreach ($namespaces as $namespace) {
             $path = [ROOT, 'src', str_replace("\\", DS, $namespace), $segments[0], 'View', 'JavaScript'];
             $path = implode(DS, array_merge($path, array_slice($segments, 1)));
             if (is_readable($path . DS . $file)) {
                 $this->view->setTemplateDirectory($path);
                 $this->view->setTemplate($file);
                 $response = new Response('text/javascript');
                 $response->setHeader('Expires', 'Wed, 01 Jan 2014 00:00:00 GMT');
                 $response->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate');
                 $response->setHeader('Pragma', 'no-cache');
                 $response->setContent($this->view->render());
                 $response->setStatus(200);
                 break;
             }
         }
     }
     if (empty($response)) {
         throw new Exception('Resource not found', Exception::HTTP_NOT_FOUND);
     }
     return $response;
 }
 /**
  * Get translation(s) for given module (or module and key)
  *
  * @param string $language
  * @param string $module
  * @param string|null $key
  * @return string|array
  */
 public function get($language, $module, $key = null)
 {
     $translation = null;
     if (false === isset($this->translations[$language][$module])) {
         $this->translations[$language][$module] = [];
         foreach (array_reverse((array) $this->registry->get('routing.namespace')) as $namespace) {
             $path = [ROOT, 'src', str_replace("\\", DS, $namespace), CamelCase::to($module), 'View', 'Translation'];
             $file = implode(DS, $path) . DS . sprintf('%s.xml', $language);
             if (is_readable($file)) {
                 if (false !== ($xml = simplexml_load_file($file))) {
                     foreach ($this->parse($xml) as $index => $value) {
                         $this->translations[$language][$module][$index] = $value;
                     }
                 }
             }
         }
     }
     if (null === $key) {
         $translation = $this->translations[$language][$module];
     } elseif (isset($this->translations[$language][$module][$key])) {
         $translation = $this->translations[$language][$module][$key];
     }
     return $translation;
 }
 /**
  * @template Schema/Update.phtml
  * @return string
  */
 public function updateAction()
 {
     $hash = hash('crc32', serialize($this->adapter->getSchema()));
     $hashCurrent = $hash;
     $this->view->set('current', $hash);
     do {
         $update = ROOT . sprintf($this->registry->get('database.schema'), $hash);
         if (file_exists($update)) {
             try {
                 $this->adapter->getDriver()->query(file_get_contents($update));
             } catch (\Exception $e) {
                 $update = false;
             }
         } else {
             $update = false;
         }
         $hash = hash('crc32', serialize($this->adapter->getSchema()));
     } while (false !== $update && $hash !== $hashCurrent);
     return $this->view->set('new', $hash)->render();
 }
Exemple #4
0
 public function testRegistryFromLoadedFile()
 {
     $filename = str_replace('/', DS, __DIR__ . '/RegistryTestConfiguration.php');
     $this->registry->load($filename);
     $this->assertEquals('correct_value', $this->registry->get('loaded.some_key'));
 }