Exemplo n.º 1
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');
 }
Exemplo n.º 2
0
 /**
  * Testing the doGET method.
  */
 public function testDoGET()
 {
     $config = ConfigProvider::getInstance();
     $sessionProvider = $config->get('session.provider.name');
     $session = SessionProviderFactory::getInstance($sessionProvider);
     $front = new FrontController();
     $controller = new LogoutController();
     $securityParams = $controller->generateSecurityFields();
     $person = $this->createPersonObject('logintest');
     $person->save();
     $params = array('loginBut' => true, 'var1' => $securityParams[0], 'var2' => $securityParams[1], 'email' => '*****@*****.**', 'password' => 'passwordTest');
     $request = new Request(array('method' => 'POST', 'URI' => '/login', 'params' => $params));
     $response = $front->process($request);
     $this->assertEquals(301, $response->getStatus(), 'Testing the doPOST with correct password');
     $this->assertTrue($session->get('currentUser') instanceof Person, 'Testing that the user is logged in');
     $request = new Request(array('method' => 'GET', 'URI' => '/logout'));
     $response = $front->process($request);
     $this->assertEquals(200, $response->getStatus(), 'Testing the doGET method');
     $this->assertEquals('text/html', $response->getHeader('Content-Type'), 'Testing the doGET method');
     $this->assertFalse($session->get('currentUser'), 'Testing that the user is no longer logged in');
 }