示例#1
0
 /**
  * Method that sets the cookie headers
  * @param $cookies
  */
 public static function setCookieHeaders($cookies)
 {
     if (!empty($cookies) && is_array($cookies)) {
         foreach ($cookies as $cookie) {
             setcookie($cookie["name"], $cookie["value"], array_key_exists('expire', $cookie) ? $cookie["expire"] : NULL, array_key_exists('path', $cookie) ? $cookie["path"] : "/", array_key_exists('domain', $cookie) ? $cookie["domain"] : Request::getInstance()->getRootUrl(FALSE), array_key_exists('secure', $cookie) ? $cookie["secure"] : FALSE, array_key_exists('http', $cookie) ? $cookie["http"] : FALSE);
         }
     }
 }
示例#2
0
 /**
  * Función que copia los recursos de las carpetas Public al DocumentRoot
  * @param $string
  * @param null $name
  * @param bool|TRUE $return
  *
  * @return string
  */
 public static function asset($string, $name = null, $return = true)
 {
     $file_path = "";
     if (!file_exists($file_path)) {
         $file_path = BASE_DIR . $string;
     }
     $filename_path = AssetsParser::findDomainPath($string, $file_path);
     $file_path = self::processAsset($string, $name, $return, $filename_path);
     $return_path = empty($name) ? Request::getInstance()->getRootUrl() . '/' . $file_path : $name;
     return $return ? $return_path : '';
 }
示例#3
0
文件: PSFSTest.php 项目: c15k0/psfs
 /**
  * Basic test for Request functionality
  */
 public function testRequest()
 {
     $request = Request::getInstance();
     // Is Request instance?
     $this->assertTrue($request instanceof Request);
     // Check headers, uploads and cookies checkers
     $this->assertTrue(is_bool($request->hasHeader("session")));
     $this->assertTrue(is_bool($request->hasUpload()));
     $this->assertTrue(is_bool($request->hasCookies()));
     $this->assertTrue(is_bool($request->isAjax()));
     // Checks if timestamp was generated
     $this->assertNotNull($request->getTs());
 }
示例#4
0
文件: AuthApi.php 项目: c15k0/psfs
 /**
  * Check service authentication
  * @return bool
  */
 private function checkAuth()
 {
     $namespace = explode('\\', $this->getModelTableMap());
     $module = strtolower($namespace[0]);
     $secret = Config::getInstance()->get($module . '.api.secret');
     if (NULL === $secret) {
         $secret = Config::getInstance()->get("api.secret");
     }
     if (NULL === $secret) {
         $auth = TRUE;
     } else {
         $token = Request::getInstance()->getHeader('X-API-SEC-TOKEN');
         if (array_key_exists('API_TOKEN', $this->query)) {
             $token = $this->query['API_TOKEN'];
         }
         $auth = Security::checkToken($token ?: '', $secret, $module);
     }
     return $auth || $this->isAdmin();
 }
示例#5
0
 /**
  * Check CROS requests
  */
 public static function checkCORS()
 {
     Logger::log('Checking CORS');
     $corsEnabled = Config::getInstance()->get('cors.enabled');
     $request = Request::getInstance();
     if (NULL !== $corsEnabled) {
         if ($corsEnabled === '*' || preg_match($corsEnabled, $request->getServer('HTTP_REFERER'))) {
             if (!headers_sent()) {
                 // TODO include this headers in Template class output method
                 header("Access-Control-Allow-Credentials: true");
                 header("Access-Control-Allow-Origin: *");
                 header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
                 header("Access-Control-Allow-Headers: Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Allow-Origin, Origin, X-Requested-With, Content-Type, Accept, Authorization, X-API-SEC-TOKEN, X-API-USER-TOKEN");
             }
             if (Request::getInstance()->getMethod() == 'OPTIONS') {
                 Logger::log('Returning OPTIONS header confirmation for CORS pre flight requests');
                 header("HTTP/1.1 200 OK");
                 exit;
             }
         }
     }
 }
示例#6
0
文件: Form.php 项目: c15k0/psfs
 /**
  * Método que extrae los datos del formulario
  * @return Form
  */
 public function hydrate()
 {
     $data = Request::getInstance()->getData() ?: [];
     //Hidratamos los campos con lo que venga del formulario
     $form_name = $this->getName();
     if (array_key_exists($form_name, $data)) {
         foreach ($this->fields as $key => &$field) {
             list($data, $field) = $this->hydrateField($data, $form_name, $key, $field);
         }
         //Limpiamos los datos
         unset($data[$form_name]);
     }
     //Cargamos los campos extras
     $this->extra = $data;
     return $this;
 }
示例#7
0
文件: Router.php 项目: c15k0/psfs
 /**
  * Método que devuelve una ruta del framework
  *
  * @param string $slug
  * @param boolean $absolute
  * @param array $params
  *
  * @return string|null
  * @throws RouterException
  */
 public function getRoute($slug = '', $absolute = FALSE, $params = [])
 {
     if (strlen($slug) === 0) {
         return $absolute ? Request::getInstance()->getRootUrl() . '/' : '/';
     }
     if (NULL === $slug || !array_key_exists($slug, $this->slugs)) {
         throw new RouterException(_("No existe la ruta especificada"));
     }
     $url = $absolute ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug];
     if (!empty($params)) {
         foreach ($params as $key => $value) {
             $url = str_replace("{" . $key . "}", $value, $url);
         }
     } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) {
         $url = $absolute ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
     }
     return preg_replace('/(GET|POST|PUT|DELETE|ALL)\\#\\|\\#/', '', $url);
 }
示例#8
0
文件: Config.php 项目: psfs/Core
 /**
  * Method that check if the user is trying to save the config
  * @return bool
  */
 public function checkTryToSaveConfig()
 {
     $uri = Request::getInstance()->getRequestUri();
     $method = Request::getInstance()->getMethod();
     return preg_match('/^\\/admin\\/(config|setup)$/', $uri) !== false && strtoupper($method) === 'POST';
 }
示例#9
0
文件: Dispatcher.php 项目: psfs/Core
 private function redirectToHome()
 {
     Request::getInstance()->redirect($this->router->getRoute($this->config->get('home_action')));
 }
示例#10
0
文件: Api.php 项目: c15k0/psfs
 /**
  * Hydrate data from request
  */
 private function hydrateRequestData()
 {
     $request = Request::getInstance();
     $this->query = array_merge($this->query, $request->getQueryParams());
     $this->data = array_merge($this->data, $request->getData());
 }
示例#11
0
文件: Controller.php 项目: c15k0/psfs
 /**
  * Método que devuelve el objeto de petición
  * @return \PSFS\base\Request
  */
 protected function getRequest()
 {
     return Request::getInstance();
 }
示例#12
0
文件: Security.php 项目: c15k0/psfs
 /**
  * Método que obtiene el usuario y contraseña de la cookie de sesión de administración
  * @return array
  */
 protected function getAdminFromCookie()
 {
     $auth_cookie = Request::getInstance()->getCookie($this->getHash());
     $user = $pass = array();
     if (!empty($auth_cookie)) {
         list($user, $pass) = explode(':', base64_decode($auth_cookie));
     }
     return array($user, $pass);
 }
示例#13
0
文件: Template.php 项目: psfs/Core
 /**
  * Método que cierra y limpia los buffers de salida
  */
 public function closeRender()
 {
     Logger::log('Close template render');
     Security::getInstance()->setSessionKey("lastRequest", array("url" => Request::getInstance()->getRootUrl() . Request::requestUri(), "ts" => microtime(true)));
     Security::getInstance()->updateSession();
     Logger::log('End request: ' . Request::requestUri(), LOG_INFO);
     exit;
 }