예제 #1
0
 /**
  * @param Request $request
  * @param Response $response
  * @return bool
  */
 public function run(Request $request, Response $response)
 {
     $controller = $request->getController();
     $action = $request->getAction();
     $controllerContent = $controller->runAction($action, [$request, $response]);
     $request->data['controllerContent'] = $controllerContent;
     return true;
 }
예제 #2
0
 /**
  * @param Request $request
  * @param Response $response
  * @return bool
  */
 public function run(Request $request, Response $response)
 {
     $view = $request->getView();
     ob_start();
     extract($request->data['controllerContent']);
     include PATH_ROOT . '/views/' . $view . '.php';
     $viewContent = ob_get_contents();
     ob_end_clean();
     $response->setContent($viewContent);
     return true;
 }
예제 #3
0
 /**
  * @param Request $request
  * @param Response $response
  * @return bool
  */
 public function run(Request $request, Response $response)
 {
     ob_start();
     $content = $response->getContent();
     $layout = $request->getLayout();
     include PATH_ROOT . '/views/layouts/' . $layout . '.php';
     $layoutContent = ob_get_contents();
     ob_end_clean();
     $response->setBody($layoutContent);
     return true;
 }
예제 #4
0
 /**
  * Método responsável por obter o nome do controlador e do método e executá-los.
  * @access public
  * @return void
  */
 public static function run()
 {
     ob_start();
     //pega o controller na URL
     Request::run();
     Session::start();
     $controller = Request::getCompleteController();
     //verifica se o controlador existe
     if (file_exists(PATH_CONTROLLER . $controller . '.php')) {
         //instancia o controlador
         $controlador = NAMESPACE_CONTROLLER . "\\" . $controller;
         $controlador = new $controlador();
         //pega o metodo da URL
         $action = Request::getAction();
         //Transforma o resto da URL em Array
         $args = (array) Request::getArgs();
         //verifica se o metodo existe no controlador
         $post = self::VerificaMetodo($controlador, $action);
     } else {
         Request::InverseArea();
         $area = Request::getArea();
         $controller = Request::getCompleteController();
         if (file_exists(PATH_AREA . $area . DS . 'Controllers' . DS . $controller . '.php')) {
             //instancia o controlador
             $controlador = NAMESPACE_AREAS . "\\" . $area . "\\Controllers\\" . $controller;
             $controlador = new $controlador();
             //pega o metodo da URL
             $action = Request::getAction();
             //Transforma o resto da URL em Array
             $args = (array) Request::getArgs();
             $post = self::VerificaMetodo($controlador, $action);
         } else {
             if (file_exists(PATH_CONTROLLER . CONTROLLER_404 . '.php')) {
                 Request::setController(CONTROLLER_404);
                 Request::setAction(ACTION_404);
                 Request::setArea(null);
                 $controlador = NAMESPACE_CONTROLLER . '\\' . CONTROLLER_404;
                 $controlador = new $controlador();
                 $action = ACTION_404;
                 //Transforma o resto da URL em Array
                 $args = (array) Request::getArgs();
                 $post = self::VerificaMetodo($controlador, $action);
             }
         }
     }
     self::getPost($args);
     //        try {
     call_user_func_array(array($controlador, $action . $post), $args);
     //        }catch (\Exception $e){
     //            echo $e->getMessage();
     //        }
     $content = ob_get_clean();
     Layout::render($content);
 }
예제 #5
0
 public function getMatch(Request $request)
 {
     $path = $request->getPath();
     $matches = [];
     $data = ['route' => '/', 'matches' => []];
     foreach ($this->_routes as $rule => $route) {
         if (isset($this->_paths[$path])) {
             $data = $this->_paths[$path];
             break;
         }
         $regex = "/<(.+?):(.+?)>/";
         $rule = preg_replace($regex, '(?P<\\1>\\2)', $rule);
         $regex = addcslashes($rule, '/');
         if (preg_match("/{$regex}/", $path, $matches)) {
             $data = ['matches' => $matches, 'route' => $route];
             $this->_paths[$path] = $data;
             break;
         }
     }
     return $data;
 }
예제 #6
0
 static function getUrl($action, $controller = null, $area = null)
 {
     if ($controller == null) {
         $controller = Request::getController();
     }
     if ($area == null && $controller != CONTROLLER_404) {
         $area = Request::getArea();
     }
     $url = URL;
     if ($area != null) {
         $url .= $area . "/";
     }
     $url .= (ucfirst($controller) == ucfirst(DEFAULT_CONTROLLER_ABV) && ucfirst($action) == ucfirst(DEFAULT_VIEW) ? "" : ucfirst($controller) . "/") . (ucfirst($action) == ucfirst(DEFAULT_VIEW) ? "" : ucfirst($action));
     return $url;
 }
예제 #7
0
파일: View.php 프로젝트: gueff/mymvc
 /**
  * instantiates smarty object and set major smarty configs
  * 
  * @access public
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $this->sTemplateDir = \mvc\registry::get('MVC_MODULES') . '/' . \mvc\Request::getInstance()->getModule() . '/templates';
     $this->sTemplate = Registry::get('MVC_SMARTY_TEMPLATE_DEFAULT');
     $this->iSmartyVersion = (int) preg_replace('/[^0-9]+/', '', self::SMARTY_VERSION);
     $this->setAbsolutePathToTemplateDir();
     $this->setCompileDir(\MVC\Registry::get('MVC_SMARTY_TEMPLATE_CACHE_DIR'));
     $this->setCacheDir(\MVC\Registry::get('MVC_SMARTY_CACHE_DIR'));
     $this->caching = \MVC\Registry::get('MVC_SMARTY_CACHE_STATUS');
     $aPlugInDir = array(\MVC\Registry::get('MVC_APPLICATION_PATH') . '/vendor/smarty/smarty/libs/plugins/');
     \MVC\Registry::isRegistered('MVC_SMARTY_PLUGINS_DIR') ? $aPlugInDir = array_merge($aPlugInDir, \MVC\Registry::get('MVC_SMARTY_PLUGINS_DIR')) : false;
     $this->setPluginsDir($aPlugInDir);
     $this->checkDirs();
     \MVC\Event::BIND('mvc.view.echoOut.off', function () {
         MVC_View::$bEchoOut = false;
     });
     \MVC\Event::BIND('mvc.view.echoOut.on', function () {
         MVC_View::$bEchoOut = true;
     });
 }
예제 #8
0
 public function actionDetail(Request $request, Response $response)
 {
     $newsId = $request->getRequestData()['newsId'];
     $request->setView('site/details');
     return News::getByIdOr404($newsId);
 }
예제 #9
0
파일: View.php 프로젝트: gueff/mymvc
 /**
  * set absolute Path to Smarty Template Dir and saves this into includePath
  * 
  * @access public
  * @param string $sAbsolutePathToTemplateDir
  * @return void
  */
 public function setAbsolutePathToTemplateDir($sAbsolutePathToTemplateDir = '')
 {
     if ($sAbsolutePathToTemplateDir === '') {
         $aQueryArray = \MVC\Request::getInstance()->getQueryArray();
         array_key_exists(Registry::get('MVC_GET_PARAM_MODULE'), $aQueryArray['GET']) ? $sAbsolutePathToTemplateDir = realpath(\MVC\Registry::get('MVC_MODULES') . '/' . $aQueryArray['GET'][Registry::get('MVC_GET_PARAM_MODULE')] . '/templates/') : false;
     }
     if (is_dir($sAbsolutePathToTemplateDir)) {
         $aIncludePath = explode(PATH_SEPARATOR, get_include_path());
         if (!in_array($sAbsolutePathToTemplateDir, $aIncludePath)) {
             $aIncludePath[] = $sAbsolutePathToTemplateDir;
         }
         $sImplodePaths = implode(PATH_SEPARATOR, $aIncludePath);
         set_include_path($sImplodePaths);
     }
     $this->setTemplateDir($sAbsolutePathToTemplateDir);
 }
예제 #10
0
파일: IDS.php 프로젝트: gueff/mymvc
 /**
  * dispose affected Variables
  * 
  * @param \IDS\Report $oIdsReport
  * @access public
  * @static
  */
 public static function dispose(\IDS\Report $oIdsReport)
 {
     $aName = array();
     $aDisposed = array();
     // get Name of Variables
     foreach ($oIdsReport->getIterator() as $oEvent) {
         $aName[] = $oEvent->getName();
     }
     // iterate infected and dispose those
     foreach ($aName as $sName) {
         // get Type and Key
         $aType = explode('.', $sName);
         $sType = isset($aType[0]) ? $aType[0] : '';
         $sKey = isset($aType[1]) ? $aType[1] : '';
         $aAffected = isset($GLOBALS['_' . $sType][$sKey]) ? $GLOBALS['_' . $sType][$sKey] : array();
         if (!empty($aAffected)) {
             if ('GET' == $sType) {
                 if (isset($_GET[$sKey])) {
                     $_GET[$sKey] = null;
                     unset($_GET[$sKey]);
                 }
             }
             if ('POST' == $sType) {
                 if (isset($_POST[$sKey])) {
                     $_POST[$sKey] = null;
                     unset($_POST[$sKey]);
                 }
             }
             if ('COOKIE' == $sType) {
                 if (isset($_COOKIE[$sKey])) {
                     $_COOKIE[$sKey] = null;
                     unset($_COOKIE[$sKey]);
                 }
             }
             $aDisposed[] = $sType . '[' . $sKey . ']';
             \MVC\Log::WRITE("INFO\tdisposed: " . $sType . '[' . $sKey . ']', 'ids.log');
             // overwrite
             $oRequest = Request::getInstance();
             $oRequest->saveRequest();
         }
     }
     \MVC\Registry::set('MVC_IDS_DISPOSED', $aDisposed);
 }
예제 #11
0
 /**
  * @return string
  */
 private function getClassModel()
 {
     //fora das areas
     if (Request::getArea() == null) {
         return $model = NAMESPACE_MODELS . '\\' . Request::getController();
     }
     //dentro das areas
     return NAMESPACE_AREAS . '\\' . Request::getArea() . '\\' . 'Models' . '\\' . Request::getController();
 }
예제 #12
0
파일: Index.php 프로젝트: gueff/mymvc
 /**
  * collects all Info for being displayed by the Toolbar
  * 
  * @access private
  * @param \Smarty $oView
  * @return array $aToolbar containing all Info for toolbar
  */
 private function collectInfo(\Smarty $oView)
 {
     $aToolbar = array();
     $aToolbar['sPHP'] = phpversion();
     $aToolbar['sOS'] = PHP_OS;
     $aToolbar['sEnv'] = \MVC\Registry::get('MVC_ENV');
     $aToolbar['aGet'] = array_map('htmlentities', $_GET);
     $aToolbar['aPost'] = array_map('htmlentities', $_POST);
     $aToolbar['aCookie'] = array_map('htmlentities', $_COOKIE);
     $aToolbar['aRequest'] = array_map('htmlentities', $_REQUEST);
     $aToolbar['aSession'] = $_SESSION;
     $aToolbar['aSmartyTemplateVars'] = $oView->getTemplateVars();
     $aConstants = get_defined_constants(true);
     $aToolbar['aConstant'] = $aConstants['user'];
     $aToolbar['aServer'] = $_SERVER;
     $aToolbar['oMvcRequestGetWhitelistParams'] = \MVC\Request::getInstance()->getWhitelistParams();
     $aToolbar['oMvcRequestGetQueryArray'] = \MVC\Request::getInstance()->getQueryArray();
     $aToolbar['aEvent'] = \MVC\Registry::isRegistered('MVC_EVENT') ? \MVC\Registry::get('MVC_EVENT') : array();
     $aRequest = \MVC\Request::GETCURRENTREQUEST();
     $aToolbar['aRouting'] = array('aRequest' => \MVC\Request::GETCURRENTREQUEST(), 'sModule' => \MVC\Request::getInstance()->getModule(), 'sController' => \MVC\Request::getInstance()->getController(), 'sMethod' => \MVC\Request::getInstance()->getMethod(), 'sArg' => isset($aToolbar['oMvcRequestGetQueryArray']['GET']['a']) ? $aToolbar['oMvcRequestGetQueryArray']['GET']['a'] : '', 'aRoute' => \MVC\Registry::get('MVC_ROUTING_CURRENT'), 'sRoutingJsonBuilder' => \MVC\Registry::get('MVC_ROUTING_JSON_BUILDER'), 'sRoutingHandling' => \MVC\Registry::get('MVC_ROUTING_HANDLING'));
     $aPolicy = \MVC\Registry::get('MVC_POLICY');
     $sController = '\\' . \MVC\Request::getInstance()->getModule() . '\\Controller\\' . \MVC\Request::getInstance()->getController();
     $sMethod = \MVC\Request::getInstance()->getMethod();
     $aToolbar['aPolicy']['aRule'] = \MVC\Registry::isRegistered('MVC_POLICY') ? \MVC\Registry::get('MVC_POLICY') : array();
     $aToolbar['aPolicy']['aApplied'] = isset($aPolicy[$sController][$sMethod]) ? $aPolicy[$sController][$sMethod] : false;
     $aToolbar['aPolicy']['sAppliedAt'] = isset($aPolicy[$sController][$sMethod]) ? $sController . '::' . $sMethod : false;
     $sTemplate = file_exists($oView->sTemplate) ? $oView->sTemplate : (file_exists($oView->_joined_template_dir . '/' . $oView->sTemplate) ? $oView->_joined_template_dir . '/' . $oView->sTemplate : false);
     $aToolbar['sTemplate'] = $sTemplate;
     $aToolbar['sTemplateContent'] = file_get_contents($aToolbar['sTemplate']);
     ob_start();
     $sTemplate = file_get_contents($oView->sTemplate, true);
     $oView->renderString($sTemplate);
     $sRendered = ob_get_contents();
     ob_end_clean();
     $aToolbar['sRendered'] = $sRendered;
     $aToolbar['aFilesIncluded'] = get_required_files();
     $aToolbar['aMemory'] = array('iRealMemoryUsage' => memory_get_usage(true) / 1024, 'dMemoryUsage' => memory_get_usage() / 1024, 'dMemoryPeakUsage' => memory_get_peak_usage() / 1024);
     $aToolbar['aRegistry'] = \MVC\Registry::getStorageArray();
     $aToolbar['aCache'] = $this->getCaches();
     $aToolbar['aError'] = \MVC\Error::getERROR();
     $aToolbar['oIds'] = \MVC\Registry::isRegistered('MVC_IDS_IMPACT') ? \MVC\Registry::get('MVC_IDS_IMPACT') : '';
     $aToolbar['aIdsConfig'] = \MVC\Registry::isRegistered('MVC_IDS_INIT') ? \MVC\Registry::get('MVC_IDS_INIT') : '';
     $aToolbar['aIdsDisposed'] = \MVC\Registry::isRegistered('MVC_IDS_DISPOSED') ? \MVC\Registry::get('MVC_IDS_DISPOSED') : '';
     $iMicrotime = microtime(true);
     $sMicrotime = sprintf("%06d", ($iMicrotime - floor($iMicrotime)) * 1000000);
     $oDateTime = new \DateTime(date('Y-m-d H:i:s.' . $sMicrotime, $iMicrotime));
     $oStart = \MVC\Session::getInstance()->get('startDateTime');
     $dDiff = date_format($oDateTime, "s.u") - date_format($oStart, "s.u");
     $aToolbar['sConstructionTime'] = round($dDiff, 3);
     return $aToolbar;
 }