-
Notifications
You must be signed in to change notification settings - Fork 2
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 #31 from Ehyiah/matt/allow-service-override
refacto bundle, add override default service by implementation of int…
- Loading branch information
Showing
8 changed files
with
121 additions
and
70 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 was deleted.
Oops, something went wrong.
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,12 @@ | ||
services: | ||
_defaults: | ||
autowire: true # Automatically injects dependencies in your services. | ||
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. | ||
|
||
Ehyiah\MappingBundle\: | ||
resource: '../src/' | ||
exclude: | ||
- '../src/Attributes/' | ||
- '../src/DependencyInjection/' | ||
- '../src/Exception/' | ||
- '../src/Kernel.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,30 @@ | ||
<?php | ||
|
||
namespace Ehyiah\MappingBundle\DependencyInjection\Compiler; | ||
|
||
use Ehyiah\MappingBundle\MappingService; | ||
use Ehyiah\MappingBundle\MappingServiceInterface; | ||
use LogicException; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
class MappingServicePass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
$taggedServices = $container->findTaggedServiceIds('ehyiah.mapping_bundle.mapping_service'); | ||
|
||
if (count($taggedServices) > 1 && array_key_exists(MappingService::class, $taggedServices)) { | ||
unset($taggedServices[MappingService::class]); | ||
} | ||
|
||
if (1 === count($taggedServices)) { | ||
$definition = new Definition(MappingServiceInterface::class); | ||
$container->setDefinition(MappingServiceInterface::class, $definition); | ||
$container->setAlias(MappingServiceInterface::class, array_key_first($taggedServices)); | ||
} else { | ||
throw new LogicException('Please create a single MappingService service. You got ' . count($taggedServices) . ' services.'); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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
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,13 @@ | ||
<?php | ||
|
||
namespace Ehyiah\MappingBundle; | ||
|
||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; | ||
|
||
#[AutoconfigureTag('ehyiah.mapping_bundle.mapping_service')] | ||
interface MappingServiceInterface | ||
{ | ||
public function mapToTarget(object $mappingAwareSourceObject, ?object $targetObject = null, bool $persist = false, bool $flush = false): object; | ||
|
||
public function mapFromTarget(object $sourceObject, object $mappingAwareTargetObject): object; | ||
} |