Skip to content

Commit

Permalink
feat: bundlestore
Browse files Browse the repository at this point in the history
  • Loading branch information
joostfaassen committed Apr 7, 2021
1 parent 68657d6 commit 67918ad
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Core/BundleStore/BundleStoreInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Xillion\Core\BundleStore;

interface BundleStoreInterface
{
public function getBundle(string $bundleId): ?array;
public function setBundle(string $bundleId, array $config): void;
}
32 changes: 32 additions & 0 deletions src/Core/BundleStore/FileBundleStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Xillion\Core\BundleStore;

class FileBundleStore implements BundleStoreInterface
{
protected $basePath;

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

public function getBundle(string $bundleId): ?array
{
$filename = $this->basePath . '/' . $bundleId . '.json';
$json = file_get_contents($filename);
$config = json_decode($json, true);
return $config;
}

public function setBundle(string $bundleId, array $config): void
{
$json = json_encode($config, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
$filename = $this->basePath . '/' . $bundleId . '.json';
$path = dirname($filename);
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
file_put_contents($filename, $json);
}
}

0 comments on commit 67918ad

Please sign in to comment.