Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Path to BasePath #393

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions includes/Http/Controllers/Api/Setup/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Install\SetupManager;
use App\Support\Database;
use App\Support\FileSystemContract;
use App\Support\Path;
use App\Support\BasePath;
use App\System\Application;
use Exception;
use PDOException;
Expand All @@ -25,7 +25,7 @@ public function post(
RequirementStore $requirementStore,
EnvCreator $envCreator,
SetupManager $setupManager,
Path $path,
BasePath $path,
FileSystemContract $fileSystem,
Application $app
) {
Expand Down
6 changes: 3 additions & 3 deletions includes/Http/Controllers/View/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use App\Install\ShopState;
use App\Install\UpdateInfo;
use App\Support\FileSystemContract;
use App\Support\Path;
use App\Support\BasePath;
use App\Theme\Template;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -26,7 +26,7 @@ public function get(
UpdateInfo $updateInfo,
RequirementStore $requirementStore,
FileSystemContract $fileSystem,
Path $path
BasePath $path
) {
if ($oldShop->hasConfigFile()) {
return new HtmlResponse($this->template->render("setup/missing_env"));
Expand All @@ -45,7 +45,7 @@ public function get(

private function install(
RequirementStore $requirementStore,
Path $path,
BasePath $path,
FileSystemContract $fileSystem
) {
$modules = $requirementStore->getModules();
Expand Down
6 changes: 3 additions & 3 deletions includes/Http/Validation/Rules/LanguageRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
use App\Exceptions\ValidationException;
use App\Http\Validation\BaseRule;
use App\Support\FileSystemContract;
use App\Support\Path;
use App\Support\BasePath;

class LanguageRule extends BaseRule
{
private FileSystemContract $fileSystem;
private Path $path;
private BasePath $path;

public function __construct()
{
parent::__construct();
$this->fileSystem = app()->make(FileSystemContract::class);
$this->path = app()->make(Path::class);
$this->path = app()->make(BasePath::class);
}

public function validate($attribute, $value, array $data): void
Expand Down
6 changes: 3 additions & 3 deletions includes/Install/EnvCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
namespace App\Install;

use App\Support\FileSystemContract;
use App\Support\Path;
use App\Support\BasePath;

class EnvCreator
{
private Path $path;
private BasePath $path;
private FileSystemContract $fileSystem;

public function __construct(Path $path, FileSystemContract $fileSystem)
public function __construct(BasePath $path, FileSystemContract $fileSystem)
{
$this->path = $path;
$this->fileSystem = $fileSystem;
Expand Down
6 changes: 3 additions & 3 deletions includes/Install/MigrationFiles.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
namespace App\Install;

use App\Support\Path;
use App\Support\BasePath;
use DirectoryIterator;

class MigrationFiles
{
private Path $path;
private BasePath $path;

public function __construct(Path $path)
public function __construct(BasePath $path)
{
$this->path = $path;
}
Expand Down
6 changes: 3 additions & 3 deletions includes/Install/OldShop.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
namespace App\Install;

use App\Support\FileSystemContract;
use App\Support\Path;
use App\Support\BasePath;

class OldShop
{
private Path $path;
private BasePath $path;
private FileSystemContract $fileSystem;

public function __construct(Path $path, FileSystemContract $fileSystem)
public function __construct(BasePath $path, FileSystemContract $fileSystem)
{
$this->path = $path;
$this->fileSystem = $fileSystem;
Expand Down
6 changes: 3 additions & 3 deletions includes/Install/RequirementStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

use App\Support\FileSystemContract;
use App\Support\Meta;
use App\Support\Path;
use App\Support\BasePath;

class RequirementStore
{
private Path $path;
private BasePath $path;
private FileSystemContract $fileSystem;
private Meta $meta;

public function __construct(Path $path, Meta $meta, FileSystemContract $fileSystem)
public function __construct(BasePath $path, Meta $meta, FileSystemContract $fileSystem)
{
$this->path = $path;
$this->fileSystem = $fileSystem;
Expand Down
6 changes: 3 additions & 3 deletions includes/Install/SetupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
namespace App\Install;

use App\Support\FileSystemContract;
use App\Support\Path;
use App\Support\BasePath;

class SetupManager
{
private Path $path;
private BasePath $path;
private FileSystemContract $fileSystem;

public function __construct(Path $path, FileSystemContract $fileSystem)
public function __construct(BasePath $path, FileSystemContract $fileSystem)
{
$this->path = $path;
$this->fileSystem = $fileSystem;
Expand Down
6 changes: 3 additions & 3 deletions includes/Install/UpdateInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
namespace App\Install;

use App\Support\FileSystemContract;
use App\Support\Path;
use App\Support\BasePath;
use App\Theme\Template;

class UpdateInfo
{
private Path $path;
private BasePath $path;
private Template $template;
private FileSystemContract $fileSystem;

public function __construct(Path $path, Template $template, FileSystemContract $fileSystem)
public function __construct(BasePath $path, Template $template, FileSystemContract $fileSystem)
{
$this->path = $path;
$this->template = $template;
Expand Down
6 changes: 3 additions & 3 deletions includes/Loggers/FileLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
namespace App\Loggers;

use App\Support\FileSystemContract;
use App\Support\Path;
use App\Support\BasePath;
use App\System\Settings;
use Psr\Log\LoggerInterface;

class FileLogger implements LoggerInterface
{
private Settings $settings;
private FileSystemContract $fileSystem;
private Path $path;
private BasePath $path;

public function __construct(Settings $settings, FileSystemContract $fileSystem, Path $path)
public function __construct(Settings $settings, FileSystemContract $fileSystem, BasePath $path)
{
$this->settings = $settings;
$this->fileSystem = $fileSystem;
Expand Down
6 changes: 3 additions & 3 deletions includes/Payment/General/PurchaseDataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

use App\Models\Purchase;
use App\Support\FileSystemContract;
use App\Support\Path;
use App\Support\BasePath;

class PurchaseDataService
{
private PurchaseSerializer $purchaseSerializer;
private Path $path;
private BasePath $path;
private FileSystemContract $fileSystem;

public function __construct(
PurchaseSerializer $purchaseSerializer,
Path $path,
BasePath $path,
FileSystemContract $fileSystem
) {
$this->purchaseSerializer = $purchaseSerializer;
Expand Down
6 changes: 3 additions & 3 deletions includes/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use App\Support\FileSystemContract;
use App\Support\Mailer;
use App\Support\Meta;
use App\Support\Path;
use App\Support\BasePath;
use App\Theme\ContentEvaluator;
use App\Theme\EditableTemplateRepository;
use App\Theme\Template;
Expand Down Expand Up @@ -91,8 +91,8 @@ private function registerDatabase(Application $app)
private function registerCache(Application $app)
{
$app->bind(FileCache::class, function (Application $app) {
/** @var Path $path */
$path = $app->make(Path::class);
/** @var BasePath $path */
$path = $app->make(BasePath::class);
return new FileCache($app->make(FileSystemContract::class), $path->to("data/cache"));
});
$app->bind(CacheInterface::class, FileCache::class);
Expand Down
25 changes: 25 additions & 0 deletions includes/Support/BasePath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace App\Support;

class BasePath
{
private string $basePath;

public function __construct($basePath)
{
$this->basePath = $basePath;
}

public static function temporary(): BasePath
{
return new BasePath(sys_get_temp_dir());
}

public function to(string $subpath): string
{
if (!strlen($subpath)) {
return $this->basePath;
}
return $this->basePath . DIRECTORY_SEPARATOR . ltrim($subpath, "/");
}
}
16 changes: 4 additions & 12 deletions includes/Support/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use ErrorException;
use Exception;
use function filesize;
use function is_file;

class FileSystem implements FileSystemContract
{
Expand Down Expand Up @@ -39,7 +41,7 @@ public function put($path, $contents, $lock = false)

public function get($path, $lock = false)
{
if ($this->isFile($path)) {
if (is_file($path)) {
return $lock ? $this->sharedGet($path) : file_get_contents($path);
}
throw new Exception("File does not exist at path {$path}");
Expand All @@ -53,7 +55,7 @@ public function sharedGet($path)
try {
if (flock($handle, LOCK_SH)) {
clearstatcache(true, $path);
$contents = fread($handle, $this->size($path) ?: 1);
$contents = fread($handle, filesize($path) ?: 1);
flock($handle, LOCK_UN);
}
} finally {
Expand All @@ -63,21 +65,11 @@ public function sharedGet($path)
return $contents;
}

public function isFile($path)
{
return is_file($path);
}

public function isDirectory($path)
{
return is_dir($path);
}

public function size($path)
{
return filesize($path);
}

public function append($file, $text)
{
if ($this->exists($file) && strlen($this->get($file))) {
Expand Down
16 changes: 0 additions & 16 deletions includes/Support/FileSystemContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ public function get($path, $lock = false);
*/
public function sharedGet($path);

/**
* Determine if the given path is a file.
*
* @param string $path
* @return bool
*/
public function isFile($path);

/**
* Determine if the given path is a directory.
*
Expand All @@ -73,14 +65,6 @@ public function isFile($path);
*/
public function isDirectory($path);

/**
* Get the file size of a given file.
*
* @param string $path
* @return int
*/
public function size($path);

/**
* Add text to the end of the file
*
Expand Down
4 changes: 2 additions & 2 deletions includes/Support/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
class Meta
{
private MetaParser $metaParser;
private Path $path;
private BasePath $path;
private array $meta;

public function __construct(MetaParser $metaParser, Path $path)
public function __construct(MetaParser $metaParser, BasePath $path)
{
$this->metaParser = $metaParser;
$this->path = $path;
Expand Down
Loading