コード例 #1
0
ファイル: Session.php プロジェクト: papac/framework
 /**
  * Session starteur.
  */
 private static function start()
 {
     if (PHP_SESSION_ACTIVE != session_status()) {
         session_name("SESSID");
         if (!isset($_COOKIE["SESSID"])) {
             session_id(hash("sha256", Security::encrypt(Str::repeat(Security::generateCsrfToken(), 2))));
         }
         session_start();
     }
 }
コード例 #2
0
ファイル: DatabaseTools.php プロジェクト: papac/framework
 /**
  * Éxécute PDOStatement::bindValue sur une instance de PDOStatement passé en paramètre
  *
  * @param PDOStatement $pdoStatement
  * @param $data
  *
  * @return PDOStatement
  */
 protected static function bind(PDOStatement $pdoStatement, array $data = [])
 {
     // On sécurise les informations avants l'insertion.
     $data = Security::sanitaze($data, true);
     foreach ($data as $key => $value) {
         if (is_null($value) || strtolower($value) === 'null') {
             $pdoStatement->bindValue(':' . $key, $value, PDO::PARAM_NULL);
             continue;
         }
         $param = PDO::PARAM_INT;
         if (preg_match('/[a-zA-Z_-]+/', $value)) {
             /**
              * SÉCURIATION DES DONNÉS
              * - Injection SQL
              * - XSS
              */
             $param = PDO::PARAM_STR;
         } else {
             /**
              * On force la valeur en entier ou en réél.
              */
             if (is_int($value)) {
                 $value = (int) $value;
             } else {
                 if (is_float($value)) {
                     $value = (double) $value;
                 } else {
                     $value = (double) $value;
                 }
             }
         }
         /**
          * Exécution de bindValue
          */
         if (is_string($key)) {
             $pdoStatement->bindValue(':' . $key, $value, $param);
         } else {
             $pdoStatement->bindValue($key, $value, $param);
         }
     }
 }
コード例 #3
0
ファイル: helper.php プロジェクト: papac/framework
 /**
  * permet de decrypter des données crypté par la function crypt
  *
  * @param string $data
  * @return string
  */
 function decrypt($data)
 {
     return Security::decrypt($data);
 }
コード例 #4
0
ファイル: Cookie.php プロジェクト: papac/framework
 /**
  * remove, supprime une entrée dans la table
  *
  * @param string $key
  *
  * @return self
  */
 public static function remove($key)
 {
     $old = null;
     if (static::has($key)) {
         if (!static::$isDecrypt[$key]) {
             $old = Security::decrypt($_COOKIE[$key]);
             unset(static::$isDecrypt[$key]);
         }
         static::add($key, null, -1000);
         unset($_COOKIE[$key]);
     }
     return $old;
 }
コード例 #5
0
ファイル: Response.php プロジェクト: papac/framework
 /**
  * templateLoader, charge le moteur template à utiliser.
  *
  * @throws ErrorException
  * @return \Twig_Environment|\Mustache_Engine|\Jade\Jade
  */
 private function templateLoader()
 {
     if ($this->config->getTemplateEngine() !== null) {
         if (!in_array($this->config->getTemplateEngine(), ['twig', 'mustache', 'jade'], true)) {
             throw new ErrorException('Le moteur de template n\'est pas implementé.', E_USER_ERROR);
         }
     } else {
         throw new ResponseException('Le moteur de template non défini.', E_USER_ERROR);
     }
     $tpl = null;
     if ($this->config->getTemplateEngine() == 'twig') {
         $loader = new \Twig_Loader_Filesystem($this->config->getViewpath());
         $tpl = new \Twig_Environment($loader, ['cache' => $this->config->getCachepath(), 'auto_reload' => $this->config->getCacheAutoReload(), 'debug' => $this->config->getLoggerMode() == 'develepment' ? true : false]);
         /**
          * - Ajout de variable globale
          * dans le cadre de l'utilisation de Twig
          */
         $tpl->addGlobal('public', $this->config->getPublicPath());
         $tpl->addGlobal('root', $this->config->getApproot());
         /**
          * - Ajout de fonction global
          *  dans le cadre de l'utilisation de Twig
          */
         $tpl->addFunction(new \Twig_SimpleFunction('secure', function ($data) {
             return Security::sanitaze($data, true);
         }));
         $tpl->addFunction(new \Twig_SimpleFunction('sanitaze', function ($data) {
             return Security::sanitaze($data);
         }));
         $tpl->addFunction(new \Twig_SimpleFunction('csrf_field', function () {
             return Security::getCsrfToken()->field;
         }));
         $tpl->addFunction(new \Twig_SimpleFunction('csrf_token', function () {
             return Security::getCsrfToken()->token;
         }));
         $tpl->addFunction(new \Twig_SimpleFunction('slugify', [Str::class, 'slugify']));
         return $tpl;
     }
     if ($this->config->getTemplateEngine() == 'mustache') {
         return new \Mustache_Engine(['cache' => $this->config->getCachepath(), 'loader' => new \Mustache_Loader_FilesystemLoader($this->config->getViewpath()), 'helpers' => ['secure' => function ($data) {
             return Security::sanitaze($data, true);
         }, 'sanitaze' => function ($data) {
             return Security::sanitaze($data);
         }, 'slugify' => function ($data) {
             return Str::slugify($data);
         }, 'csrf_token' => function () {
             return Security::getCsrfToken()->token;
         }, 'csrf_field' => function () {
             return Security::getCsrfToken()->field;
         }, 'public', $this->config->getPublicPath(), 'root', $this->config->getApproot()]]);
     }
     return new Jade(['cache' => $this->config->getCachepath(), 'prettyprint' => true, 'extension' => $this->config->getTemplateExtension()]);
 }
コード例 #6
0
ファイル: Table.php プロジェクト: papac/framework
 /**
  * Action update
  *
  * @param array $data  Les données à mettre à jour
  * @param callable $cb La fonction de rappel. Dans ou elle est définie
  *                     elle récupère en paramètre une instance de DatabaseErrorHanlder
  *                     et les données récupérés par la réquête.
  *
  * @return int
  */
 public function update(array $data = [], callable $cb = null)
 {
     $sql = 'update `' . $this->tableName . '` set ';
     $sql .= parent::rangeField(parent::add2points(array_keys($data)));
     if (!is_null($this->where)) {
         $sql .= ' where ' . $this->where;
         $this->where = null;
         $data = array_merge($data, $this->whereDataBind);
         $this->whereDataBind = [];
     }
     $stmt = $this->connection->prepare($sql);
     $data = Security::sanitaze($data, true);
     static::bind($stmt, $data);
     // execution de la requête
     $stmt->execute();
     // récupération de la dernière erreur.
     self::$errorInfo = $stmt->errorInfo();
     $r = $stmt->rowCount();
     if (is_callable($cb)) {
         return call_user_func_array($cb, [$this->getResponseOfQuery($r), $r]);
     }
     return (int) $r;
 }
コード例 #7
0
ファイル: Database.php プロジェクト: papac/framework
 /**
  * Insertion des données dans la DB avec la method query
  * ====================== USAGE ========================
  *	$options = [
  *		"query" => [
  *			"table" => "nomdelatable",
  *			"type" => INSERT|SELECT|DELETE|UPDATE,
  *			"data" => [ les informations a mettre ici dépendent de la requête que l'utilisateur veux faire. ]
  *		],
  *		"data" => [ "les données a insérer." ]
  *	];
  *
  * @param array $options
  * @param bool|false $return
  * @param bool|false $lastInsertId
  *
  * @throws \ErrorException
  *
  * @return array|static|\StdClass
  */
 public static function query(array $options, $return = false, $lastInsertId = false)
 {
     static::verifyConnection();
     $sqlStatement = static::makeQuery($options["query"]);
     $pdoStatement = static::$db->prepare($sqlStatement);
     static::bind($pdoStatement, isset($options["data"]) ? $options["data"] : []);
     $pdoStatement->execute();
     static::$errorInfo = $pdoStatement->errorInfo();
     $data = $pdoStatement->fetchAll();
     if ($return == true) {
         if ($lastInsertId == false) {
             $data = empty($data) ? null : Security::sanitaze($data);
         } else {
             $data = static::$db->lastInsertId();
         }
     }
     return $data;
 }