-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ccf7a2e
commit 54fdcde
Showing
13 changed files
with
219 additions
and
35 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
32 changes: 32 additions & 0 deletions
32
src/DependencyInjection/Compiler/StorageAdapterCompilerPass.php
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,32 @@ | ||
<?php | ||
|
||
/** | ||
* Created on Wed Mar 16 2022 | ||
* @author : Nicolas RENAULT <[email protected]> | ||
* @copyright (c) 2022 Tangkoko | ||
**/ | ||
|
||
namespace Nicoren\CronBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\DependencyInjection\Alias; | ||
|
||
class StorageAdapterCompilerPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
$pool = $container->getDefinition('nicoren_cron.storage.adapter.pool'); | ||
|
||
$adapters = []; | ||
foreach ($container->findTaggedServiceIds('nicoren_cron.storage_adapter') as $id => $tags) { | ||
$adapters[$tags[0]["alias"]] = new Reference($id); | ||
if ($container->getParameter('nicoren_cron.storage.adapter_code') == $tags[0]["alias"]) { | ||
|
||
$container->setAlias('nicoren_cron.storage.adapter', new Alias($id, false)); | ||
} | ||
} | ||
$pool->setArgument(0, $adapters); | ||
} | ||
} |
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
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
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,27 @@ | ||
<?xml version="1.0" ?> | ||
<!-- | ||
Created on Mon Apr 12 2021 | ||
@author : Nicolas RENAULT <[email protected]> | ||
@license MIT | ||
--> | ||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<defaults autowire="true" autoconfigure="true"/> | ||
<!-- Pool Adapter --> | ||
<service id="nicoren_cron.storage.adapter.pool" class="Nicoren\CronBundle\Storage\Adapter\Pool"> | ||
<argument type="collection"> | ||
</argument> | ||
</service> | ||
<service id="Nicoren\CronBundle\Storage\Adapter\PoolInterface" alias="nicoren_cron.storage.adapter.pool" public="false"/> | ||
|
||
<!-- Adapters --> | ||
<service id="nicoren_cron.storage.adapter.filesystem" class="Nicoren\CronBundle\Storage\Adapter\Filesystem"> | ||
<argument>%kernel.project_dir%/var/cron/pids</argument> | ||
<tag name="nicoren_cron.storage_adapter" alias="filesystem"/> | ||
</service> | ||
</services> | ||
</container> | ||
|
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 | ||
|
||
namespace Nicoren\CronBundle\Storage\Adapter; | ||
|
||
/** | ||
* Created on Wed Mar 16 2022 | ||
* @author : Nicolas RENAULT <[email protected]> | ||
* @copyright (c) 2022 Tangkoko | ||
**/ | ||
|
||
|
||
interface AdapterInterface | ||
{ | ||
public function get(): array; | ||
|
||
public function set(array $value): self; | ||
} |
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,46 @@ | ||
<?php | ||
|
||
namespace Nicoren\CronBundle\Storage\Adapter; | ||
|
||
use Symfony\Component\Filesystem\Exception\IOExceptionInterface; | ||
use Symfony\Component\Filesystem\Filesystem as FilesystemClient; | ||
use Symfony\Component\Filesystem\Path; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
|
||
|
||
/** | ||
* Created on Wed Mar 16 2022 | ||
* @author : Nicolas RENAULT <[email protected]> | ||
* @copyright (c) 2022 Tangkoko | ||
**/ | ||
|
||
|
||
class Filesystem implements AdapterInterface | ||
{ | ||
|
||
private string $file; | ||
private FilesystemClient $client; | ||
|
||
public function __construct(string $file) | ||
{ | ||
$this->file = $file; | ||
$this->client = new FilesystemClient(); | ||
} | ||
|
||
public function get(): array | ||
{ | ||
$ids = []; | ||
if ($this->client->exists($this->file)) { | ||
$fileInfo = new SplFileInfo($this->file, '', ''); | ||
$ids = json_decode($fileInfo->getContents(), true); | ||
} | ||
return $ids; | ||
} | ||
|
||
public function set(array $value): self | ||
{ | ||
$this->client->dumpFile($this->file, json_encode($value)); | ||
return $this; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Nicoren\CronBundle\Storage\Adapter; | ||
|
||
/** | ||
* Created on Wed Mar 16 2022 | ||
* @author : Nicolas RENAULT <[email protected]> | ||
* @copyright (c) 2022 Tangkoko | ||
**/ | ||
|
||
|
||
class Pool implements PoolInterface | ||
{ | ||
/** | ||
* | ||
* @var array<AdapterInterface> | ||
*/ | ||
private array $adapters = []; | ||
|
||
public function __construct(?array $adapters = []) | ||
{ | ||
var_dump($this->adapters); | ||
$this->adapters = $adapters; | ||
} | ||
|
||
public function getAdapters(): array | ||
{ | ||
return $this->adapters; | ||
} | ||
|
||
public function getAdapter(string $key): AdapterInterface | ||
{ | ||
return $this->adapters[$key]; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Nicoren\CronBundle\Storage\Adapter; | ||
|
||
/** | ||
* Created on Wed Mar 16 2022 | ||
* @author : Nicolas RENAULT <[email protected]> | ||
* @copyright (c) 2022 Tangkoko | ||
**/ | ||
|
||
|
||
interface PoolInterface | ||
{ | ||
|
||
public function getAdapters(): array; | ||
|
||
public function getAdapter(string $key): AdapterInterface; | ||
} |