Skip to content

Commit

Permalink
Add addons
Browse files Browse the repository at this point in the history
  • Loading branch information
WyriHaximus committed Oct 9, 2024
1 parent 4549091 commit f2d795c
Show file tree
Hide file tree
Showing 10 changed files with 1,167 additions and 935 deletions.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
"require": {
"php": "^8.2",
"composer-plugin-api": "^2.0",
"illuminate/collections": "^8.54 || ^9 || ^10",
"mammatus/app": "dev-master",
"mammatus/cron-attributes": "^1",
"mammatus/cron-attributes": "^2",
"mammatus/cron-contracts": "^1.0.1",
"mammatus/kubernetes-attributes": "dev-main",
"mammatus/kubernetes-contracts": "dev-main",
"mammatus/kubernetes-events": "dev-main",
"mammatus/life-cycle-events": "^2",
"psr/container": "^1.1.2",
Expand All @@ -19,13 +19,12 @@
"react/async": "^4.2",
"roave/better-reflection": "^6.26",
"wyrihaximus/broadcast-contracts": "^1.3",
"wyrihaximus/list-classes-in-directory": "^1.6",
"wyrihaximus/generative-composer-plugin-tooling": "^1",
"wyrihaximus/monolog-factory": "^2",
"wyrihaximus/psr-3-context-logger": "^2.0",
"wyrihaximus/react-cron": "^5",
"wyrihaximus/react-mutex-contracts": "^2.3",
"wyrihaximus/simple-twig": "^2.1",
"wyrihaximus/string-get-in": "^1.1",
"wyrihaximus/ticking-promise": "^3.1"
},
"require-dev": {
Expand Down
1,619 changes: 966 additions & 653 deletions composer.lock

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions etc/generated_templates/AbstractList_.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ declare(strict_types=1);
namespace Mammatus\Cron\Generated;
use WyriHaximus\React\Cron;
use WyriHaximus\React\Cron\Action;
use WyriHaximus\React\Mutex\Contracts\MutexInterface;
use Mammatus\Cron\Action;
// phpcs:disable
/**
Expand All @@ -15,22 +13,23 @@ use WyriHaximus\React\Mutex\Contracts\MutexInterface;
abstract class AbstractList_
{
/**
* @return iterable<array<string, string>>
* @return iterable<Action>
*/
final protected function crons(): iterable
{
{% for action in actions %}
/** @see \{{ action.class }} */
yield [
{% if action.split_out == true %}
'type' => 'kubernetes',
yield new Action(
{% if action.splitOut == true %}
type: 'kubernetes',
{% else %}
'type' => 'internal',
type: 'internal',
{% endif %}
'name' => '{{ action.cron.name }}',
'schedule' => '{{ action.cron.schedule }}',
'class' => \{{ action.class }}::class,
];
name: '{{ action.cron.name }}',
schedule: '{{ action.cron.schedule }}',
class: \{{ action.class }}::class,
addOns: \json_decode('{{ action.cron.addOns|json_encode()|raw }}', true), /** @phpstan-ignore-line */
);
{% endfor %}
}
}
2 changes: 1 addition & 1 deletion etc/generated_templates/AbstractManager.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class AbstractManager
$this->cron = Cron::createWithMutex(
$mutex,
{% for action in actions %}
{% if action.split_out != true %}
{% if action.splitOut != true %}
/** @see \{{ action.class }} */
new Action(
'cron_{{ action.cron.name }}',
Expand Down
18 changes: 18 additions & 0 deletions src/Action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Mammatus\Cron;

final readonly class Action
{
/** @param array<string, mixed> $addOns */
public function __construct(
public string $type,
public string $name,
public string $schedule,
public string $class,
public array $addOns,
) {
}
}
37 changes: 37 additions & 0 deletions src/Composer/Collector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Mammatus\Cron\Composer;

use Mammatus\Cron\Attributes\Cron;
use Mammatus\Kubernetes\Attributes\SplitOut;
use Roave\BetterReflection\Reflection\ReflectionClass;
use WyriHaximus\Composer\GenerativePluginTooling\Item as ItemContract;
use WyriHaximus\Composer\GenerativePluginTooling\ItemCollector;

use function array_key_exists;

final class Collector implements ItemCollector
{
/** @return iterable<ItemContract> */
public function collect(ReflectionClass $class): iterable
{
/** @var array<Cron> $attributes */
$attributes = [];
foreach ((new \ReflectionClass($class->getName()))->getAttributes() as $attributeReflection) {
$attribute = $attributeReflection->newInstance();
$attributes[$attribute::class] = $attribute;
}

if (! array_key_exists(Cron::class, $attributes)) {
return;
}

yield new Item(
$class->getName(),
$attributes[Cron::class],

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.2 (nts) with highest dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.2 (nts) with locked dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.2 (nts) with lowest dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.2 (zts) with highest dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.2 (zts) with locked dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.2 (zts) with lowest dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.3 (nts) with highest dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.3 (nts) with locked dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.3 (nts) with lowest dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.3 (zts) with highest dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.3 (zts) with locked dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.

Check failure on line 33 in src/Composer/Collector.php

View workflow job for this annotation

GitHub Actions / Continuous Integration / Continuous Integration / Run stan on PHP 8.3 (zts) with lowest dependency preference

Parameter #2 $cron of class Mammatus\Cron\Composer\Item constructor expects Mammatus\Cron\Attributes\Cron, object given.
array_key_exists(SplitOut::class, $attributes),
);
}
}
Loading

0 comments on commit f2d795c

Please sign in to comment.