Skip to content

Commit

Permalink
Merge pull request #256 from tienvx/flysystem-bundle
Browse files Browse the repository at this point in the history
Use offical flysystem bundle
  • Loading branch information
tienvx committed May 30, 2019
2 parents 48bb11b + ef312d8 commit 9085bfe
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 149 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ All you have to do:
## Requirements

* PHP 7.1 / 7.2 / 7.3
* Symfony 4.2
* Symfony 4.3
* See also the `require` section of [composer.json](composer.json)

## Installation
Expand All @@ -43,10 +43,23 @@ $ composer create-project symfony/skeleton my-project
Install lastest version of this bundle:

```console
$ composer require tienvx/mbt-bundle "^1.6"
$ composer require tienvx/mbt-bundle "^1.7"
```

### Step 3: Create models and subjects
### Step 3: Config file storage

In order to save screenshots of bug report, we need to configure file system:
```yaml
flysystem:
storages:
# Name of the storage is matter
mbt.storage:
adapter: 'local'
options:
directory: '%kernel.project_dir%/var/storage/screenshots'
```
### Step 4: Create models and subjects
Model is the way to describe part your application. Subject is
the way to tell this bundle to interact with your application.
Expand Down
30 changes: 15 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@
"php": "^7.1.3",
"ext-json": "*",
"graphp/algorithms": "^0.8.1",
"symfony/framework-bundle": "^v4.2",
"symfony/console": "^v4.2",
"symfony/workflow": "^v4.2",
"symfony/validator": "^v4.2",
"symfony/messenger": "^v4.2",
"symfony/process": "^v4.2",
"symfony/serializer": "^4.2",
"symfony/framework-bundle": "^v4.3",
"symfony/console": "^v4.3",
"symfony/workflow": "^v4.3",
"symfony/validator": "^v4.3",
"symfony/messenger": "^v4.3",
"symfony/process": "^v4.3",
"symfony/serializer": "^4.3",
"doctrine/doctrine-bundle": "^1.10",
"doctrine/orm": "^2.6",
"dunglas/doctrine-json-odm": "^0.1.3",
"symfony/monolog-bundle": "^3.3",
"oneup/flysystem-bundle": "^3.0"
"league/flysystem-bundle": "^1.1"
},
"require-dev": {
"phpunit/phpunit": "^7.4",
"phpunit/phpunit": "^7.5",
"php-coveralls/php-coveralls": "^2.1",
"friendsofphp/php-cs-fixer": "^2.14",
"symfony/yaml": "^4.2",
"symfony/expression-language": "^4.2",
"symfony/security-bundle": "^4.2",
"friendsofphp/php-cs-fixer": "^2.15",
"symfony/yaml": "^4.3",
"symfony/expression-language": "^4.3",
"symfony/security-bundle": "^4.3",
"symfony/maker-bundle": "^1.11",
"tienvx/messenger-memory-transport": "^0.1",
"tienvx/messenger-memory-transport": "^0.2",
"league/flysystem-memory": "^1.0"
},
"autoload": {
Expand Down Expand Up @@ -70,7 +70,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.6-dev"
"dev-master": "1.7-dev"
}
},
"suggest": {
Expand Down
21 changes: 7 additions & 14 deletions src/Command/CaptureScreenshotsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\ORM\EntityManagerInterface;
use Exception;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -32,16 +32,18 @@ class CaptureScreenshotsCommand extends AbstractCommand
protected $workflowRegistry;

/**
* @var Filesystem
* @var FilesystemInterface
*/
protected $filesystem;
protected $mbtStorage;

public function __construct(
EntityManagerInterface $entityManager,
SubjectManager $subjectManager
SubjectManager $subjectManager,
FilesystemInterface $mbtStorage
) {
$this->entityManager = $entityManager;
$this->subjectManager = $subjectManager;
$this->mbtStorage = $mbtStorage;

parent::__construct();
}
Expand All @@ -60,11 +62,6 @@ public function setWorkflowRegistry(Registry $workflowRegistry)
$this->workflowRegistry = $workflowRegistry;
}

public function setFilesystem(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}

/**
* @param InputInterface $input
* @param OutputInterface $output
Expand All @@ -87,10 +84,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new Exception('Can not capture screenshots: No workflows were defined');
}

if (!$this->filesystem instanceof Filesystem) {
throw new Exception("Can not capture screenshots: No filesystems with name 'mbt' were defined");
}

$this->setAnonymousToken();

$path = Path::unserialize($bug->getPath());
Expand All @@ -99,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$workflow = $this->workflowRegistry->get($subject, $model);

$subject->setUp();
$subject->setFilesystem($this->filesystem);
$subject->setFilesystem($this->mbtStorage);
$subject->removeScreenshots($bugId);

try {
Expand Down
21 changes: 7 additions & 14 deletions src/Command/RemoveScreenshotsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\ORM\EntityManagerInterface;
use Exception;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -24,16 +24,18 @@ class RemoveScreenshotsCommand extends Command
protected $subjectManager;

/**
* @var Filesystem
* @var FilesystemInterface
*/
protected $filesystem;
protected $mbtStorage;

public function __construct(
EntityManagerInterface $entityManager,
SubjectManager $subjectManager
SubjectManager $subjectManager,
FilesystemInterface $mbtStorage
) {
$this->entityManager = $entityManager;
$this->subjectManager = $subjectManager;
$this->mbtStorage = $mbtStorage;

parent::__construct();
}
Expand All @@ -48,11 +50,6 @@ protected function configure()
->addArgument('model', InputArgument::REQUIRED, 'The model of the task.');
}

public function setFilesystem(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}

/**
* @param InputInterface $input
* @param OutputInterface $output
Expand All @@ -64,12 +61,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$bugId = $input->getArgument('bug-id');
$model = $input->getArgument('model');

if (!$this->filesystem instanceof Filesystem) {
throw new Exception("Can not remove screenshots: No filesystems with name 'mbt' were defined");
}

$subject = $this->subjectManager->createSubject($model);
$subject->setFilesystem($this->filesystem);
$subject->setFilesystem($this->mbtStorage);
$subject->removeScreenshots($bugId);
}
}
21 changes: 7 additions & 14 deletions src/Command/ReportBugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\ORM\EntityManagerInterface;
use Exception;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -32,16 +32,18 @@ class ReportBugCommand extends Command
protected $subjectManager;

/**
* @var Filesystem
* @var FilesystemInterface
*/
protected $filesystem;
protected $mbtStorage;

public function __construct(
EntityManagerInterface $entityManager,
SubjectManager $subjectManager
SubjectManager $subjectManager,
FilesystemInterface $mbtStorage
) {
$this->entityManager = $entityManager;
$this->subjectManager = $subjectManager;
$this->mbtStorage = $mbtStorage;

parent::__construct();
}
Expand All @@ -60,11 +62,6 @@ public function setLogger(LoggerInterface $logger)
$this->logger = $logger;
}

public function setFilesystem(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}

/**
* @param InputInterface $input
* @param OutputInterface $output
Expand All @@ -77,10 +74,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new Exception("Can not report bug: No monolog's handlers with channel 'mbt' were defined");
}

if (!$this->filesystem instanceof Filesystem) {
throw new Exception("Can not report bug: No filesystems with name 'mbt' were defined");
}

$bugId = $input->getArgument('bug-id');

$callback = function () use ($bugId) {
Expand All @@ -105,7 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$model = $bug->getTask()->getModel();
$subject = $this->subjectManager->createSubject($model);

$subject->setFilesystem($this->filesystem);
$subject->setFilesystem($this->mbtStorage);

$this->logger->error($bug->getBugMessage(), [
'bug' => $bug,
Expand Down
42 changes: 0 additions & 42 deletions src/DependencyInjection/Compiler/FlysystemFilesystemPass.php

This file was deleted.

35 changes: 19 additions & 16 deletions src/Service/GraphBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use Fhaculty\Graph\Graph;
use Fhaculty\Graph\Vertex;
use Graphp\Algorithms\ConnectedComponents;
use Psr\SimpleCache\CacheException;
use Psr\SimpleCache\CacheInterface;
use Psr\Cache\InvalidArgumentException;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Workflow\StateMachine;
use Symfony\Component\Workflow\Transition;
use Symfony\Component\Workflow\Workflow;
Expand All @@ -16,11 +16,11 @@
class GraphBuilder
{
/**
* @var CacheInterface
* @var AdapterInterface
*/
protected $cache;

public function __construct(CacheInterface $cache)
public function __construct(AdapterInterface $cache)
{
$this->cache = $cache;
}
Expand All @@ -31,24 +31,27 @@ public function __construct(CacheInterface $cache)
* @return Graph
*
* @throws Exception
* @throws CacheException
* @throws InvalidArgumentException
*/
public function build(Workflow $workflow): Graph
{
if ($this->cache->has('mbt.graph.'.$workflow->getName())) {
return $this->cache->get('mbt.graph.'.$workflow->getName());
}
if ($workflow instanceof StateMachine) {
$graph = $this->buildForStateMachine($workflow);
$cacheItem = $this->cache->getItem('mbt.graph.'.$workflow->getName());
if (!$cacheItem->isHit()) {
if ($workflow instanceof StateMachine) {
$graph = $this->buildForStateMachine($workflow);
} else {
$graph = $this->buildForWorkflow($workflow);
$initVertex = VertexHelper::getId([$workflow->getDefinition()->getInitialPlace()]);
$components = new ConnectedComponents($graph);
$graph = $components->createGraphComponentVertex($graph->getVertex($initVertex));
}

$cacheItem->set($graph);
$this->cache->save($cacheItem);
} else {
$graph = $this->buildForWorkflow($workflow);
$initVertex = VertexHelper::getId([$workflow->getDefinition()->getInitialPlace()]);
$components = new ConnectedComponents($graph);
$graph = $components->createGraphComponentVertex($graph->getVertex($initVertex));
$graph = $cacheItem->get();
}

$this->cache->set('mbt.graph.'.$workflow->getName(), $graph);

return $graph;
}

Expand Down
Loading

0 comments on commit 9085bfe

Please sign in to comment.