Skip to content

Commit

Permalink
Merge pull request #3 from Jeroen-G/php-cache-file
Browse files Browse the repository at this point in the history
PHP cache file instead of JSON
  • Loading branch information
Jeroen-G authored Jan 6, 2022
2 parents b1a891f + e96f97c commit b2acea1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [1.3.0]

## Changed
- Cache is now saves as a PHP file instead of JSON

## [1.2.0]

### Added
Expand Down
3 changes: 1 addition & 2 deletions src/AutowireServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public function register(): void
$this->mergeConfigFrom(__DIR__.'/../config/autowire.php', 'autowire');

try {
$file = File::get(App::bootstrapPath('cache/autowire.json'));
$cache = json_decode($file, true, 512, JSON_THROW_ON_ERROR);
$cache = File::getRequire(App::bootstrapPath('cache/autowire.php'));
$this->loadFromCache($cache);
} catch (FileNotFoundException | JsonException) {
$this->crawlAndLoad();
Expand Down
5 changes: 4 additions & 1 deletion src/Console/AutowireCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public function handle(): int
'configure' => $configureCache,
];

File::put(App::bootstrapPath('cache/autowire.json'), json_encode($cache, JSON_THROW_ON_ERROR));
File::put(
App::bootstrapPath('cache/autowire.php'),
'<?php return '.var_export($cache, true).';'.PHP_EOL
);

$this->info('Autowire cache created!');
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Console/AutowireClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AutowireClearCommand extends Command

public function handle(): int
{
$deleted = File::delete(App::bootstrapPath('cache/autowire.json'));
$deleted = File::delete(App::bootstrapPath('cache/autowire.php'));

if (!$deleted) {
$this->error('Could not clear cache.');
Expand Down

0 comments on commit b2acea1

Please sign in to comment.