-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
98 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Frontend\Compiler; | ||
|
||
use Illuminate\Contracts\Filesystem\Filesystem; | ||
use Illuminate\Support\Arr; | ||
|
||
class FileVersioner implements VersionerInterface | ||
{ | ||
/** | ||
* @var Filesystem | ||
*/ | ||
protected $filesystem; | ||
const REV_MANIFEST = 'rev-manifest.json'; | ||
|
||
public function __construct(Filesystem $filesystem) | ||
{ | ||
$this->filesystem = $filesystem; | ||
} | ||
|
||
public function putRevision(string $file, ?string $revision) | ||
{ | ||
if ($this->filesystem->has(static::REV_MANIFEST)) { | ||
$manifest = json_decode($this->filesystem->read(static::REV_MANIFEST), true); | ||
} else { | ||
$manifest = []; | ||
} | ||
|
||
if ($revision) { | ||
$manifest[$file] = $revision; | ||
} else { | ||
unset($manifest[$file]); | ||
} | ||
|
||
$this->filesystem->put(static::REV_MANIFEST, json_encode($manifest)); | ||
} | ||
|
||
public function getRevision(string $file): ?string | ||
{ | ||
if ($this->filesystem->has(static::REV_MANIFEST)) { | ||
$manifest = json_decode($this->filesystem->read(static::REV_MANIFEST), true); | ||
|
||
return Arr::get($manifest, $file); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Frontend\Compiler; | ||
|
||
interface VersionerInterface | ||
{ | ||
public function putRevision(string $file, ?string $revision); | ||
|
||
public function getRevision(string $file): ?string; | ||
} |