Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 9 support #84

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
{
"name": "brexis/laravel-workflow",
"description": "Integerate Symfony Workflow component into Laravel.",
"keywords": ["workflow", "symfony", "laravel", "laravel5", "laravel6"],
"keywords": ["workflow", "symfony", "laravel", "laravel8", "laravel9"],
"license": "MIT",
"require": {
"php": ">=5.5.9",
"symfony/workflow": "^3.3 || ^4.0",
"symfony/process": "^3.3 || ^4.0",
"symfony/event-dispatcher": "^3.3 || ^4.0",
"illuminate/console": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.*",
"illuminate/support": "5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.*"
"php": "^8.0.2",
"symfony/workflow": "^6.0",
"symfony/process": "^6.0",
"symfony/event-dispatcher": "^5.0",
"illuminate/console": "8.* || 9.*",
"illuminate/support": "8.* || 9.*"
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^8.0 || ^9.0"
},
"autoload": {
"psr-4": {
Expand All @@ -33,9 +37,5 @@
"Workflow": "Brexis\\LaravelWorkflow\\Facades\\WorkflowFacade"
}
}
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^6.0 || ~7.0 || ^8.0"
}
}
2 changes: 1 addition & 1 deletion src/Commands/WorkflowDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle()

$dotCommand = "dot -T$format -o $workflowName.$format";

$process = new Process($dotCommand);
$process = Process::fromShellCommandline($dotCommand);
$process->setInput($dumper->dump($definition));
$process->mustRun();
}
Expand Down
41 changes: 30 additions & 11 deletions src/WorkflowRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Brexis\LaravelWorkflow;

use Brexis\LaravelWorkflow\Events\WorkflowSubscriber;
use phpDocumentor\Reflection\DocBlock\Tags\Param;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Workflow\Definition;
use Symfony\Component\Workflow\DefinitionBuilder;
use Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface;
use Symfony\Component\Workflow\MarkingStore\MultipleStateMarkingStore;
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
use Symfony\Component\Workflow\Registry;
use Symfony\Component\Workflow\StateMachine;
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
Expand Down Expand Up @@ -58,8 +58,8 @@ public function __construct(array $config)
/**
* Return the $subject workflow
*
* @param object $subject
* @param string $workflowName
* @param object $subject
* @param string|null $workflowName
* @return Workflow
*/
public function get($subject, $workflowName = null)
Expand Down Expand Up @@ -144,18 +144,37 @@ protected function getWorkflowInstance(
protected function getMarkingStoreInstance(array $workflowData)
{
$markingStoreData = isset($workflowData['marking_store']) ? $workflowData['marking_store'] : [];
$arguments = isset($markingStoreData['arguments']) ? $markingStoreData['arguments'] : [];
$arguments = $this->getMarkingStoreArguments($markingStoreData);

if (isset($markingStoreData['class'])) {
$className = $markingStoreData['class'];
} elseif (isset($markingStoreData['type']) && $markingStoreData['type'] === 'multiple_state') {
$className = MultipleStateMarkingStore::class;
} else {
$className = SingleStateMarkingStore::class;

$class = new \ReflectionClass($className);

return $class->newInstanceArgs($arguments);
}

$class = new \ReflectionClass($className);
return new MethodMarkingStore(...$arguments);
}

/**
* Get the arguments for the marking store
*
* @param array $markingStoreData
* @return array
*/
protected function getMarkingStoreArguments(array $markingStoreData)
{
$arguments = isset($markingStoreData['arguments']) ? $markingStoreData['arguments'] : [];

if (isset($markingStoreData['class']) || empty($arguments) || is_bool($arguments[0])) {
return $arguments;
}

$singleState = isset($markingStoreData['type']) && $markingStoreData['type'] === 'single_state';

array_unshift($arguments, $singleState);

return $class->newInstanceArgs($arguments);
return $arguments;
}
}
16 changes: 16 additions & 0 deletions tests/Fixtures/TestObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@
class TestObject
{
public $marking;

/**
* @return mixed
*/
public function getMarking()
{
return $this->marking;
}

/**
* @param mixed $marking
*/
public function setMarking($marking)
{
$this->marking = $marking;
}
}
27 changes: 27 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Tests {

/**
* Class TestCase
*
* @package Tests
*/
abstract class TestCase extends \PHPUnit\Framework\TestCase
{

}
}

namespace {

if (! function_exists('event')) {
$events = null;

function event($ev)
{
global $events;
$events[] = $ev;
}
}
}
2 changes: 1 addition & 1 deletion tests/WorkflowDumpCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Tests {

use Brexis\LaravelWorkflow\Commands\WorkflowDumpCommand;
use Mockery;
use PHPUnit\Framework\TestCase;

class WorkflowDumpCommandTest extends TestCase
{
Expand Down
Loading