Exemple #1
0
 /**
  * Retrieve a URL for a view. Since the Dispatcher type is used to
  * adapt an HTTP request to a View, this Reverse can be used to find
  * the URL that could be used to trigger the View in a future request.
  * This paradigm assists in the DRY pattern, so that refactoring the
  * URL scheme of your Application does not affect the application
  * itself
  */
 function reverse($view, $args = array(), $method = null, $application = null)
 {
     $dispatcher = $this->dispatcher;
     $project = Project::getCurrent();
     if (!$dispatcher) {
         $dispatcher = $project->getApplication($application);
     }
     $applications = $project->getApplications();
     foreach ($dispatcher->getUrls() as $route) {
         $target = $route->getTarget();
         // Isolate the namespace portion of a FQ class name
         $namespace = explode('\\', $target);
         array_pop($namespace);
         $namespace = implode('\\', $namespace);
         // TODO: getTarget() may be a view which may need to be
         // inspected. Assume namespaces will coincide
         if (isset($applications[$namespace])) {
             try {
                 $app = $applications[$namespace];
                 $reverser = new Reverser($app);
                 return $reverser->reverse($view, $args, $method);
             } catch (Route404 $ex) {
                 // Fall through
             }
         } elseif ($route->getTarget() != $view) {
             continue;
         } elseif (!$args || $args && $route->matchesArgs($args)) {
             // TODO: Consider URL path from recursed reversing. It
             // should be prepended.
             return $route->getUrl($args);
         }
     }
     throw new Exception\Route404($view . ': No reverse found with supplied args');
 }
Exemple #2
0
function mail_admins($subject, $body, $attachments = array(), $options = array())
{
    $settings = Project::currentProject()->getSettings();
    $recipients = $settings['ADMINS'];
    // TODO: Massage the recipients list format
    Mailer::send($recipients, $subject, $body, $attachments, $options);
}
Exemple #3
0
 /**
  * tryAddConnection
  *
  * Attempt to add a new connection, by name, from the current project's
  * configuration settings.
  *
  * Returns:
  * <bool> TRUE upon success.
  */
 protected function tryAddConnection($key)
 {
     $databases = Project::getCurrent()->getSetting('DATABASES');
     if ($databases && is_array($databases) && isset($databases[$key])) {
         $this->addConnection($databases[$key], $key);
         return true;
     }
 }
Exemple #4
0
 function _getContext($request)
 {
     $base = $this->context;
     foreach (Project::getCurrent()->getTemplateContexts() as $TCP) {
         $I = new $TCP();
         $base->update($I->getContext($request));
     }
     return $base;
 }
Exemple #5
0
 function getFinders()
 {
     $settings = Project::getCurrent()->getSettings();
     $finders = $settings->get('STATICFILES_FINDERS', []);
     foreach ($finders as $idx => $F) {
         if (is_string($F)) {
             $finders[$idx] = new $F();
         }
     }
     return $finders;
 }
Exemple #6
0
 static function getLoader($request)
 {
     if (!($app = Project::getCurrent()->getCurrentApp())) {
         return false;
     }
     $root = $app->getFilesystemRoot();
     $dir = $request->getSettings()->get('TEMPLATE_DIR', 'Templates');
     // Add the local application as the root namespace
     $loader = new \Twig_Loader_Filesystem("{$root}/{$dir}");
     return $loader;
 }
Exemple #7
0
 function findInstalledCliApps()
 {
     $discovered = new Util\ArrayObject();
     $apps = Project::getCurrent()->getApplications();
     foreach ($apps as $A) {
         foreach ($A->getCliModules() as $mod) {
             // TODO: Error if there is already a mod under this name
             $section = $discovered->setDefault($A->getName(), new Util\ArrayObject());
             $section[$A->getLabel() . ':' . $mod->getName()] = $mod;
         }
     }
     return $discovered;
 }
Exemple #8
0
 static function getLoader($request)
 {
     $loader = new \Twig_Loader_Filesystem();
     $project = Project::getCurrent();
     foreach ($project->getSetting('TEMPLATE_DIRS', []) as $dir) {
         $dir = realpath($dir);
         if (is_dir($dir)) {
             $loader->addPath($dir);
         }
     }
     $loader->addPath(dirname(__DIR__) . '/BuiltIn/');
     return $loader;
 }
Exemple #9
0
 function getIterator()
 {
     $paths = array();
     $project = Project::getCurrent();
     foreach ($project->getApplications() as $A) {
         $root = $A->getFilesystemRoot();
         $full = "{$root}/Static";
         if (!is_dir($full)) {
             continue;
         }
         $paths[] = $full;
     }
     return $this->iterPaths($paths);
 }
Exemple #10
0
 function run($args, $options)
 {
     $project = Project::getCurrent();
     $root = $project->getFilesystemRoot() . '/';
     $settings = $project->getSettings();
     $static_url = $settings->get('STATIC_URL');
     foreach ($settings->get('STATICFILES_FINDERS') as $F) {
         if (is_string($F)) {
             $F = new $F();
         }
         foreach ($F as $file) {
             $file = $file->getFullPath();
             if (strpos($file, $root) !== false) {
                 $file = '(project)/' . substr($file, strlen($root));
             }
             $this->stderr->writeline($file);
         }
     }
 }
Exemple #11
0
 protected function setupInternal()
 {
     $this->internal = array();
     $settings = Project::getCurrent()->getSettings();
     // 1. Remote address (for IP binding)
     $bind_ip = isset($bind_ip) ? $bind_ip : (isset($settings['SESSION_BIND_IP']) ? $settings['SESSION_BIND_IP'] : static::$bind_ip);
     if ($bind_ip) {
         $this->internal['ip'] = $request->getRemoteAddress();
     }
     // 2. If the current request is HTTPS, so the session can be
     //    checked later for validity
     $this->internal['https'] = $request->isHttps();
 }
Exemple #12
0
 function loadMiddleware()
 {
     $this->middleware = Project::getCurrent()->getMiddleware();
 }
Exemple #13
0
 function resolve($url, $args = null, $setCurrentProject = true)
 {
     $disp = $this->getDispatcher();
     if ($setCurrentProject) {
         Project::getCurrent()->setCurrentApp($this);
     }
     if ($disp) {
         return $disp->resolve($url, $args);
     }
 }