Browse Source

2018-04-01

Visman 7 years ago
parent
commit
6c44946e39

+ 2 - 2
app/Core/Cache/FileCache.php

@@ -44,7 +44,7 @@ class FileCache implements ProviderCacheInterface
     public function get($key, $default = null)
     {
         $file = $this->file($key);
-        if (\file_exists($file)) {
+        if (\is_file($file)) {
             require $file;
 
             if (isset($expire) && isset($data)
@@ -92,7 +92,7 @@ class FileCache implements ProviderCacheInterface
     public function delete($key)
     {
         $file = $this->file($key);
-        if (\file_exists($file)) {
+        if (\is_file($file)) {
             if (\unlink($file)) {
                 $this->invalidate($file);
                 return true;

+ 1 - 1
app/Core/DB.php

@@ -59,7 +59,7 @@ class DB extends PDO
     public function __construct($dsn, $username = null, $password = null, array $options = [], $prefix = '')
     {
         $type = \strstr($dsn, ':', true);
-        if (! $type || ! \file_exists(__DIR__ . '/DB/' . \ucfirst($type) . '.php')) {
+        if (! $type || ! \is_file(__DIR__ . '/DB/' . \ucfirst($type) . '.php')) {
             throw new PDOException("Driver isn't found for '$type'");
         }
         $this->dbType = $type;

+ 1 - 1
app/Core/Lang.php

@@ -79,7 +79,7 @@ class Lang
         do {
             $flag = true;
             $fullPath = $path . '/'. $lang . '/' . $name . '.po';
-            if (\file_exists($fullPath)) {
+            if (\is_file($fullPath)) {
                 $file = \file_get_contents($fullPath);
                 if (isset($this->tr[$lang])) {
                     $this->tr[$lang] += $this->arrayFromStr($file);

+ 2 - 2
app/Core/Mail.php

@@ -120,7 +120,7 @@ class Mail
             $ip          = null;
             $domainASCII = $domain = \mb_strtolower($domain, 'UTF-8');
 
-            if (\preg_match('%[\x80-\xFF]%', $domain) && \function_exists('idn_to_ascii')) {
+            if (\preg_match('%[\x80-\xFF]%', $domain) && \function_exists('\idn_to_ascii')) {
                 $domainASCII = \idn_to_ascii($domain, 0, \INTL_IDNA_VARIANT_UTS46);
             }
 
@@ -325,7 +325,7 @@ class Mail
     public function setTpl($tpl, array $data)
     {
         $file = \rtrim($this->folder, '\\/') . '/' . $this->language . '/mail/' . $tpl;
-        if (! \file_exists($file)) {
+        if (! \is_file($file)) {
             throw new MailException('The template isn\'t found (' . $file . ').');
         }
         $tpl = \trim(\file_get_contents($file));

+ 4 - 2
app/Core/Secury.php

@@ -127,14 +127,16 @@ class Secury
     /**
      * Replacing invalid UTF-8 characters and remove control characters
      *
-     * @param string|array $data
+     * @param mixed $data
      *
-     * @return string|array
+     * @return mixed
      */
     public function replInvalidChars($data)
     {
         if (\is_array($data)) {
             return \array_map([$this, 'replInvalidChars'], $data);
+        } elseif (\is_int($data)) {
+            return (int) $data;
         }
         // Replacing invalid UTF-8 characters
         // slow, small memory

+ 6 - 4
app/Core/Validator.php

@@ -581,8 +581,9 @@ class Validator
     protected function vMin($v, $value, $attr)
     {
         if (\is_string($value)) {
-            if ((\strpos($attr, 'bytes') && \strlen($value) < (int) $attr)
-                || \mb_strlen($value, 'UTF-8') < $attr
+            $isBytes = \strpos($attr, 'bytes');
+            if (($isBytes && \strlen($value) < (int) $attr)
+                || (! $isBytes && \mb_strlen($value, 'UTF-8') < $attr)
             ) {
                 $this->addError('The :alias minimum is :attr characters');
             }
@@ -604,8 +605,9 @@ class Validator
     protected function vMax($v, $value, $attr)
     {
         if (\is_string($value)) {
-            if ((\strpos($attr, 'bytes') && \strlen($value) > (int) $attr)
-                || \mb_strlen($value, 'UTF-8') > $attr
+            $isBytes = \strpos($attr, 'bytes');
+            if (($isBytes && \strlen($value) > (int) $attr)
+                || (! $isBytes && \mb_strlen($value, 'UTF-8') > $attr)
             ) {
                 $this->addError('The :alias maximum is :attr characters');
             }

+ 1 - 1
app/Models/Pages/Install.php

@@ -35,7 +35,7 @@ class Install extends Page
         $dbTypes = [];
         $pdoDrivers = PDO::getAvailableDrivers();
         foreach ($pdoDrivers as $type) {
-            if (\file_exists($this->c->DIR_APP . '/Core/DB/' . \ucfirst($type) . '.php')) {
+            if (\is_file($this->c->DIR_APP . '/Core/DB/' . \ucfirst($type) . '.php')) {
                 switch ($type) {
                     case 'mysql':
                         $dbTypes['mysql_innodb'] = 'MySQL InnoDB (PDO)';

+ 1 - 1
app/Models/User/Model.php

@@ -162,7 +162,7 @@ class Model extends DataModel
         foreach ($filetypes as $type) {
             $path = $this->c->DIR_PUBLIC . "{$this->c->config->o_avatars_dir}/{$this->id}.{$type}";
 
-            if (\file_exists($path) && \getimagesize($path)) {
+            if (\is_file($path) && \getimagesize($path)) {
                 return $this->c->PUBLIC_URL . "{$this->c->config->o_avatars_dir}/{$this->id}.{$type}";
             }
         }

+ 2 - 2
app/bootstrap.php

@@ -21,9 +21,9 @@ use RuntimeException;
 
 require __DIR__ . '/../vendor/autoload.php';
 
-if (\file_exists(__DIR__ . '/config/main.php')) {
+if (\is_file(__DIR__ . '/config/main.php')) {
     $c = new Container(include __DIR__ . '/config/main.php');
-} elseif (\file_exists(__DIR__ . '/config/install.php')) {
+} elseif (\is_file(__DIR__ . '/config/install.php')) {
     $c = new Container(include __DIR__ . '/config/install.php');
 } else {
     throw new RuntimeException('Application is not configured');