-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from kbond/fixes
Fixes
- Loading branch information
Showing
4 changed files
with
62 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
tests/Fixture/Command/BaseServiceSubscriberTraitCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/console-extra package. | ||
* | ||
* (c) Kevin Bond <kevinbond@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Console\Tests\Fixture\Command; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Symfony\Contracts\Service\Attribute\SubscribedService; | ||
use Zenstruck\Console\InvokableServiceCommand; | ||
use Zenstruck\Console\IO; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
*/ | ||
abstract class BaseServiceSubscriberTraitCommand extends InvokableServiceCommand | ||
{ | ||
public function __invoke(IO $io, RouterInterface $router): void | ||
{ | ||
$io->comment(\sprintf('IO: %s', \get_debug_type($io))); | ||
$io->comment(\sprintf('RouterInterface: %s', \get_debug_type($router))); | ||
$io->comment(\sprintf('LoggerInterface: %s', \get_debug_type($this->logger()))); | ||
} | ||
|
||
public static function getDefaultName(): string | ||
{ | ||
return 'service-subscriber-trait-command'; | ||
} | ||
|
||
abstract protected function logger(): LoggerInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,32 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/console-extra package. | ||
* | ||
* (c) Kevin Bond <kevinbond@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Console\Tests\Fixture\Command; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Routing\RouterInterface; | ||
use Symfony\Contracts\Service\Attribute\SubscribedService; | ||
use Symfony\Contracts\Service\ServiceMethodsSubscriberTrait; | ||
use Symfony\Contracts\Service\ServiceSubscriberTrait; | ||
use Zenstruck\Console\InvokableServiceCommand; | ||
use Zenstruck\Console\IO; | ||
|
||
/** | ||
* @author Kevin Bond <kevinbond@gmail.com> | ||
*/ | ||
final class ServiceSubscriberTraitCommand extends InvokableServiceCommand | ||
{ | ||
use ServiceSubscriberTrait; | ||
|
||
public function __invoke(IO $io, RouterInterface $router): void | ||
if (trait_exists(ServiceMethodsSubscriberTrait::class)) { | ||
final class ServiceSubscriberTraitCommand extends BaseServiceSubscriberTraitCommand | ||
{ | ||
$io->comment(\sprintf('IO: %s', \get_debug_type($io))); | ||
$io->comment(\sprintf('RouterInterface: %s', \get_debug_type($router))); | ||
$io->comment(\sprintf('LoggerInterface: %s', \get_debug_type($this->logger()))); | ||
} | ||
use ServiceMethodsSubscriberTrait; | ||
|
||
public static function getDefaultName(): string | ||
{ | ||
return 'service-subscriber-trait-command'; | ||
#[SubscribedService] | ||
protected function logger(): LoggerInterface | ||
{ | ||
return $this->container->get(__METHOD__); | ||
} | ||
} | ||
|
||
#[SubscribedService] | ||
private function logger(): LoggerInterface | ||
} else { | ||
final class ServiceSubscriberTraitCommand extends BaseServiceSubscriberTraitCommand | ||
{ | ||
return $this->container->get(__METHOD__); | ||
use ServiceSubscriberTrait; | ||
|
||
#[SubscribedService] | ||
protected function logger(): LoggerInterface | ||
{ | ||
return $this->container->get(__METHOD__); | ||
} | ||
} | ||
} |