Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
68 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace ICanBoogie\Binding\ActiveRecord; | ||
|
||
use Attribute; | ||
use ICanBoogie\ActiveRecord; | ||
use Symfony\Component\DependencyInjection\Attribute\Autowire; | ||
|
||
use function sprintf; | ||
use function str_replace; | ||
|
||
#[Attribute(Attribute::TARGET_PARAMETER)] | ||
class Record extends Autowire | ||
{ | ||
/** | ||
* @param class-string<ActiveRecord> $activerecord_class | ||
*/ | ||
public function __construct( // @phpstan-ignore-line | ||
public readonly string $activerecord_class, | ||
) { | ||
parent::__construct( | ||
expression: sprintf( | ||
"service('%s').model_for_activerecord('%s')", | ||
self::escape(ActiveRecord\ModelProvider::class), | ||
self::escape($this->activerecord_class) | ||
) | ||
); | ||
} | ||
|
||
private static function escape(string $str): string { | ||
return str_replace('\\', '\\\\', $str); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace Test\ICanBoogie\Binding\ActiveRecord\Acme; | ||
|
||
use ICanBoogie\ActiveRecord\Model; | ||
use ICanBoogie\Binding\ActiveRecord\Record; | ||
|
||
final class SampleService | ||
{ | ||
/** | ||
* @param Model<int, Article> $model | ||
*/ | ||
public function __construct( | ||
#[Record(Article::class)] public readonly Model $model, | ||
) { | ||
} | ||
} |
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