mirror of
https://github.com/flextype/flextype.git
synced 2025-08-08 06:06:45 +02:00
feat(actions): add Actions API #549
This commit is contained in:
66
src/flextype/Foundation/Actions.php
Normal file
66
src/flextype/Foundation/Actions.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (https://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
namespace Flextype\Foundation;
|
||||
|
||||
use Atomastic\Arrays\Arrays;
|
||||
use Atomastic\Macroable\Macroable;
|
||||
|
||||
class Actions extends Arrays
|
||||
{
|
||||
use Macroable;
|
||||
|
||||
/**
|
||||
* Actions instance
|
||||
*/
|
||||
private static ?Actions $instance = null;
|
||||
|
||||
/**
|
||||
* Actions storage
|
||||
*/
|
||||
private static ?Arrays $storage = null;
|
||||
|
||||
/**
|
||||
* Gets the instance via lazy initialization (created on first usage)
|
||||
*/
|
||||
public static function getInstance(): Actions
|
||||
{
|
||||
if (static::$instance === null) {
|
||||
static::$instance = new self();
|
||||
}
|
||||
|
||||
if (static::$storage === null) {
|
||||
static::$storage = new Arrays();
|
||||
}
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is not allowed to call from outside to prevent from creating multiple instances,
|
||||
* to use the Actions, you have to obtain the instance from Actions::getInstance() instead.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent the instance from being cloned (which would create a second instance of it)
|
||||
*/
|
||||
protected function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent from being unserialized (which would create a second instance of it)
|
||||
*/
|
||||
public function __wakeup(): void
|
||||
{
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ use Atomastic\Session\Session;
|
||||
use Bnf\Slim3Psr15\CallableResolver;
|
||||
use Cocur\Slugify\Slugify;
|
||||
use DateTimeZone;
|
||||
use Flextype\Foundation\Actions;
|
||||
use Flextype\Foundation\Cors;
|
||||
use Flextype\Foundation\Entries\Entries;
|
||||
use Flextype\Foundation\Flextype;
|
||||
@@ -76,6 +77,11 @@ use function ucwords;
|
||||
*/
|
||||
$registry = Registry::getInstance();
|
||||
|
||||
/**
|
||||
* Init Actions
|
||||
*/
|
||||
$actions = Actions::getInstance();
|
||||
|
||||
/**
|
||||
* Preflight the Flextype
|
||||
*/
|
||||
@@ -155,6 +161,11 @@ flextype()->container()['callableResolver'] = static fn () => new CallableResolv
|
||||
*/
|
||||
flextype()->container()['registry'] = $registry;
|
||||
|
||||
/**
|
||||
* Add actions service to Flextype container
|
||||
*/
|
||||
flextype()->container()['actions'] = $actions;
|
||||
|
||||
/**
|
||||
* Add logger service to Flextype container
|
||||
*/
|
||||
|
Reference in New Issue
Block a user