Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alishahidi committed Jul 4, 2022
1 parent 47a2b9f commit 1a57ad4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
9 changes: 6 additions & 3 deletions system/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace System\Config;

use Symfony\Component\Finder\Finder;

class Config
{
Expand All @@ -18,9 +19,11 @@ private function initialConfigArray()
{
$dirSep = DIRECTORY_SEPARATOR;
$configPath = dirname(dirname(__DIR__)) . "{$dirSep}config{$dirSep}";
foreach (glob($configPath . "*.php") as $fileName) {
$config = require $fileName;
$key = str_replace([$configPath, ".php"], "", $fileName);
$finder = new Finder();
$finder->files()->in($configPath);
foreach ($finder as $file) {
$config = require $file->getRealPath();
$key = str_replace([$configPath, ".php"], "", $file->getRealPath());
$this->config_nested_array[$key] = $config;
}
$this->initialDefaultValues();
Expand Down
60 changes: 30 additions & 30 deletions system/Request/Traits/HasFileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,44 @@

trait HasFileManager
{
public function createDir($path)
{
$basePath = Config::get("app.BASE_DIR") . DIRECTORY_SEPARATOR;
$path = trim(str_replace("/", DIRECTORY_SEPARATOR, $path), "/");
$fullPath = $basePath . $path;
$filesystem = new Filesystem();
try {
$filesystem->mkdir($fullPath);
return true;
} catch (IOExceptionInterface $exception) {
return false;
}
}
// public function createDir($path)
// {
// $basePath = Config::get("app.BASE_DIR") . DIRECTORY_SEPARATOR;
// $path = trim(str_replace("/", DIRECTORY_SEPARATOR, $path), "/");
// $fullPath = $basePath . $path;
// $filesystem = new Filesystem();
// try {
// $filesystem->mkdir($fullPath);
// return true;
// } catch (IOExceptionInterface $exception) {
// return false;
// }
// }

public function removeFile($path)
{
$basePath = Config::get("app.BASE_DIR") . DIRECTORY_SEPARATOR;
$path = trim(str_replace("/", DIRECTORY_SEPARATOR, $path), "/");
$fullPath = $basePath . $path;
$filesystem = new Filesystem();
try {
$filesystem->remove($fullPath);
return true;
} catch (IOExceptionInterface $exception) {
return false;
}
}
// public function removeFile($path)
// {
// $basePath = Config::get("app.BASE_DIR") . DIRECTORY_SEPARATOR;
// $path = trim(str_replace("/", DIRECTORY_SEPARATOR, $path), "/");
// $fullPath = $basePath . $path;
// $filesystem = new Filesystem();
// try {
// $filesystem->remove($fullPath);
// return true;
// } catch (IOExceptionInterface $exception) {
// return false;
// }
// }

public function uploadImage($fileName, $path, $name, $widthHeight = [], $watermark = null)
{
$file = $this->file($fileName);
if (!$file["tmp_name"])
return false;

$path = trim($path, "\/") . DIRECTORY_SEPARATOR;
$name = trim($name, "\/") . "." . pathinfo($file["name"], PATHINFO_EXTENSION);
$dirAccess = $this->createDir("public/" . $path);
if (!$dirAccess)
dd("Faild to create directory.");
if (!is_dir($path))
if (!mkdir($path, recursive: true))
dd("Faild to create directory.");
if (!is_writable($path))
dd("Directory not writable");
Image::configure(["driver" => "gd"]);
Expand Down
2 changes: 1 addition & 1 deletion system/Request/Traits/HasValidationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function minNumber($name, $count)

protected function required($name)
{
if ((!isset($this->request[$name]) || $this->request[$name] == "") && $this->checkFirstError($name))
if ((!isset($this->request[$name]) || trim($this->request[$name], " ") == "") && $this->checkFirstError($name))
$this->setError($name, "$name is required", "required");
}

Expand Down

0 comments on commit 1a57ad4

Please sign in to comment.