Ejemplo n.º 1
0
 /**
  * Testing the createApplicationDirs method.
  */
 public function testCreateApplicationDirs()
 {
     $controller = new InstallController();
     $testInstallDir = '/tmp/alphainstalltestdir';
     $config = ConfigProvider::getInstance();
     $config->set('app.root', $testInstallDir . '/');
     $config->set('app.file.store.dir', $testInstallDir . '/store/');
     if (!file_exists($testInstallDir)) {
         mkdir($testInstallDir);
     }
     if (!file_exists($testInstallDir . '/store')) {
         mkdir($testInstallDir . '/store');
     }
     $controller->createApplicationDirs();
     $this->assertTrue(file_exists($testInstallDir . '/src'));
     $this->assertTrue(file_exists($testInstallDir . '/src/Model'));
     $this->assertTrue(file_exists($testInstallDir . '/src/View'));
     $this->assertTrue(file_exists($testInstallDir . '/store/logs'));
     $this->assertTrue(file_exists($testInstallDir . '/store/attachments'));
     $this->assertTrue(file_exists($testInstallDir . '/store/cache'));
     $this->assertTrue(file_exists($testInstallDir . '/store/cache/html'));
     $this->assertTrue(file_exists($testInstallDir . '/store/cache/images'));
     $this->assertTrue(file_exists($testInstallDir . '/store/cache/pdf'));
     $this->assertTrue(file_exists($testInstallDir . '/store/cache/xls'));
 }
Ejemplo n.º 2
0
 /**
  * The constructor method.
  *
  * @throws Alpha\Exception\BadRequestException
  *
  * @since 1.0
  */
 public function __construct()
 {
     self::$logger = new Logger('FrontController');
     self::$logger->debug('>>__construct()');
     $config = ConfigProvider::getInstance();
     mb_internal_encoding('UTF-8');
     mb_http_output('UTF-8');
     mb_http_input('UTF-8');
     ini_set('default_charset', 'utf-8');
     if (!mb_check_encoding()) {
         throw new BadRequestException('Request character encoding does not match expected UTF-8');
     }
     $this->addRoute('/', function ($request) {
         $controller = new IndexController();
         return $controller->process($request);
     });
     $this->addRoute('/a/{title}/{view}', function ($request) {
         $controller = new ArticleController();
         return $controller->process($request);
     })->value('title', null)->value('view', 'detailed');
     $this->addRoute('/articles/{start}/{limit}', function ($request) {
         $controller = new ArticleController();
         return $controller->process($request);
     })->value('start', 0)->value('limit', $config->get('app.list.page.amount'));
     $this->addRoute('/attach/{articleOID}/{filename}', function ($request) {
         $controller = new AttachmentController();
         return $controller->process($request);
     });
     $this->addRoute('/cache', function ($request) {
         $controller = new CacheController();
         return $controller->process($request);
     });
     $this->addRoute('/denum/{denumOID}', function ($request) {
         $controller = new DEnumController();
         return $controller->process($request);
     })->value('denumOID', null);
     $this->addRoute('/excel/{ActiveRecordType}/{ActiveRecordOID}', function ($request) {
         $controller = new ExcelController();
         return $controller->process($request);
     })->value('ActiveRecordOID', null);
     $this->addRoute('/feed/{ActiveRecordType}/{type}', function ($request) {
         $controller = new FeedController();
         return $controller->process($request);
     })->value('type', 'Atom');
     $this->addRoute('/gensecure', function ($request) {
         $controller = new GenSecureQueryStringController();
         return $controller->process($request);
     });
     $this->addRoute('/image/{source}/{width}/{height}/{type}/{quality}/{scale}/{secure}/{var1}/{var2}', function ($request) {
         $controller = new ImageController();
         return $controller->process($request);
     })->value('var1', null)->value('var2', null);
     $this->addRoute('/listactiverecords', function ($request) {
         $controller = new ListActiveRecordsController();
         return $controller->process($request);
     });
     $this->addRoute('/log/{logPath}', function ($request) {
         $controller = new LogController();
         return $controller->process($request);
     });
     $this->addRoute('/login', function ($request) {
         $controller = new LoginController();
         return $controller->process($request);
     });
     $this->addRoute('/logout', function ($request) {
         $controller = new LogoutController();
         return $controller->process($request);
     });
     $this->addRoute('/metric', function ($request) {
         $controller = new MetricController();
         return $controller->process($request);
     });
     $this->addRoute('/recordselector/12m/{ActiveRecordOID}/{field}/{relatedClass}/{relatedClassField}/{relatedClassDisplayField}/{relationType}', function ($request) {
         $controller = new RecordSelectorController();
         return $controller->process($request);
     })->value('relationType', 'ONE-TO-MANY');
     $this->addRoute('/recordselector/m2m/{ActiveRecordOID}/{field}/{relatedClassLeft}/{relatedClassLeftDisplayField}/{relatedClassRight}/{relatedClassRightDisplayField}/{accessingClassName}/{lookupOIDs}/{relationType}', function ($request) {
         $controller = new RecordSelectorController();
         return $controller->process($request);
     })->value('relationType', 'MANY-TO-MANY');
     $this->addRoute('/search/{query}/{start}/{limit}', function ($request) {
         $controller = new SearchController();
         return $controller->process($request);
     })->value('start', 0)->value('limit', $config->get('app.list.page.amount'));
     $this->addRoute('/sequence/{start}/{limit}', function ($request) {
         $controller = new SequenceController();
         return $controller->process($request);
     })->value('start', 0)->value('limit', $config->get('app.list.page.amount'));
     $this->addRoute('/tag/{ActiveRecordType}/{ActiveRecordOID}', function ($request) {
         $controller = new TagController();
         return $controller->process($request);
     });
     $this->addRoute('/install', function ($request) {
         $controller = new InstallController();
         return $controller->process($request);
     });
     $this->addRoute('/record/{ActiveRecordType}/{ActiveRecordOID}/{view}', function ($request) {
         $controller = new ActiveRecordController();
         return $controller->process($request);
     })->value('ActiveRecordOID', null)->value('view', 'detailed');
     $this->addRoute('/records/{ActiveRecordType}/{start}/{limit}', function ($request) {
         $controller = new ActiveRecordController();
         return $controller->process($request);
     })->value('start', 0)->value('limit', $config->get('app.list.page.amount'));
     $this->addRoute('/tk/{token}', function ($request) {
         $params = self::getDecodeQueryParams($request->getParam('token'));
         if (isset($params['act'])) {
             $className = $params['act'];
             if (class_exists($className)) {
                 $controller = new $className();
                 if (isset($params['ActiveRecordType']) && $params['act'] == 'Alpha\\Controller\\ActiveRecordController') {
                     $customController = $controller->getCustomControllerName($params['ActiveRecordType']);
                     if ($customController != null) {
                         $controller = new $customController();
                     }
                 }
                 $request->setParams(array_merge($params, $request->getParams()));
                 return $controller->process($request);
             }
         }
         self::$logger->warn('Bad params [' . print_r($params, true) . '] provided on a /tk/ request');
         return new Response(404, 'Resource not found');
     });
     $this->addRoute('/alpha/service', function ($request) {
         $controller = new LoginController();
         $controller->setUnitOfWork(array('Alpha\\Controller\\LoginController', 'Alpha\\Controller\\ListActiveRecordsController'));
         return $controller->process($request);
     });
     $this->addRoute('/phpinfo', function ($request) {
         $controller = new PhpinfoController();
         return $controller->process($request);
     });
     self::$logger->debug('<<__construct');
 }