コード例 #1
0
ファイル: Controller.class.php プロジェクト: gaetanm/caphpy
 /**
  * Orders to the DbConnectionHandler to create a PDO instance. This function can be used 
  * when two or more connections need to be etablished in the same controller function.
  *
  * @param string $dbInfoKey
  *
  * @throws DbConnectionHandlerException
  * @throws PDOException
  */
 protected function connectDb($dbInfoKey = null)
 {
     try {
         DbConnectionHandler::createPDOInstance($dbInfoKey);
     } catch (DbConnectionHandlerException $e) {
         ExceptionHandler::displayException($e);
     } catch (PDOException $e) {
         ExceptionHandler::displayException($e);
     }
 }
コード例 #2
0
ファイル: Page.class.php プロジェクト: gaetanm/caphpy
 /**
  * Displays the input element.
  *
  * @param string $element
  */
 public function display($element = null)
 {
     if ($element === null) {
         $element = self::APP_VIEW_DIR . $this->view;
     } else {
         $element = self::INC_DIR . $element;
     }
     try {
         if (!is_file($element)) {
             throw new PageException('Page error: missing element to display ("' . $element . '" given)');
         }
     } catch (PageException $e) {
         ExceptionHandler::displayException($e);
     }
     include $element;
 }
コード例 #3
0
ファイル: Dispatcher.class.php プロジェクト: gaetanm/caphpy
 /**
  * Performs the request.
  *
  * @param Request $request
  *
  * @throws DispatcherException
  * @throws MissingRessourceException
  */
 public static function dispatch($request)
 {
     try {
         $controller = self::createController($request->getController());
     } catch (DispatcherException $e) {
         ExceptionHandler::displayException($e);
     }
     $action = $request->getAction();
     if ($action === null) {
         $action = $controller->getDefaultAction();
     }
     if (!method_exists($controller, $action)) {
         throw new DispatcherException('Dispatcher error: The ' . $action . ' method doesn\'t exist');
     }
     $rController = new \ReflectionClass(get_class($controller));
     $method = $rController->getMethod($action);
     if (!$method->isPublic()) {
         throw new DispatcherException('Dispatcher error: The ' . $action . ' method is private');
     }
     $controller->setRequest($request);
     if (in_array('sys\\core\\SController', class_parents($controller))) {
         self::parseSecurisedController($controller, $action);
     } else {
         try {
             $controller->{$action}();
         } catch (MissingRessourceException $e) {
             throw $e;
         }
     }
 }
コード例 #4
0
ファイル: index.php プロジェクト: gaetanm/caphpy
 * along with CaPHPy.  If not, see <http://www.gnu.org/licenses/>.
 */
require 'app/etc/sys.conf.php';
require 'app/etc/db.conf.php';
require 'sys/core/Loader.class.php';
define('DB_INFO', serialize($dbInfo));
define('JS_DIR', ROOT_DIR . '/app/public/js/');
define('CSS_DIR', ROOT_DIR . '/app/public/css/');
define('IMG_DIR', ROOT_DIR . '/app/public/img/');
use sys\core\Loader;
use sys\core\Dispatcher;
use sys\core\Router;
use sys\core\ExceptionHandler;
use sys\error\MissingRessourceException;
use sys\error\DispatcherException;
use sys\error\RouterException;
Loader::register();
require 'app/etc/route.conf.php';
$router = new Router($routingTable);
try {
    $request = $router->getRequest($_GET, $_POST, $_FILES);
    try {
        Dispatcher::dispatch($request);
    } catch (DispatcherException $e) {
        ExceptionHandler::displayException($e);
    } catch (MissingRessourceException $e) {
        ExceptionHandler::displayException($e);
    }
} catch (RouterException $e) {
    ExceptionHandler::displayException($e);
}
コード例 #5
0
ファイル: Model.class.php プロジェクト: gaetanm/caphpy
 /**
  * Updates the actual instance of the database by using its properties.
  */
 public function update()
 {
     $data = get_object_vars($this);
     if (!isset($this->pk)) {
         $id = 'id';
     } else {
         $id = $this->pk;
     }
     unset($data['fk']);
     unset($data['pk']);
     $val = $data[$id];
     try {
         $data = self::parseUpdateData($data);
         $inputQuery = "WHERE {$id} = ?";
         $param = $val;
         $param = self::parseQuery($inputQuery, $param);
         $param = array_merge($data[1], $param);
         $query = 'UPDATE ' . self::getTableName() . ' SET ' . $data[0] . ' ' . $inputQuery;
         if (!array_key_exists($query, self::$stmt)) {
             self::$stmt[$query] = self::getPDO()->prepare($query);
         }
         $q = self::$stmt[$query];
         $q->execute($param);
     } catch (PDOException $e) {
         ExceptionHandler::displayException($e);
     }
 }