Skip to content

Commit 15f0a48

Browse files
committed
refactoring.
1 parent eea4f1e commit 15f0a48

27 files changed

+250
-155
lines changed

.github/workflows/ci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build-test:
7+
runs-on: ubuntu-latest
8+
container:
9+
image: php:8.4 # This forces the job to run in a Docker container
10+
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
15+
- name: Install System Dependencies (Git, Zip, Unzip)
16+
run: |
17+
apt-get update
18+
apt-get install -y unzip git zip
19+
20+
- name: Install and Enable extensions
21+
run: |
22+
docker-php-ext-install sockets calendar
23+
docker-php-ext-enable sockets calendar
24+
25+
- name: Install Composer
26+
run: |
27+
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
28+
composer --version
29+
30+
- name: Install Dependencies
31+
run: composer install --prefer-dist --no-progress
32+
33+
- name: Run PHPUnit
34+
run: vendor/bin/phpunit tests

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,14 @@ An ObserverableTrait and IObserver interface make up the Observer pattern implem
6060

6161
### Registry
6262

63+
64+
6365
### Singleton
6466

67+
The singleton is a mixture of singleton and memento patterns whereby it can
68+
serialize itself to both memcache and redis to be shared across applications.
69+
70+
6571
# More Information
6672

6773
You can read more about the Neuron components at [neuronphp.com](http://neuronphp.com)

VERSIONLOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
## 0.6.7
1+
## 0.7.0
2+
* Refactoring.
3+
* Added Redis singleton.
24

5+
## 0.6.7
36
## 0.6.6 2025-01-27
4-
* Updated to data 0.7
5-
67
## 0.6.5
78
## 0.6.4
89
## 0.6.3

src/Patterns/Command/Cache.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Neuron\Patterns\Command;
4+
5+
use Neuron\Core\Exceptions\CommandNotFound;
6+
use Neuron\Patterns\Singleton\Memory as Singleton;
7+
8+
/**
9+
* Maps strings to command classes.
10+
*/
11+
12+
class Cache extends Singleton
13+
{
14+
private static array $_Cache = [];
15+
16+
/**
17+
* @param string $Action
18+
* @param string $Command
19+
* @return Cache
20+
*/
21+
22+
public function set( string $Action, string $Command ): Cache
23+
{
24+
self::$_Cache[ $Action ] = $Command;
25+
26+
return self::instance();
27+
}
28+
29+
/**
30+
* @param string $Action
31+
* @return ICommand
32+
* @throws CommandNotFound
33+
*/
34+
35+
public function get( string $Action ): ICommand
36+
{
37+
if( !isset( self::$_Cache[ $Action ] ) )
38+
{
39+
throw new CommandNotFound( "No command found for action '{$Action}' in the cache." );
40+
}
41+
42+
return new self::$_Cache[ $Action ];
43+
}
44+
}

src/Patterns/Command/CommandCache.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/Patterns/Command/CommandFactory.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/Patterns/Command/CommandNotFoundException.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Patterns/Command/EmptyActionParameterException.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Patterns/Command/Factory.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Neuron\Patterns\Command;
4+
5+
use Neuron\Core\Exceptions\CommandNotFound;
6+
7+
/**
8+
* Gets or creates a command object.
9+
*/
10+
11+
class Factory
12+
{
13+
private Cache $_Cache;
14+
15+
/**
16+
* @param Cache $Cache
17+
*/
18+
19+
public function __construct( Cache $Cache )
20+
{
21+
$this->_Cache = $Cache;
22+
}
23+
24+
/**
25+
* @param string $Action
26+
* @return ICommand
27+
* @throws CommandNotFound
28+
*/
29+
30+
public function get( string $Action ): ICommand
31+
{
32+
return $this->_Cache->get( $Action );
33+
}
34+
}

0 commit comments

Comments
 (0)