diff --git a/function.php b/function.php index e2250731..cebfdeff 100644 --- a/function.php +++ b/function.php @@ -43,11 +43,11 @@ if (!function_exists('storage')) { function storage($fileName = '', $path = '') { $basePath = Snowflake::getStoragePath(); -// if (empty($path)) { -// return $basePath . '/' . $fileName; -// } else if (empty($fileName)) { -// return initDir($basePath, $path); -// } + if (empty($path)) { + return $basePath . '/' . $fileName; + } else if (empty($fileName)) { + return initDir($basePath, $path); + } return initDir($basePath, $path) . $fileName; } @@ -64,10 +64,10 @@ if (!function_exists('storage')) { foreach ($explode as $value) { $path .= $value . '/'; if (!is_dir($basePath . $path)) { -// mkdir($basePath . $path); + mkdir($basePath . $path); } if (!is_dir($basePath . $path)) { -// throw new Exception('System error, directory ' . $basePath . $path . ' is not writable'); + throw new Exception('System error, directory ' . $basePath . $path . ' is not writable'); } } return realpath($basePath . $path); diff --git a/system/Abstracts/BaseApplication.php b/system/Abstracts/BaseApplication.php index 7e37930f..998ed9d3 100644 --- a/system/Abstracts/BaseApplication.php +++ b/system/Abstracts/BaseApplication.php @@ -20,6 +20,7 @@ use Snowflake\Di\Service; use Snowflake\Error\ErrorHandler; use Snowflake\Error\Logger; use Snowflake\Exception\ComponentException; +use Snowflake\Exception\InitException; use Snowflake\Pool\Connection; use Snowflake\Pool\RedisClient; use Snowflake\Processes; @@ -142,45 +143,17 @@ abstract class BaseApplication extends Service foreach ($config as $key => $value) { Config::set($key, $value); } -// if (isset($config['id'])) { -// $this->id = $config['id']; -// unset($config['id']); -// } -// if (isset($config['storage'])) { -// $this->storage = $config['storage']; -// unset($config['storage']); -// } -// if (!empty($this->runtimePath)) { -// if (!is_dir($this->runtimePath)) { -// mkdir($this->runtimePath, 777); -// } -// -// if (!is_dir($this->runtimePath) || !is_writeable($this->runtimePath)) { -// throw new InitException("Directory {$this->runtimePath} does not have write permission"); -// } -// } -// if (isset($config['aliases'])) { -// $this->classAlias($config); -// } -// -// foreach ($this->moreComponents() as $key => $val) { -// if (isset($config['components'][$key])) { -// $config['components'][$key] = array_merge($val, $config['components'][$key]); -// } else { -// $config['components'][$key] = $val; -// } -// } - } - - /** - * @param array $data - */ - private function classAlias(array &$data) - { - foreach ($data['aliases'] as $key => $val) { - class_alias($val, $key, true); + if ($storage = Config::get('storage', false, 'storage')) { + if (strpos($storage, APP_PATH) === false) { + $storage = realpath(APP_PATH . $storage); + } + if (!is_dir($storage)) { + mkdir($storage, 777); + } + if (!is_dir($storage) || !is_writeable($storage)) { + throw new InitException("Directory {$storage} does not have write permission"); + } } - unset($data['aliases']); } diff --git a/system/Snowflake.php b/system/Snowflake.php index 4c4312da..3083a6e4 100644 --- a/system/Snowflake.php +++ b/system/Snowflake.php @@ -93,7 +93,7 @@ class Snowflake { $path = realpath(static::$service->storage); if (!is_dir($path)) { -// mkdir($path); + mkdir($path); } return $path; } @@ -128,11 +128,11 @@ class Snowflake public static function writeFile($fileName, $content, $is_append = FILE_APPEND) { return false; -// if (self::inCoroutine()) { -// return Coroutine::writeFile($fileName, $content, $is_append); -// } else { -// return file_put_contents($fileName, $content, $is_append); -// } + if (self::inCoroutine()) { + return Coroutine::writeFile($fileName, $content, $is_append); + } else { + return file_put_contents($fileName, $content, $is_append); + } }