示例#1
0
 function __construct($invocation)
 {
     parent::__construct($invocation);
     // can easily set skin parameters for ALL views in this module in the constructor
     $skin = $this->invocation()->rootSkin();
     if ($skin) {
         $skin->setTitle('PHOCOA Examples');
     }
 }
示例#2
0
 /**
  *  Parses the invocationPath, looks for the module, instantiates the module, etc.
  *
  *  This is where {@link WFAuthorizationManager module security} is applied. If the page requies login to continue, the system will redirect to a login page,
  *  and will redirect back to the initial page upon successful login.
  *
  *  NOTE: Will convert WFNull params into NULL values.
  *
  *  @throws Various exceptions in setting up the module.
  *  @todo This doesn't seem super-clean... I don't understand needsRedirect, and throwing exceptions for redir causes problems with quickModule() not being able to use shorthand invocation paths, and it doesn't trip the !isRootInvocation() check...
  */
 private function extractComponentsFromInvocationPath()
 {
     // walk path looking for the module -- keep "blank" entry when "//" encountered.
     $pathInfoParts = preg_split('/\\//', trim($this->invocationPath, '/'), -1);
     $modulesDirPath = WFWebApplication::appDirPath(WFWebApplication::DIR_MODULES);
     foreach (WFWebApplication::sharedWebApplication()->modulePaths() as $prefix => $dir) {
         if (strpos($this->invocationPath, $prefix) === 0) {
             $modulesDirPath = realpath($dir . '/..');
         }
     }
     // this block determines modulePath, moduleName, and pageName [optionally]
     //print "URI: {$this->invocationPath}<BR>";
     //print_r($pathInfoParts);
     $foundModule = false;
     $modulePath = $possibleModulePath = '';
     $moduleName = NULL;
     $pageName = NULL;
     $partsUsedBeforeModule = 0;
     foreach ($pathInfoParts as $part) {
         // recurse into directories until there are no more dirs to drop into
         $possibleModulePath .= '/' . $part;
         $possibleSubModule = $modulesDirPath . $possibleModulePath;
         //print "Testing to see if there is a directory at: '$possibleSubModule' ($possibleModulePath).<BR>";
         if (is_dir($possibleSubModule)) {
             //print "Directory found<br>";
             $modulePath .= '/' . $part;
             $moduleName = $part;
             $partsUsedBeforeModule++;
             continue;
         } else {
             $pageName = $part;
             //print "No Directory found... will look for module<br>";
             break;
         }
     }
     //print "Only POssible ModulePath: $modulePath<Br />";
     if ($partsUsedBeforeModule < 1) {
         $possibleModuleFilePath = NULL;
     } else {
         $possibleModuleFilePath = $modulesDirPath . $modulePath . '/' . $pathInfoParts[$partsUsedBeforeModule - 1] . '.php';
     }
     if (file_exists($possibleModuleFilePath)) {
         //print "Found module at $possibleModuleFilePath<BR>";
         $foundModule = true;
         $this->modulePath = ltrim($modulePath, '/');
         $this->moduleName = $moduleName;
         $this->pageName = $pageName;
         $this->setModulesDir($modulesDirPath);
     }
     //print "MP: {$this->modulePath}<br>Mod:{$this->moduleName}<BR>Page: {$this->pageName}<BR>Params:" . print_r($this->invocationParameters,true) . "<BR>";
     if (!$foundModule) {
         throw new WFRequestController_NotFoundException("Module 404: invocation path '{$this->invocationPath}' could not be found.");
     }
     if (empty($this->moduleName) or empty($this->pageName)) {
         // test - i don't think !$moduleName can happen. can refactor needsRedirect to if (empty(pageName)) if true...
         if (empty($this->moduleName)) {
             throw new WFException("empty moduleName - don't expect that this can even happen.");
         }
         // also, the only need for needsRedirect I *think* is if the URL is "/<moduleName>/?" and NO extra info. it's basically just a simple shortcut to redirect to "default" page.
         // it only kicks in if allPages() is not set up. With allPages() defined, then I don't think it can happen.
         // @todo there may be a better way to handle this case. consider refactoring.
         $needsRedirect = true;
     } else {
         $needsRedirect = false;
     }
     // i don't think this line ever can execture...
     if (empty($this->moduleName)) {
         throw new WFRequestController_NotFoundException("Module 404: No module name could be determined from {$this->invocationPath}.");
     }
     // if we get here, we're guaranteed that a modulePath is valid.
     // load module instance
     $this->module = WFModule::factory($this);
     // Calculate Parameters for the page
     // test to see if what we think is the page name IS a page in the module. If so, proceed as normal. If not, assume it's the first parameter of the default page.
     if ($this->pageName) {
         $params = array();
         $modulePages = $this->module->allPages();
         if (count($modulePages) == 0 or in_array($this->pageName, $modulePages)) {
             // a page was detected; skip one pathpart to get to params
             if (count($pathInfoParts) > 2) {
                 $params = array_slice($pathInfoParts, $partsUsedBeforeModule + 1);
             }
         } else {
             // no page detected; params start now; send to default page
             $this->pageName = $this->module->defaultPage();
             if (count($pathInfoParts) > 1) {
                 $params = array_slice($pathInfoParts, $partsUsedBeforeModule);
             }
         }
         // parse out parameter data from URL
         if (count($params)) {
             foreach ($params as $k => $v) {
                 if ($v === WFModuleInvocation::PARAMETER_NULL_VALUE) {
                     $params[$k] = NULL;
                 } else {
                     $params[$k] = urldecode($v);
                 }
             }
             $this->invocationParameters = $params;
         }
     }
     // determine default page
     if (empty($this->pageName)) {
         $this->pageName = $this->module->defaultPage();
     }
     if (empty($this->pageName)) {
         throw new WFException("No page could be determined. Make sure you are supplying an page in the invocation path or have your module supply a defaultPage.");
     }
     // redirect as needed - this doesn't make sense inside of WFModuleInvocation...
     // of course cannot have invocationParameters from invocationPath unless module and pageName are specified
     if ($needsRedirect) {
         if ($this->isRootInvocation()) {
             // should be internal redirect to preserve pretty urls
             throw new WFRequestController_InternalRedirectException(WFRequestController::WFURL($this->modulePath, $this->pageName));
             //header('Location: ' . WFRequestController::WFURL($this->modulePath, $this->pageName));
             //exit;
         } else {
             throw new WFException("You must specify a complete invocationPath.");
         }
     }
 }
示例#3
0
 function __construct($inv)
 {
     parent::__construct($inv);
     $path = $this->pathToModule() . '/../../widgets/exampleClasses.php';
     require $path;
 }
示例#4
0
 function __construct($i)
 {
     parent::__construct($i);
     $this->propelDBMap = NULL;
     $this->readConfig();
 }