Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Commit

Permalink
Add kernel project dir in bind services to use it in MediaObjectProce…
Browse files Browse the repository at this point in the history
…ssor
  • Loading branch information
GuillaumeKESTEMAN committed Aug 25, 2022
1 parent 597b49b commit 2e37c1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions api/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ services:
$twitterAccessTokenSecret: '%env(TWITTER_ACCESS_TOKEN_SECRET)%'
$communicationWebsiteUrl: '%env(COMMUNICATION_WEBSITE_URL)%'
$appEnv: '%env(APP_ENV)%'
$kernelDir: '%kernel.project_dir%'

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
Expand Down
16 changes: 7 additions & 9 deletions api/src/DataFixtures/Processor/MediaObjectProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

final class MediaObjectProcessor implements ProcessorInterface
{
public function __construct(private readonly string $appEnv)
public function __construct(private readonly string $appEnv, private readonly string $kernelDir)
{
}

/**
* {@inheritdoc}
*/
public function preProcess(string $id, $object): void
public
function preProcess(string $id, $object): void
{
if (!$object instanceof MediaObject) {
return;
Expand All @@ -29,18 +30,15 @@ public function preProcess(string $id, $object): void

$fs = new Filesystem();

$root = explode('/', __DIR__);
$root = \array_slice($root, 0, -3);
$root = implode('/', $root);

$fs->touch($root . '/fixtures/test/files/invalid_file.txt');
$fs->appendToFile($root . '/fixtures/test/files/invalid_file.txt', 'My invalid file !!!');
$fs->touch($this->kernelDir . '/fixtures/test/files/invalid_file.txt');
$fs->appendToFile($this->kernelDir . '/fixtures/test/files/invalid_file.txt', 'My invalid file !!!');
}

/**
* {@inheritdoc}
*/
public function postProcess(string $id, $object): void
public
function postProcess(string $id, $object): void
{
// do nothing
}
Expand Down

0 comments on commit 2e37c1b

Please sign in to comment.