Beispiel #1
0
 public function testControllerize()
 {
     $this->assertEqual(TipyInflector::controllerize('welcome'), 'Welcome');
     $this->assertEqual(TipyInflector::controllerize('wELcOmE'), 'Welcome');
     $this->assertEqual(TipyInflector::controllerize('welcomes'), 'Welcomes');
     $this->assertEqual(TipyInflector::controllerize('welcome_home'), 'WelcomeHome');
     $this->assertEqual(TipyInflector::controllerize('welcome_homes'), 'WelcomeHomes');
     $this->assertEqual(TipyInflector::controllerize('welcomehomes'), 'Welcomehomes');
     $this->assertEqual(TipyInflector::controllerize('123welcomes'), '123welcomes');
     $this->assertEqual(TipyInflector::controllerize('projects'), 'Projects');
     $this->assertEqual(TipyInflector::controllerize('big_projects'), 'BigProjects');
     $this->assertEqual(TipyInflector::controllerize('mice'), 'Mice');
 }
Beispiel #2
0
 /**
  * Return foreign key name for foreign table
  *
  * You may override this method to change the rules
  *
  * @param string $tableName
  * @return string
  */
 protected static function tableForeignKeyFieldName($tableName)
 {
     return TipyInflector::singularize($tableName) . "_id";
 }
Beispiel #3
0
 /**
  * Initialize controller and run action
  *
  * Requires **$app->in('controller')** and **$app->in('action')**
  * parameters to be defined.
  *
  * @see TipyController
  * @todo Different exceptions handling in production and development modes
  */
 public function run()
 {
     $this->logger->debug($this->request->method() . ': ' . $this->request->uri());
     try {
         // Get controller and action name
         $controllerName = $this->in->get('controller');
         $actionName = $this->in->get('action');
         // Some basic checking
         if (!$controllerName || preg_match('/^\\W*$/', $controllerName)) {
             throw new TipyException('Controller name is missing');
         }
         if (!$actionName || preg_match('/^\\W*$/', $actionName)) {
             throw new TipyException('Action name is missing');
         }
         $controllerName = TipyInflector::controllerize($controllerName) . 'Controller';
         if (class_exists($controllerName)) {
             $controller = new $controllerName();
         } else {
             throw new TipyException('Unable to find ' . $controllerName . ' class');
         }
         $actionName = TipyInflector::camelCase($actionName);
         if (in_array($actionName, get_class_methods($controllerName))) {
             $this->logger->debug('Executing ' . $controllerName . '::' . $actionName . '();');
             $controller->execute($actionName);
         } else {
             throw new TipyException('Undefined action ' . $controllerName . '::' . $actionName . '()');
         }
     } catch (Exception $exception) {
         throw new TipyException($exception->getMessage(), $exception->getCode(), $exception);
     }
 }