diff --git a/.github/workflows/code_samples.yaml b/.github/workflows/code_samples.yaml index 4721bce9f9..138326cc59 100644 --- a/.github/workflows/code_samples.yaml +++ b/.github/workflows/code_samples.yaml @@ -38,6 +38,9 @@ jobs: - name: Run PHPStan analysis run: composer phpstan + - name: Run rector + run: vendor/bin/rector process --dry-run --ansi + code-samples-inclusion-check: name: Check code samples inclusion runs-on: ubuntu-latest diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 38b8df8e41..bc76d9099e 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -11,6 +11,9 @@ $configFactory = new InternalConfigFactory(); $configFactory->withRules([ 'header_comment' => false, + 'method_argument_space' => [ + 'attribute_placement' => 'same_line' + ] ]); return $configFactory diff --git a/code_samples/ai_actions/src/AI/Action/TranscribeAudioAction.php b/code_samples/ai_actions/src/AI/Action/TranscribeAudioAction.php index 49663f2bb3..6ab3027e0f 100644 --- a/code_samples/ai_actions/src/AI/Action/TranscribeAudioAction.php +++ b/code_samples/ai_actions/src/AI/Action/TranscribeAudioAction.php @@ -9,11 +9,8 @@ final class TranscribeAudioAction extends Action { - private Audio $audio; - - public function __construct(Audio $audio) + public function __construct(private readonly Audio $audio) { - $this->audio = $audio; } public function getParameters(): array diff --git a/code_samples/ai_actions/src/AI/ActionType/TranscribeAudioActionType.php b/code_samples/ai_actions/src/AI/ActionType/TranscribeAudioActionType.php index e77e9efb45..d6b4b87f48 100644 --- a/code_samples/ai_actions/src/AI/ActionType/TranscribeAudioActionType.php +++ b/code_samples/ai_actions/src/AI/ActionType/TranscribeAudioActionType.php @@ -12,17 +12,13 @@ use Ibexa\Contracts\ConnectorAi\DataType; use Ibexa\Contracts\Core\Exception\InvalidArgumentException; -final class TranscribeAudioActionType implements ActionTypeInterface +final readonly class TranscribeAudioActionType implements ActionTypeInterface { - public const IDENTIFIER = 'transcribe_audio'; - - /** @var iterable<\Ibexa\Contracts\ConnectorAi\Action\ActionHandlerInterface> */ - private iterable $actionHandlers; + public const string IDENTIFIER = 'transcribe_audio'; /** @param iterable<\Ibexa\Contracts\ConnectorAi\Action\ActionHandlerInterface> $actionHandlers*/ - public function __construct(iterable $actionHandlers) + public function __construct(private iterable $actionHandlers) { - $this->actionHandlers = $actionHandlers; } public function getIdentifier(): string diff --git a/code_samples/ai_actions/src/AI/DataType/Audio.php b/code_samples/ai_actions/src/AI/DataType/Audio.php index 8f9f0f9475..bea562a1c9 100644 --- a/code_samples/ai_actions/src/AI/DataType/Audio.php +++ b/code_samples/ai_actions/src/AI/DataType/Audio.php @@ -11,15 +11,11 @@ */ final class Audio implements DataType { - /** @var non-empty-array */ - private array $base64; - /** * @param non-empty-array $base64 */ - public function __construct(array $base64) + public function __construct(private array $base64) { - $this->base64 = $base64; } public function getBase64(): string diff --git a/code_samples/ai_actions/src/AI/Handler/LLaVaTextToTextActionHandler.php b/code_samples/ai_actions/src/AI/Handler/LLaVaTextToTextActionHandler.php index 71ed36cda0..df616c173f 100644 --- a/code_samples/ai_actions/src/AI/Handler/LLaVaTextToTextActionHandler.php +++ b/code_samples/ai_actions/src/AI/Handler/LLaVaTextToTextActionHandler.php @@ -12,18 +12,12 @@ use Ibexa\Contracts\ConnectorAi\ActionResponseInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; -final class LLaVaTextToTextActionHandler implements ActionHandlerInterface +final readonly class LLaVaTextToTextActionHandler implements ActionHandlerInterface { - private HttpClientInterface $client; + public const string IDENTIFIER = 'LLaVATextToText'; - private string $host; - - public const IDENTIFIER = 'LLaVATextToText'; - - public function __construct(HttpClientInterface $client, string $host = 'http://localhost:8080') + public function __construct(private HttpClientInterface $client, private string $host = 'http://localhost:8080') { - $this->client = $client; - $this->host = $host; } public function supports(ActionInterface $action): bool @@ -63,7 +57,7 @@ public function handle(ActionInterface $action, array $context = []): ActionResp ] ); - $output = strip_tags(json_decode($response->getContent(), true)['choices'][0]['message']['content']); + $output = strip_tags((string) json_decode($response->getContent(), true)['choices'][0]['message']['content']); return new TextResponse(new Text([$output])); } diff --git a/code_samples/ai_actions/src/AI/Handler/WhisperAudioToTextActionHandler.php b/code_samples/ai_actions/src/AI/Handler/WhisperAudioToTextActionHandler.php index 1c253249ce..583f75fa54 100644 --- a/code_samples/ai_actions/src/AI/Handler/WhisperAudioToTextActionHandler.php +++ b/code_samples/ai_actions/src/AI/Handler/WhisperAudioToTextActionHandler.php @@ -15,7 +15,7 @@ final class WhisperAudioToTextActionHandler implements ActionHandlerInterface { - private const TIMESTAMP_FORMAT = '/^\[\d{2}:\d{2}\.\d{3} --> \d{2}:\d{2}\.\d{3}]\s*/'; + private const string TIMESTAMP_FORMAT = '/^\[\d{2}:\d{2}\.\d{3} --> \d{2}:\d{2}\.\d{3}]\s*/'; public function supports(ActionInterface $action): bool { @@ -33,7 +33,7 @@ public function handle(ActionInterface $action, array $context = []): ActionResp $language = $action->getRuntimeContext()?->get('languageCode'); if ($language !== null) { - $arguments[] = sprintf('--language=%s', substr($language, 0, 2)); + $arguments[] = sprintf('--language=%s', substr((string) $language, 0, 2)); } $arguments[] = '--output_format=txt'; @@ -72,9 +72,7 @@ private function removeTimestamps(string $text): string { $lines = explode(PHP_EOL, $text); - $processedLines = array_map(static function (string $line): string { - return preg_replace(self::TIMESTAMP_FORMAT, '', $line) ?? ''; - }, $lines); + $processedLines = array_map(static fn (string $line): string => preg_replace(self::TIMESTAMP_FORMAT, '', $line) ?? '', $lines); return implode(PHP_EOL, $processedLines); } diff --git a/code_samples/ai_actions/src/AI/REST/Input/Parser/TranscribeAudio.php b/code_samples/ai_actions/src/AI/REST/Input/Parser/TranscribeAudio.php index 0951c9b732..78520a1e4e 100644 --- a/code_samples/ai_actions/src/AI/REST/Input/Parser/TranscribeAudio.php +++ b/code_samples/ai_actions/src/AI/REST/Input/Parser/TranscribeAudio.php @@ -13,8 +13,8 @@ final class TranscribeAudio extends BaseParser { - public const AUDIO_KEY = 'Audio'; - public const BASE64_KEY = 'base64'; + public const string AUDIO_KEY = 'Audio'; + public const string BASE64_KEY = 'base64'; /** @param array $data */ public function parse(array $data, ParsingDispatcher $parsingDispatcher): TranscribeAudioAction diff --git a/code_samples/ai_actions/src/AI/REST/Output/ValueObjectVisitor/AudioText.php b/code_samples/ai_actions/src/AI/REST/Output/ValueObjectVisitor/AudioText.php index 07b2240db0..1c8277f585 100644 --- a/code_samples/ai_actions/src/AI/REST/Output/ValueObjectVisitor/AudioText.php +++ b/code_samples/ai_actions/src/AI/REST/Output/ValueObjectVisitor/AudioText.php @@ -10,8 +10,11 @@ final class AudioText extends ValueObjectVisitor { - private const OBJECT_IDENTIFIER = 'AudioText'; + private const string OBJECT_IDENTIFIER = 'AudioText'; + /** + * @param \App\AI\REST\Value\AudioText $data + */ public function visit(Visitor $visitor, Generator $generator, $data): void { $mediaType = 'ai.' . self::OBJECT_IDENTIFIER; diff --git a/code_samples/ai_actions/src/AI/REST/Value/TranscribeAudioAction.php b/code_samples/ai_actions/src/AI/REST/Value/TranscribeAudioAction.php index 643b32867e..258381dab6 100644 --- a/code_samples/ai_actions/src/AI/REST/Value/TranscribeAudioAction.php +++ b/code_samples/ai_actions/src/AI/REST/Value/TranscribeAudioAction.php @@ -7,18 +7,10 @@ use App\AI\DataType\Audio; use Ibexa\Contracts\ConnectorAi\Action\RuntimeContext; -final class TranscribeAudioAction +final readonly class TranscribeAudioAction { - private Audio $input; - - private RuntimeContext $runtimeContext; - - public function __construct( - Audio $input, - RuntimeContext $runtimeContext - ) { - $this->input = $input; - $this->runtimeContext = $runtimeContext; + public function __construct(private Audio $input, private RuntimeContext $runtimeContext) + { } public function getInput(): Audio diff --git a/code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php b/code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php index cb7ce9bc29..59c0ae9772 100644 --- a/code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php +++ b/code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php @@ -13,51 +13,30 @@ use Ibexa\Contracts\Core\Collection\ArrayMap; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'app:action-configuration-create' )] -final class ActionConfigurationCreateCommand extends Command +final readonly class ActionConfigurationCreateCommand { - private ActionConfigurationServiceInterface $actionConfigurationService; - - private PermissionResolver $permissionResolver; - - private UserService $userService; - - private ActionServiceInterface $actionService; - - private ActionTypeRegistryInterface $actionTypeRegistry; - public function __construct( - ActionConfigurationServiceInterface $actionConfigurationService, - PermissionResolver $permissionResolver, - UserService $userService, - ActionServiceInterface $actionService, - ActionTypeRegistryInterface $actionTypeRegistry + private ActionConfigurationServiceInterface $actionConfigurationService, + private PermissionResolver $permissionResolver, + private UserService $userService, + private ActionServiceInterface $actionService, + private ActionTypeRegistryInterface $actionTypeRegistry ) { - $this->actionConfigurationService = $actionConfigurationService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - $this->actionService = $actionService; - $this->actionTypeRegistry = $actionTypeRegistry; - - parent::__construct(); - } - - protected function configure(): void - { - $this->addArgument('user', InputArgument::OPTIONAL, 'Login of the user executing the actions', 'admin'); } - protected function execute(InputInterface $input, OutputInterface $output): int - { - $user = $input->getArgument('user'); + public function __invoke( + #[Argument(name: 'user', description: 'Login of the user executing the actions')] string $user, + OutputInterface $output + ): int { + $user = $user; $this->permissionResolver->setCurrentUserReference($this->userService->loadUserByLogin($user)); $refineTextActionType = $this->actionTypeRegistry->getActionType('refine_text'); diff --git a/code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php b/code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php index 5084b61d4e..67084cc909 100644 --- a/code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php +++ b/code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php @@ -22,57 +22,33 @@ use Ibexa\Contracts\Core\Repository\Values\Filter\Filter; use Ibexa\Core\FieldType\Image\Value; use Ibexa\Core\IO\IOBinarydataHandler; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'app:add-alt-text', )] -final class AddMissingAltTextCommand extends Command +final readonly class AddMissingAltTextCommand { - private const IMAGE_FIELD_IDENTIFIER = 'image'; - - private ContentService $contentService; - - private PermissionResolver $permissionResolver; - - private UserService $userService; - - private FieldTypeService $fieldTypeService; - - private ActionServiceInterface $actionService; - - private IOBinarydataHandler $binaryDataHandler; + private const string IMAGE_FIELD_IDENTIFIER = 'image'; public function __construct( - ContentService $contentService, - PermissionResolver $permissionResolver, - UserService $userService, - FieldTypeService $fieldTypeService, - ActionServiceInterface $actionService, - IOBinarydataHandler $binaryDataHandler + private ContentService $contentService, + private PermissionResolver $permissionResolver, + private UserService $userService, + private FieldTypeService $fieldTypeService, + private ActionServiceInterface $actionService, + private IOBinarydataHandler $binaryDataHandler ) { - $this->contentService = $contentService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - $this->fieldTypeService = $fieldTypeService; - $this->actionService = $actionService; - $this->binaryDataHandler = $binaryDataHandler; - - parent::__construct(); } - protected function configure(): void - { - $this->addArgument('user', InputArgument::OPTIONAL, 'Login of the user executing the actions', 'admin'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $this->setUser($input->getArgument('user')); + public function __invoke( + #[Argument(name: 'user', description: 'Login of the user executing the actions')] string $user, + OutputInterface $output + ): int { + $this->setUser($user); $modifiedImages = $this->getModifiedImages(); $output->writeln(sprintf('Found %d modified image in the last 24h', $modifiedImages->getTotalCount())); diff --git a/code_samples/api/commerce/src/Command/CartCommand.php b/code_samples/api/commerce/src/Command/CartCommand.php index aedfb50589..b1d9b07f02 100644 --- a/code_samples/api/commerce/src/Command/CartCommand.php +++ b/code_samples/api/commerce/src/Command/CartCommand.php @@ -19,53 +19,26 @@ use Ibexa\Core\Repository\Permission\PermissionResolver; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:cart' )] -final class CartCommand extends Command +final readonly class CartCommand { - private PermissionResolver $permissionResolver; - - private UserService $userService; - - private CartServiceInterface $cartService; - - private CurrencyServiceInterface $currencyService; - - private ProductServiceInterface $productService; - - private OrderServiceInterface $orderService; - - private ReorderService $reorderService; - - private CartResolverInterface $cartResolver; - public function __construct( - PermissionResolver $permissionResolver, - UserService $userService, - CartServiceInterface $cartService, - CurrencyServiceInterface $currencyService, - ProductServiceInterface $productService, - OrderServiceInterface $orderService, - ReorderService $reorderService, - CartResolverInterface $cartResolver + private PermissionResolver $permissionResolver, + private UserService $userService, + private CartServiceInterface $cartService, + private CurrencyServiceInterface $currencyService, + private ProductServiceInterface $productService, + private OrderServiceInterface $orderService, + private ReorderService $reorderService, + private CartResolverInterface $cartResolver ) { - $this->cartService = $cartService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - $this->currencyService = $currencyService; - $this->productService = $productService; - $this->orderService = $orderService; - $this->reorderService = $reorderService; - $this->cartResolver = $cartResolver; - - parent::__construct(); } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $this->permissionResolver->setCurrentUserReference( $this->userService->loadUserByLogin('admin') @@ -117,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->cartService->emptyCart($cart); // Validate a cart - $violationList = $this->cartService->validateCart($cart); // Symfony\Component\Validator\ConstraintViolationListInterface + $violationList = $this->cartService->validateCart($cart); // Add product to a cart $product = $this->productService->getProduct('desk1'); @@ -163,6 +136,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Merge the carts into the target cart and delete the merged carts $reorderCart = $this->cartService->mergeCarts($reorderCart, true, $existingCart); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/commerce/src/Command/OrderCommand.php b/code_samples/api/commerce/src/Command/OrderCommand.php index 904ff231ee..dd572bbe77 100644 --- a/code_samples/api/commerce/src/Command/OrderCommand.php +++ b/code_samples/api/commerce/src/Command/OrderCommand.php @@ -23,37 +23,21 @@ use Money; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:order' )] -final class OrderCommand extends Command +final readonly class OrderCommand { - private PermissionResolver $permissionResolver; - - private UserService $userService; - - private OrderServiceInterface $orderService; - public function __construct( - PermissionResolver $permissionResolver, - UserService $userService, - OrderServiceInterface $orderService + private PermissionResolver $permissionResolver, + private UserService $userService, + private OrderServiceInterface $orderService ) { - $this->orderService = $orderService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - - parent::__construct(); - } - - public function configure(): void - { } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $currentUser = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($currentUser); @@ -128,6 +112,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln(sprintf('Found %d orders with provided criteria', count($orders))); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/commerce/src/Command/PaymentCommand.php b/code_samples/api/commerce/src/Command/PaymentCommand.php index d7f98eeb6e..fe824d1a9b 100644 --- a/code_samples/api/commerce/src/Command/PaymentCommand.php +++ b/code_samples/api/commerce/src/Command/PaymentCommand.php @@ -18,45 +18,23 @@ use Money; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:payment' )] -final class PaymentCommand extends Command +final readonly class PaymentCommand { - private PermissionResolver $permissionResolver; - - private UserService $userService; - - private PaymentServiceInterface $paymentService; - - private OrderServiceInterface $orderService; - - private PaymentMethodServiceInterface $paymentMethodService; - public function __construct( - PermissionResolver $permissionResolver, - UserService $userService, - PaymentServiceInterface $paymentService, - OrderServiceInterface $orderService, - PaymentMethodServiceInterface $paymentMethodService, + private PermissionResolver $permissionResolver, + private UserService $userService, + private PaymentServiceInterface $paymentService, + private OrderServiceInterface $orderService, + private PaymentMethodServiceInterface $paymentMethodService ) { - $this->paymentService = $paymentService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - $this->orderService = $orderService; - $this->paymentMethodService = $paymentMethodService; - - parent::__construct(); - } - - public function configure(): void - { } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $currentUser = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($currentUser); @@ -121,6 +99,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Delete existing payment permanently $this->paymentService->deletePayment($payment); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/commerce/src/Command/PaymentMethodCommand.php b/code_samples/api/commerce/src/Command/PaymentMethodCommand.php index 0d26d03de0..11d2488eb0 100644 --- a/code_samples/api/commerce/src/Command/PaymentMethodCommand.php +++ b/code_samples/api/commerce/src/Command/PaymentMethodCommand.php @@ -16,33 +16,21 @@ use Ibexa\Payment\Values\PaymentMethodType; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:paymentMethod' )] -final class PaymentMethodCommand extends Command +final readonly class PaymentMethodCommand { - private PermissionResolver $permissionResolver; - - private UserService $userService; - - private PaymentMethodServiceInterface $paymentMethodService; - public function __construct( - PermissionResolver $permissionResolver, - UserService $userService, - PaymentMethodServiceInterface $paymentMethodService + private PermissionResolver $permissionResolver, + private UserService $userService, + private PaymentMethodServiceInterface $paymentMethodService ) { - $this->paymentMethodService = $paymentMethodService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - - parent::__construct(); } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $currentUser = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($currentUser); @@ -125,6 +113,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int )); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/commerce/src/Command/ShipmentCommand.php b/code_samples/api/commerce/src/Command/ShipmentCommand.php index 35dbfe7dfc..3be9f1b815 100644 --- a/code_samples/api/commerce/src/Command/ShipmentCommand.php +++ b/code_samples/api/commerce/src/Command/ShipmentCommand.php @@ -19,41 +19,23 @@ use Money; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:shipment' )] -final class ShipmentCommand extends Command +final readonly class ShipmentCommand { - private PermissionResolver $permissionResolver; - - private UserService $userService; - - private ShipmentServiceInterface $shipmentService; - - private ShippingMethodServiceInterface $shippingMethodService; - - private OrderServiceInterface $orderService; - public function __construct( - PermissionResolver $permissionResolver, - UserService $userService, - ShipmentServiceInterface $shipmentService, - ShippingMethodServiceInterface $shippingMethodService, - OrderServiceInterface $orderService + private PermissionResolver $permissionResolver, + private UserService $userService, + private ShipmentServiceInterface $shipmentService, + private ShippingMethodServiceInterface $shippingMethodService, + private OrderServiceInterface $orderService ) { - $this->shipmentService = $shipmentService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - $this->shippingMethodService = $shippingMethodService; - $this->orderService = $orderService; - - parent::__construct(); } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $currentUser = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($currentUser); @@ -134,6 +116,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int // Delete existing shipment permanently $this->shipmentService->deleteShipment($shipment); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/commerce/src/Command/ShippingMethodCommand.php b/code_samples/api/commerce/src/Command/ShippingMethodCommand.php index 23f25286f9..cd8290b85d 100644 --- a/code_samples/api/commerce/src/Command/ShippingMethodCommand.php +++ b/code_samples/api/commerce/src/Command/ShippingMethodCommand.php @@ -15,37 +15,22 @@ use Ibexa\Shipping\Value\ShippingMethodType; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:shippingMethod' )] -final class ShippingMethodCommand extends Command +final readonly class ShippingMethodCommand { - private PermissionResolver $permissionResolver; - - private UserService $userService; - - private ShippingMethodServiceInterface $shippingMethodService; - - private RegionServiceInterface $regionService; - public function __construct( - PermissionResolver $permissionResolver, - UserService $userService, - ShippingMethodServiceInterface $shippingMethodService, - RegionServiceInterface $regionService + private PermissionResolver $permissionResolver, + private UserService $userService, + private ShippingMethodServiceInterface $shippingMethodService, + private RegionServiceInterface $regionService ) { - $this->shippingMethodService = $shippingMethodService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - $this->regionService = $regionService; - - parent::__construct(); } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $currentUser = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($currentUser); @@ -154,6 +139,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $languageCode )); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/commerce/src/Controller/CustomCheckoutController.php b/code_samples/api/commerce/src/Controller/CustomCheckoutController.php index 79ec15a75c..622c615697 100644 --- a/code_samples/api/commerce/src/Controller/CustomCheckoutController.php +++ b/code_samples/api/commerce/src/Controller/CustomCheckoutController.php @@ -11,14 +11,8 @@ class CustomCheckoutController extends Controller { - private CartServiceInterface $cartService; - - private CheckoutServiceInterface $checkoutService; - - public function __construct(CartServiceInterface $cartService, CheckoutServiceInterface $checkoutService) + public function __construct(private readonly CartServiceInterface $cartService, private readonly CheckoutServiceInterface $checkoutService) { - $this->cartService = $cartService; - $this->checkoutService = $checkoutService; } public function showContentAction(): Response diff --git a/code_samples/api/migration/src/Command/MigrationCommand.php b/code_samples/api/migration/src/Command/MigrationCommand.php index 862170007a..93beb87116 100644 --- a/code_samples/api/migration/src/Command/MigrationCommand.php +++ b/code_samples/api/migration/src/Command/MigrationCommand.php @@ -6,24 +6,18 @@ use Ibexa\Migration\Repository\Migration; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:migration' )] -final class MigrationCommand extends Command +final readonly class MigrationCommand { - private MigrationService $migrationService; - - public function __construct(MigrationService $migrationService) + public function __construct(private MigrationService $migrationService) { - $this->migrationService = $migrationService; - - parent::__construct(); } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $string_with_migration_content = ''; $this->migrationService->add( @@ -43,6 +37,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->migrationService->executeOne($my_migration); $this->migrationService->executeAll('admin'); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/product_catalog/src/Command/AttributeCommand.php b/code_samples/api/product_catalog/src/Command/AttributeCommand.php index 609238328d..51246b511b 100644 --- a/code_samples/api/product_catalog/src/Command/AttributeCommand.php +++ b/code_samples/api/product_catalog/src/Command/AttributeCommand.php @@ -11,53 +11,25 @@ use Ibexa\Contracts\ProductCatalog\Local\LocalAttributeGroupServiceInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:attributes' )] -final class AttributeCommand extends Command +final readonly class AttributeCommand { - private AttributeGroupServiceInterface $attributeGroupService; - - private LocalAttributeGroupServiceInterface $localAttributeGroupService; - - private AttributeDefinitionServiceInterface $attributeDefinitionService; - - private LocalAttributeDefinitionServiceInterface $localAttributeDefinitionService; - - private AttributeTypeServiceInterface $attributeTypeService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - public function __construct( - LocalAttributeDefinitionServiceInterface $localAttributeDefinitionService, - AttributeDefinitionServiceInterface $attributeDefinitionService, - AttributeGroupServiceInterface $attributeGroupService, - LocalAttributeGroupServiceInterface $localAttributeGroupService, - AttributeTypeServiceInterface $attributeTypeService, - UserService $userService, - PermissionResolver $permissionResolver + private LocalAttributeDefinitionServiceInterface $localAttributeDefinitionService, + private AttributeDefinitionServiceInterface $attributeDefinitionService, + private AttributeGroupServiceInterface $attributeGroupService, + private LocalAttributeGroupServiceInterface $localAttributeGroupService, + private AttributeTypeServiceInterface $attributeTypeService, + private UserService $userService, + private PermissionResolver $permissionResolver ) { - $this->localAttributeGroupService = $localAttributeGroupService; - $this->attributeGroupService = $attributeGroupService; - $this->attributeTypeService = $attributeTypeService; - $this->attributeDefinitionService = $attributeDefinitionService; - $this->localAttributeDefinitionService = $localAttributeDefinitionService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - public function configure(): void - { } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); @@ -100,6 +72,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Attribute group ' . $attributeGroup->getIdentifier() . ' with name ' . $attributeGroup->getName()); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/product_catalog/src/Command/CatalogCommand.php b/code_samples/api/product_catalog/src/Command/CatalogCommand.php index 800aa3deae..ae2563a6ac 100644 --- a/code_samples/api/product_catalog/src/Command/CatalogCommand.php +++ b/code_samples/api/product_catalog/src/Command/CatalogCommand.php @@ -13,54 +13,31 @@ use Ibexa\Contracts\ProductCatalog\Values\Product\ProductQuery; use Ibexa\Contracts\ProductCatalog\Values\Product\Query\Criterion; use Ibexa\ProductCatalog\Local\Repository\Values\Catalog\Status; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:catalog' )] -final class CatalogCommand extends Command +final readonly class CatalogCommand { - private UserService $userService; - - private PermissionResolver $permissionResolver; - - private ProductServiceInterface $productService; - - private CatalogServiceInterface $catalogService; - public function __construct( - UserService $userService, - PermissionResolver $permissionResolver, - ProductServiceInterface $productService, - CatalogServiceInterface $catalogService + private UserService $userService, + private PermissionResolver $permissionResolver, + private ProductServiceInterface $productService, + private CatalogServiceInterface $catalogService ) { - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - $this->productService = $productService; - $this->catalogService = $catalogService; - - parent::__construct(); - } - - public function configure(): void - { - $this - ->setDefinition([ - new InputArgument('catalogIdentifier', InputArgument::REQUIRED, 'Catalog identifier'), - ]); } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Catalog identifier')] string $catalogIdentifier + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $catalogIdentifier = $input->getArgument('catalogIdentifier'); - // Create catalog $catalogCriterion = new Criterion\LogicalAnd( [ @@ -96,6 +73,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->catalogService->updateCatalog($catalog, $catalogUpdateStruct); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/product_catalog/src/Command/CurrencyCommand.php b/code_samples/api/product_catalog/src/Command/CurrencyCommand.php index 04f11d6d49..56a9ba4b47 100644 --- a/code_samples/api/product_catalog/src/Command/CurrencyCommand.php +++ b/code_samples/api/product_catalog/src/Command/CurrencyCommand.php @@ -7,49 +7,31 @@ use Ibexa\Contracts\ProductCatalog\CurrencyServiceInterface; use Ibexa\Contracts\ProductCatalog\Values\Currency\CurrencyCreateStruct; use Ibexa\Contracts\ProductCatalog\Values\Currency\CurrencyUpdateStruct; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:currency' )] -final class CurrencyCommand extends Command +final readonly class CurrencyCommand { - private CurrencyServiceInterface $currencyService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(CurrencyServiceInterface $currencyService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->currencyService = $currencyService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); + public function __construct( + private CurrencyServiceInterface $currencyService, + private UserService $userService, + private PermissionResolver $permissionResolver + ) { } - public function configure(): void - { - $this - ->setDefinition([ - new InputArgument('currencyCode', InputArgument::REQUIRED, 'Currency code'), - new InputArgument('newCurrencyCode', InputArgument::REQUIRED, 'New currency code'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Currency code')] string $currencyCode, + #[Argument(description: 'New currency code')] string $newCurrencyCode + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $currencyCode = $input->getArgument('currencyCode'); - $newCurrencyCode = $input->getArgument('newCurrencyCode'); - $currency = $this->currencyService->getCurrencyByCode($currencyCode); $output->writeln('Currency ID: ' . $currency->getId()); @@ -65,10 +47,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->currencyService->updateCurrency($currency, $currencyUpdateStruct); + assert($newCurrencyCode !== '', 'Currency code cannot be empty'); $currencyCreateStruct = new CurrencyCreateStruct($newCurrencyCode, 2, true); $this->currencyService->createCurrency($currencyCreateStruct); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/product_catalog/src/Command/ProductAssetCommand.php b/code_samples/api/product_catalog/src/Command/ProductAssetCommand.php index 7d67874e29..4c888b81f0 100644 --- a/code_samples/api/product_catalog/src/Command/ProductAssetCommand.php +++ b/code_samples/api/product_catalog/src/Command/ProductAssetCommand.php @@ -8,53 +8,31 @@ use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Contracts\ProductCatalog\AssetServiceInterface; use Ibexa\Contracts\ProductCatalog\ProductServiceInterface; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:assets' )] -final class ProductAssetCommand extends Command +final readonly class ProductAssetCommand { - private UserService $userService; - - private PermissionResolver $permissionResolver; - - private ProductServiceInterface $productService; - - private AssetServiceInterface $assetService; - public function __construct( - UserService $userService, - PermissionResolver $permissionResolver, - ProductServiceInterface $productService, - AssetServiceInterface $assetService + private UserService $userService, + private PermissionResolver $permissionResolver, + private ProductServiceInterface $productService, + private AssetServiceInterface $assetService ) { - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - $this->productService = $productService; - $this->assetService = $assetService; - - parent::__construct(); - } - - public function configure(): void - { - $this - ->setDefinition([ - new InputArgument('productCode', InputArgument::REQUIRED, 'Product code'), - ]); } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Product code')] string $productCode + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $productCode = $input->getArgument('productCode'); $product = $this->productService->getProduct($productCode); $singleAsset = $this->assetService->getAsset($product, '1'); @@ -70,6 +48,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/product_catalog/src/Command/ProductCommand.php b/code_samples/api/product_catalog/src/Command/ProductCommand.php index d58a537f89..99f0c6d6ea 100644 --- a/code_samples/api/product_catalog/src/Command/ProductCommand.php +++ b/code_samples/api/product_catalog/src/Command/ProductCommand.php @@ -13,64 +13,34 @@ use Ibexa\Contracts\ProductCatalog\Values\Product\ProductQuery; use Ibexa\Contracts\ProductCatalog\Values\Product\Query\Criterion; use Ibexa\Contracts\ProductCatalog\Values\Product\Query\SortClause; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:product' )] -final class ProductCommand extends Command +final readonly class ProductCommand { - private UserService $userService; - - private PermissionResolver $permissionResolver; - - private ProductTypeServiceInterface $productTypeService; - - private ProductServiceInterface $productService; - - private LocalProductServiceInterface $localProductService; - - private ProductAvailabilityServiceInterface $productAvailabilityService; - public function __construct( - UserService $userService, - PermissionResolver $permissionResolver, - ProductTypeServiceInterface $productTypeService, - ProductServiceInterface $productService, - LocalProductServiceInterface $localProductService, - ProductAvailabilityServiceInterface $productAvailabilityService + private UserService $userService, + private PermissionResolver $permissionResolver, + private ProductTypeServiceInterface $productTypeService, + private ProductServiceInterface $productService, + private LocalProductServiceInterface $localProductService, + private ProductAvailabilityServiceInterface $productAvailabilityService ) { - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - $this->productService = $productService; - $this->productTypeService = $productTypeService; - $this->localProductService = $localProductService; - $this->productAvailabilityService = $productAvailabilityService; - - parent::__construct(); - } - - public function configure(): void - { - $this - ->setDefinition([ - new InputArgument('productCode', InputArgument::REQUIRED, 'Product code'), - new InputArgument('productType', InputArgument::REQUIRED, 'Product type'), - ]); } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Product code')] string $productCode, + #[Argument(description: 'Product type')] string $productType + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $productCode = $input->getArgument('productCode'); - $productType = $input->getArgument('productType'); - $product = $this->productService->getProduct($productCode); $output->writeln('Product with code ' . $product->getCode() . ' is ' . $product->getName()); @@ -125,6 +95,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->localProductService->deleteProduct($product); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/product_catalog/src/Command/ProductPriceCommand.php b/code_samples/api/product_catalog/src/Command/ProductPriceCommand.php index ce874bfe77..b71a3e106a 100644 --- a/code_samples/api/product_catalog/src/Command/ProductPriceCommand.php +++ b/code_samples/api/product_catalog/src/Command/ProductPriceCommand.php @@ -16,65 +16,36 @@ use Ibexa\Contracts\ProductCatalog\Values\Price\Query\Criterion\LogicalOr; use Ibexa\Contracts\ProductCatalog\Values\Price\Query\Criterion\Product; use Money; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:price' )] -final class ProductPriceCommand extends Command +final readonly class ProductPriceCommand { - private ProductPriceServiceInterface $productPriceService; - - private PriceResolverInterface $priceResolver; - - private ProductServiceInterface $productService; - - private CurrencyServiceInterface $currencyService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - public function __construct( - CurrencyServiceInterface $currencyService, - ProductServiceInterface $productService, - ProductPriceServiceInterface $productPriceService, - PriceResolverInterface $priceResolver, - UserService $userService, - PermissionResolver $permissionResolver + private CurrencyServiceInterface $currencyService, + private ProductServiceInterface $productService, + private ProductPriceServiceInterface $productPriceService, + private PriceResolverInterface $priceResolver, + private UserService $userService, + private PermissionResolver $permissionResolver ) { - $this->currencyService = $currencyService; - $this->productPriceService = $productPriceService; - $this->priceResolver = $priceResolver; - $this->productService = $productService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - public function configure(): void - { - $this - ->setDefinition([ - new InputArgument('productCode', InputArgument::REQUIRED, 'Product code'), - new InputArgument('currencyCode', InputArgument::REQUIRED, 'Currency code'), - new InputArgument('newCurrencyCode', InputArgument::REQUIRED, 'New currency code'), - ]); } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Product code')] string $productCode, + #[Argument(description: 'Currency code')] string $currencyCode, + #[Argument(description: 'New currency code')] string $newCurrencyCode + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $productCode = $input->getArgument('productCode'); $product = $this->productService->getProduct($productCode); - $currencyCode = $input->getArgument('currencyCode'); $currency = $this->currencyService->getCurrencyByCode($currencyCode); $productPrice = $product->getPrice(); @@ -85,9 +56,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Price for ' . $product->getName() . ' in ' . $currencyCode . ' is ' . $productPrice); - $newCurrencyCode = $input->getArgument('newCurrencyCode'); $newCurrency = $this->currencyService->getCurrencyByCode($newCurrencyCode); + assert($newCurrencyCode !== '', 'Currency code cannot be empty'); $money = new Money\Money(50000, new Money\Currency($newCurrencyCode)); $priceCreateStruct = new ProductPriceCreateStruct($product, $newCurrency, $money, null, null); @@ -118,6 +89,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Price in ' . $currency->getCode() . ' for ' . $product->getName() . ' is ' . $price); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/product_catalog/src/Command/ProductTypeCommand.php b/code_samples/api/product_catalog/src/Command/ProductTypeCommand.php index 71af92cf14..32d711316a 100644 --- a/code_samples/api/product_catalog/src/Command/ProductTypeCommand.php +++ b/code_samples/api/product_catalog/src/Command/ProductTypeCommand.php @@ -5,47 +5,30 @@ use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Contracts\ProductCatalog\ProductTypeServiceInterface; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:product_type' )] -final class ProductTypeCommand extends Command +final readonly class ProductTypeCommand { - private UserService $userService; - - private PermissionResolver $permissionResolver; - - private ProductTypeServiceInterface $productTypeService; - - public function __construct(UserService $userService, PermissionResolver $permissionResolver, ProductTypeServiceInterface $productTypeService) - { - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - $this->productTypeService = $productTypeService; - - parent::__construct(); + public function __construct( + private UserService $userService, + private PermissionResolver $permissionResolver, + private ProductTypeServiceInterface $productTypeService + ) { } - public function configure(): void - { - $this - ->setDefinition([ - new InputArgument('productTypeIdentifier', InputArgument::REQUIRED, 'Product type identifier'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Product type identifier')] string $productTypeIdentifier + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $productTypeIdentifier = $input->getArgument('productTypeIdentifier'); - $productType = $this->productTypeService->getProductType($productTypeIdentifier); $output->writeln($productType->getName()); @@ -56,6 +39,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($productType->getName() . ' with identifier ' . $productType->getIdentifier()); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/product_catalog/src/Command/ProductVariantCommand.php b/code_samples/api/product_catalog/src/Command/ProductVariantCommand.php index 6d7bcf789a..29c1d74893 100644 --- a/code_samples/api/product_catalog/src/Command/ProductVariantCommand.php +++ b/code_samples/api/product_catalog/src/Command/ProductVariantCommand.php @@ -10,53 +10,31 @@ use Ibexa\Contracts\ProductCatalog\Local\Values\Product\ProductVariantCreateStruct; use Ibexa\Contracts\ProductCatalog\ProductServiceInterface; use Ibexa\Contracts\ProductCatalog\Values\Product\ProductVariantQuery; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:product_variant' )] -final class ProductVariantCommand extends Command +final readonly class ProductVariantCommand { - private UserService $userService; - - private PermissionResolver $permissionResolver; - - private ProductServiceInterface $productService; - - private LocalProductServiceInterface $localProductService; - public function __construct( - UserService $userService, - PermissionResolver $permissionResolver, - ProductServiceInterface $productService, - LocalProductServiceInterface $localProductService + private UserService $userService, + private PermissionResolver $permissionResolver, + private ProductServiceInterface $productService, + private LocalProductServiceInterface $localProductService ) { - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - $this->productService = $productService; - $this->localProductService = $localProductService; - - parent::__construct(); - } - - public function configure(): void - { - $this - ->setDefinition([ - new InputArgument('productCode', InputArgument::REQUIRED, 'Product code'), - ]); } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Product code')] string $productCode + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $productCode = $input->getArgument('productCode'); $product = $this->productService->getProduct($productCode); // Get variants @@ -80,6 +58,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->localProductService->createProductVariants($product, $variantCreateStructs); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/product_catalog/src/Command/VatCommand.php b/code_samples/api/product_catalog/src/Command/VatCommand.php index 8cd7bd265b..91c57e3a88 100644 --- a/code_samples/api/product_catalog/src/Command/VatCommand.php +++ b/code_samples/api/product_catalog/src/Command/VatCommand.php @@ -6,49 +6,28 @@ use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Contracts\ProductCatalog\RegionServiceInterface; use Ibexa\Contracts\ProductCatalog\VatServiceInterface; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:vat' )] -final class VatCommand extends Command +final readonly class VatCommand { - private UserService $userService; - - private PermissionResolver $permissionResolver; - - private VatServiceInterface $vatService; - - private RegionServiceInterface $regionService; - public function __construct( - UserService $userService, - PermissionResolver $permissionResolver, - VatServiceInterface $vatService, - RegionServiceInterface $regionService + private UserService $userService, + private PermissionResolver $permissionResolver, + private VatServiceInterface $vatService, + private RegionServiceInterface $regionService ) { - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - $this->vatService = $vatService; - $this->regionService = $regionService; - - parent::__construct(); - } - - public function configure(): void - { - $this - ->setDefinition([ - new InputArgument('productCode', InputArgument::REQUIRED, 'Product code'), - ]); } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Product code')] string $productCode + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); @@ -64,6 +43,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln((string) $vatCategory->getVatValue()); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/AddLanguageCommand.php b/code_samples/api/public_php_api/src/Command/AddLanguageCommand.php index 3025e68e4f..7056518e23 100644 --- a/code_samples/api/public_php_api/src/Command/AddLanguageCommand.php +++ b/code_samples/api/public_php_api/src/Command/AddLanguageCommand.php @@ -7,35 +7,22 @@ use Ibexa\Contracts\Core\Repository\UserService; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:add_language' + name: 'doc:add_language', + description: 'Lists available languages and add Polish.' )] -class AddLanguageCommand extends Command +class AddLanguageCommand { - private LanguageService $languageService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(LanguageService $languageService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->languageService = $languageService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - protected function configure(): void - { - $this->setDescription('Lists available languages and add Polish.'); + public function __construct( + private readonly LanguageService $languageService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); @@ -52,6 +39,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->languageService->createLanguage($languageCreateStruct); $output->writeln('Added language Polish with language code pol-PL.'); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php b/code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php index 6d7d99c498..87e1c8b3db 100644 --- a/code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php +++ b/code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php @@ -6,53 +6,33 @@ use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:add_location' + name: 'doc:add_location', + description: 'Add a Location to content item and hides it.' )] -class AddLocationToContentCommand extends Command +class AddLocationToContentCommand { - private ContentService $contentService; - - private LocationService $locationService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(ContentService $contentService, LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->contentService = $contentService; - $this->locationService = $locationService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDescription('Add a Location to content item and hides it.') - ->setDefinition([ - new InputArgument('contentId', InputArgument::REQUIRED, 'Content ID'), - new InputArgument('parentLocationId', InputArgument::REQUIRED, 'Parent Location ID'), - ]); + public function __construct( + private readonly ContentService $contentService, + private readonly LocationService $locationService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'Content ID')] int $contentId, + #[Argument(description: 'Parent Location ID')] int $parentLocationId, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $parentLocationId = (int) $input->getArgument('parentLocationId'); - $contentId = (int) $input->getArgument('contentId'); - $locationCreateStruct = $this->locationService->newLocationCreateStruct($parentLocationId); $locationCreateStruct->priority = 500; @@ -63,6 +43,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Added hidden location ' . $newLocation->id . ' to content item: ' . $contentInfo->name); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/BookmarkCommand.php b/code_samples/api/public_php_api/src/Command/BookmarkCommand.php index 072185599a..0125349799 100644 --- a/code_samples/api/public_php_api/src/Command/BookmarkCommand.php +++ b/code_samples/api/public_php_api/src/Command/BookmarkCommand.php @@ -4,42 +4,26 @@ use Ibexa\Contracts\Core\Repository\BookmarkService; use Ibexa\Contracts\Core\Repository\LocationService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:bookmark' )] -class BookmarkCommand extends Command +class BookmarkCommand { - private BookmarkService $bookmarkService; - - private LocationService $locationService; - - public function __construct(BookmarkService $bookmarkService, LocationService $locationService) + public function __construct(private readonly BookmarkService $bookmarkService, private readonly LocationService $locationService) { - $this->bookmarkService = $bookmarkService; - $this->locationService = $locationService; - - parent::__construct(); } - protected function configure(): void - { - $this - ->setDefinition([ - new InputArgument('locationId', InputArgument::REQUIRED, 'Location id'), - ]) - ->addOption('delete', 'd', InputOption::VALUE_NONE, 'Delete the created bookmark?', null); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $locationId = (int) $input->getArgument('locationId'); + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Location id')] int $locationId, + #[Option(shortcut: 'd', description: 'Delete the created bookmark?')] bool $delete = false + ): int { $location = $this->locationService->loadLocation($locationId); $this->bookmarkService->createBookmark($location); @@ -54,11 +38,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($bookmark->getContentInfo()->name); } - if ($input->getOption('delete')) { + if ($delete) { $this->bookmarkService->deleteBookmark($location); $output->writeln('Deleted bookmark from ' . $location->getContentInfo()->name); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/BrowseLocationsCommand.php b/code_samples/api/public_php_api/src/Command/BrowseLocationsCommand.php index b3a39049a3..aa67a998ad 100644 --- a/code_samples/api/public_php_api/src/Command/BrowseLocationsCommand.php +++ b/code_samples/api/public_php_api/src/Command/BrowseLocationsCommand.php @@ -4,33 +4,19 @@ use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\Values\Content\Location; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:browse_locations' + name: 'doc:browse_locations', + description: 'Lists all descendants of the Location' )] -class BrowseLocationsCommand extends Command +class BrowseLocationsCommand { - private LocationService $locationService; - - public function __construct(LocationService $locationService) + public function __construct(private readonly LocationService $locationService) { - $this->locationService = $locationService; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDescription('Lists all descendants of the Location') - ->setDefinition([ - new InputArgument('locationId', InputArgument::REQUIRED, 'Location ID to browse from'), - ]); } private function browseLocation(Location $location, OutputInterface $output, int $depth = 0): void @@ -43,13 +29,13 @@ private function browseLocation(Location $location, OutputInterface $output, int } } - protected function execute(InputInterface $input, OutputInterface $output): int - { - $locationId = (int) $input->getArgument('locationId'); - + public function __invoke( + #[Argument(description: 'Location ID to browse from')] int $locationId, + OutputInterface $output + ): int { $location = $this->locationService->loadLocation($locationId); $this->browseLocation($location, $output); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/CalendarCommand.php b/code_samples/api/public_php_api/src/Command/CalendarCommand.php index ea46cf7088..92623424cb 100644 --- a/code_samples/api/public_php_api/src/Command/CalendarCommand.php +++ b/code_samples/api/public_php_api/src/Command/CalendarCommand.php @@ -9,35 +9,22 @@ use Ibexa\Scheduler\Calendar\EventAction\RescheduleEventActionContext; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:calendar' + name: 'doc:calendar', + description: 'Lists Calendar event in the provided time range and reschedules them.' )] -class CalendarCommand extends Command +class CalendarCommand { - private PermissionResolver $permissionResolver; - - private UserService $userService; - - private CalendarServiceInterface $calendarService; - - public function __construct(PermissionResolver $permissionResolver, UserService $userService, CalendarServiceInterface $calendarService) - { - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - $this->calendarService = $calendarService; - - parent::__construct(); - } - - public function configure(): void - { - $this->setDescription('Lists Calendar event in the provided time range and reschedules them.'); + public function __construct( + private readonly PermissionResolver $permissionResolver, + private readonly UserService $userService, + private readonly CalendarServiceInterface $calendarService + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); @@ -67,6 +54,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->calendarService->executeAction($context); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/CreateContentCommand.php b/code_samples/api/public_php_api/src/Command/CreateContentCommand.php index be1ca6db5a..cb31423c21 100644 --- a/code_samples/api/public_php_api/src/Command/CreateContentCommand.php +++ b/code_samples/api/public_php_api/src/Command/CreateContentCommand.php @@ -7,58 +7,37 @@ use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:create_content' )] -class CreateContentCommand extends Command +class CreateContentCommand { - private ContentService $contentService; - - private ContentTypeService $contentTypeService; - - private LocationService $locationService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(ContentService $contentService, ContentTypeService $contentTypeService, LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->contentService = $contentService; - $this->contentTypeService = $contentTypeService; - $this->locationService = $locationService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDefinition([ - new InputArgument('parentLocationId', InputArgument::REQUIRED, 'Parent Location ID'), - new InputArgument('contentType', InputArgument::REQUIRED, 'Identifier of a content type with a Name and Description Field'), - new InputArgument('name', InputArgument::REQUIRED, 'Content for the Name field'), - ]) - ->addOption('publish', 'p', InputOption::VALUE_NONE, 'Do you want to publish the content item?'); + public function __construct( + private readonly ContentService $contentService, + private readonly ContentTypeService $contentTypeService, + private readonly LocationService $locationService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Parent Location ID')] int $parentLocationId, + #[Argument(description: 'Identifier of a content type with a Name and Description Field')] string $contentType, + #[Argument(description: 'Content for the Name field')] string $name, + #[Option(shortcut: 'p', description: 'Do you want to publish the content item?')] bool $publish = true + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $parentLocationId = (int) $input->getArgument('parentLocationId'); - $contentTypeIdentifier = $input->getArgument('contentType'); - $name = $input->getArgument('name'); + $contentTypeIdentifier = $contentType; $contentType = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); $contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, 'eng-GB'); @@ -70,11 +49,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Created a draft of ' . $contentType->getName() . ' with name ' . $draft->getName()); - if ($input->getOption('publish')) { + if ($publish) { $content = $this->contentService->publishVersion($draft->versionInfo); $output->writeln('Published content item ' . $content->getName()); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php b/code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php index 7a86405849..5d529c8d08 100644 --- a/code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php +++ b/code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php @@ -6,60 +6,44 @@ use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:create_content_type' )] -class CreateContentTypeCommand extends Command +class CreateContentTypeCommand { - private ContentTypeService $contentTypeService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(ContentTypeService $contentTypeService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->contentTypeService = $contentTypeService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); + public function __construct( + private readonly ContentTypeService $contentTypeService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function configure(): void - { - $this->setDefinition([ - new InputArgument('identifier', InputArgument::REQUIRED, 'Content type identifier'), - new InputArgument('group_identifier', InputArgument::REQUIRED, 'Content type group identifier'), - new InputArgument('copy_identifier', InputArgument::OPTIONAL, 'Identifier of the CT copy'), - ]) - ->addOption('copy', 'c', InputOption::VALUE_NONE, 'Do you want to make a copy of the content type?'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Content type identifier')] string $identifier, + #[Argument(description: 'Content type group identifier')] string $group_identifier, + #[Argument(description: 'Identifier of the CT copy')] ?string $copy_identifier, + #[Option(shortcut: 'c', description: 'Do you want to make a copy of the content type?')] bool $copy = false + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $groupIdentifier = $input->getArgument('group_identifier'); - $contentTypeIdentifier = $input->getArgument('identifier'); - if ($input->getArgument('copy_identifier')) { - $copyIdentifier = $input->getArgument('copy_identifier'); - } + $groupIdentifier = $group_identifier; + $contentTypeIdentifier = $identifier; + $copyIdentifier = $copy_identifier; try { $contentTypeGroup = $this->contentTypeService->loadContentTypeGroupByIdentifier($groupIdentifier); - } catch (NotFoundException $e) { + } catch (NotFoundException) { $output->writeln("Content type group with identifier $groupIdentifier not found"); - return self::FAILURE; + return Command::FAILURE; } $contentTypeCreateStruct = $this->contentTypeService->newContentTypeCreateStruct($contentTypeIdentifier); @@ -89,19 +73,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->contentTypeService->publishContentTypeDraft($contentTypeDraft); $output->writeln("Content type '$contentTypeIdentifier' with ID $contentTypeDraft->id created"); - if ($input->getOption('copy')) { + if ($copy) { $contentTypeToCopy = $this->contentTypeService->loadContentTypeByIdentifier($contentTypeIdentifier); $copy = $this->contentTypeService->copyContentType($contentTypeToCopy); $copyDraft = $this->contentTypeService->createContentTypeDraft($copy); $copyUpdateStruct = $this->contentTypeService->newContentTypeUpdateStruct(); $copyUpdateStruct->identifier = $copyIdentifier; - $copyUpdateStruct->names = ['eng-GB' => $copyIdentifier]; + $copyUpdateStruct->names = ['eng-GB' => $copyIdentifier ?? $contentTypeIdentifier . '_copy']; $this->contentTypeService->updateContentTypeDraft($copyDraft, $copyUpdateStruct); $this->contentTypeService->publishContentTypeDraft($copyDraft); $output->writeln('Copy of the new CT created with identifier ' . $copyIdentifier); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/CreateImageCommand.php b/code_samples/api/public_php_api/src/Command/CreateImageCommand.php index 5aae67c0ef..fead0ab88b 100644 --- a/code_samples/api/public_php_api/src/Command/CreateImageCommand.php +++ b/code_samples/api/public_php_api/src/Command/CreateImageCommand.php @@ -8,58 +8,35 @@ use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Core\FieldType\Image\Value; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:create_image' )] -class CreateImageCommand extends Command +class CreateImageCommand { - private ContentService $contentService; - - private ContentTypeService $contentTypeService; - - private LocationService $locationService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(ContentService $contentService, ContentTypeService $contentTypeService, LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->contentService = $contentService; - $this->contentTypeService = $contentTypeService; - $this->locationService = $locationService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDefinition([ - new InputArgument('name', InputArgument::REQUIRED, 'Content for the Name field'), - new InputArgument('file', InputArgument::REQUIRED, 'Content for the Image field'), - ]) - ->addOption('publish', 'p', InputOption::VALUE_NONE, 'Do you want to publish the content item?'); + public function __construct( + private readonly ContentService $contentService, + private readonly ContentTypeService $contentTypeService, + private readonly LocationService $locationService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Content for the Name field')] string $name, + #[Argument(description: 'Content for the Image field')] string $file, + #[Option(shortcut: 'p', description: 'Do you want to publish the content item?')] bool $publish = true + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $name = $input->getArgument('name'); - $file = $input->getArgument('file'); - $publish = $input->getOption('publish'); - $contentType = $this->contentTypeService->loadContentTypeByIdentifier('image'); $contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, 'eng-GB'); $contentCreateStruct->setField('name', $name); @@ -67,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int [ 'path' => $file, 'fileSize' => filesize($file), - 'fileName' => basename($file), + 'fileName' => basename((string) $file), 'alternativeText' => $name, ] ); @@ -79,11 +56,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Created a draft of ' . $contentType->getName() . ' with name ' . $draft->getName()); - if ($publish == true) { + if ($publish) { $content = $this->contentService->publishVersion($draft->versionInfo); $output->writeln('Published content item ' . $content->getName()); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/DeleteContentCommand.php b/code_samples/api/public_php_api/src/Command/DeleteContentCommand.php index 7aa74ffd89..e497d59131 100644 --- a/code_samples/api/public_php_api/src/Command/DeleteContentCommand.php +++ b/code_samples/api/public_php_api/src/Command/DeleteContentCommand.php @@ -5,52 +5,36 @@ use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:delete_content' )] -class DeleteContentCommand extends Command +class DeleteContentCommand { - private LocationService $locationService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->locationService = $locationService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); + public function __construct( + private readonly LocationService $locationService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function configure(): void - { - $this->setDefinition([ - new InputArgument('locationId', InputArgument::REQUIRED, 'Location to delete'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'Location to delete')] int $locationId, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $locationId = (int) $input->getArgument('locationId'); - $location = $this->locationService->loadLocation($locationId); $this->locationService->deleteLocation($location); $output->writeln('Location ' . $locationId . ' deleted.'); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/FilterCommand.php b/code_samples/api/public_php_api/src/Command/FilterCommand.php index c4f6b26515..e1962f5590 100644 --- a/code_samples/api/public_php_api/src/Command/FilterCommand.php +++ b/code_samples/api/public_php_api/src/Command/FilterCommand.php @@ -7,38 +7,25 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause; use Ibexa\Contracts\Core\Repository\Values\Filter\Filter; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:filter' + name: 'doc:filter', + description: 'Returns children of the provided Location, sorted by name in descending order.' )] -class FilterCommand extends Command +class FilterCommand { - private ContentService $contentService; - - public function __construct(ContentService $contentService) + public function __construct(private readonly ContentService $contentService) { - $this->contentService = $contentService; - - parent::__construct(); } - public function configure(): void - { - $this->setDescription('Returns children of the provided Location, sorted by name in descending order.'); - $this->setDefinition([ - new InputArgument('parentLocationId', InputArgument::REQUIRED, 'ID of the parent Location'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $parentLocationId = (int)$input->getArgument('parentLocationId'); - + public function __invoke( + #[Argument(description: 'ID of the parent Location')] int $parentLocationId, + OutputInterface $output + ): int { $filter = new Filter(); $filter ->withCriterion(new Criterion\ParentLocationId($parentLocationId)) @@ -52,6 +39,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($content->getName() ?? 'No content name'); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/FilterLocationCommand.php b/code_samples/api/public_php_api/src/Command/FilterLocationCommand.php index e7f68046fa..11a0691306 100644 --- a/code_samples/api/public_php_api/src/Command/FilterLocationCommand.php +++ b/code_samples/api/public_php_api/src/Command/FilterLocationCommand.php @@ -7,38 +7,25 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause; use Ibexa\Contracts\Core\Repository\Values\Filter\Filter; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:filter_location' + name: 'doc:filter_location', + description: 'Returns children of the provided Location, sorted by name in descending order.' )] -class FilterLocationCommand extends Command +class FilterLocationCommand { - private LocationService $locationService; - - public function __construct(LocationService $locationService) + public function __construct(private readonly LocationService $locationService) { - $this->locationService = $locationService; - - parent::__construct(); } - public function configure(): void - { - $this->setDescription('Returns children of the provided Location, sorted by name in descending order.'); - $this->setDefinition([ - new InputArgument('parentLocationId', InputArgument::REQUIRED, 'ID of the parent Location'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $parentLocationId = (int)$input->getArgument('parentLocationId'); - + public function __invoke( + #[Argument(description: 'ID of the parent Location')] int $parentLocationId, + OutputInterface $output + ): int { $filter = new Filter(); $filter ->withCriterion(new Criterion\ParentLocationId($parentLocationId)) @@ -52,6 +39,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($content->getContent()->getName()); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/FindComplexCommand.php b/code_samples/api/public_php_api/src/Command/FindComplexCommand.php index fdf2d72cb1..5040f4e47a 100644 --- a/code_samples/api/public_php_api/src/Command/FindComplexCommand.php +++ b/code_samples/api/public_php_api/src/Command/FindComplexCommand.php @@ -7,46 +7,27 @@ use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; use Ibexa\Contracts\Core\Repository\Values\Content\Query\SortClause; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:find_complex' + name: 'doc:find_complex', + description: 'Lists content belonging to the provided content type.' )] -class FindComplexCommand extends Command +class FindComplexCommand { - private SearchService $searchService; - - private LocationService $locationService; - - public function __construct(SearchService $searchService, LocationService $locationService) - { - $this->searchService = $searchService; - $this->locationService = $locationService; - - parent::__construct(); - } - - protected function configure(): void + public function __construct(private readonly SearchService $searchService, private readonly LocationService $locationService) { - $this - ->setDescription('Lists content belonging to the provided content type.') - ->setDefinition([ - new InputArgument('locationId', InputArgument::REQUIRED, ''), - new InputArgument('contentTypeIdentifier', InputArgument::REQUIRED, 'Content type identifier'), - new InputArgument('text', InputArgument::REQUIRED, ''), - ]); } - protected function execute(InputInterface $input, OutputInterface $output): int - { - $locationId = (int) $input->getArgument('locationId'); - $contentTypeIdentifier = $input->getArgument('contentTypeIdentifier'); - $text = $input->getArgument('text'); - + public function __invoke( + #[Argument(description: 'Location ID')] int $locationId, + #[Argument(description: 'Content type identifier')] string $contentTypeIdentifier, + #[Argument(description: 'Search text')] string $text, + OutputInterface $output + ): int { $query = new LocationQuery(); $query->query = new Criterion\LogicalAnd([ @@ -69,6 +50,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($searchHit->valueObject->name); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/FindContentCommand.php b/code_samples/api/public_php_api/src/Command/FindContentCommand.php index 881a10d87a..2663ea0247 100644 --- a/code_samples/api/public_php_api/src/Command/FindContentCommand.php +++ b/code_samples/api/public_php_api/src/Command/FindContentCommand.php @@ -5,39 +5,25 @@ use Ibexa\Contracts\Core\Repository\SearchService; use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:find_content' + name: 'doc:find_content', + description: 'Lists content belonging to the provided content type.' )] -class FindContentCommand extends Command +class FindContentCommand { - private SearchService $searchService; - - public function __construct(SearchService $searchService) + public function __construct(private readonly SearchService $searchService) { - $this->searchService = $searchService; - - parent::__construct(); } - protected function configure(): void - { - $this - ->setDescription('Lists content belonging to the provided content type.') - ->setDefinition([ - new InputArgument('contentTypeIdentifier', InputArgument::REQUIRED, 'Content type identifier'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $contentTypeIdentifier = $input->getArgument('contentTypeIdentifier'); - + public function __invoke( + #[Argument(description: 'Content type identifier')] string $contentTypeIdentifier, + OutputInterface $output + ): int { $query = new LocationQuery(); $query->filter = new Criterion\ContentTypeIdentifier($contentTypeIdentifier); @@ -48,6 +34,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($searchHit->valueObject->name); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/FindInTrashCommand.php b/code_samples/api/public_php_api/src/Command/FindInTrashCommand.php index 0910cf7a01..1c56f5a560 100644 --- a/code_samples/api/public_php_api/src/Command/FindInTrashCommand.php +++ b/code_samples/api/public_php_api/src/Command/FindInTrashCommand.php @@ -4,39 +4,25 @@ use Ibexa\Contracts\Core\Repository\TrashService; use Ibexa\Contracts\Core\Repository\Values\Content\Query; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:find_in_trash' + name: 'doc:find_in_trash', + description: 'Lists content in Trash belonging to the provided content type.' )] -class FindInTrashCommand extends Command +class FindInTrashCommand { - private TrashService $trashService; - - public function __construct(TrashService $trashService) + public function __construct(private readonly TrashService $trashService) { - $this->trashService = $trashService; - - parent::__construct(); } - protected function configure(): void - { - $this - ->setDescription('Lists content in Trash belonging to the provided content type.') - ->setDefinition([ - new InputArgument('contentTypeId', InputArgument::REQUIRED, 'Content type ID'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $contentTypeId = (int) $input->getArgument('contentTypeId'); - + public function __invoke( + #[Argument(description: 'Content type ID')] int $contentTypeId, + OutputInterface $output + ): int { $query = new Query(); $query->filter = new Query\Criterion\ContentTypeId($contentTypeId); @@ -45,6 +31,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($trashedLocation->getContentInfo()->name); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/FindUrlCommand.php b/code_samples/api/public_php_api/src/Command/FindUrlCommand.php index c5b1b13aa7..eea9ef6c98 100644 --- a/code_samples/api/public_php_api/src/Command/FindUrlCommand.php +++ b/code_samples/api/public_php_api/src/Command/FindUrlCommand.php @@ -10,36 +10,22 @@ use Ibexa\Contracts\Core\Repository\Values\URL\URLQuery; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:find_url' + name: 'doc:find_url', + description: 'Finds all valid URLs in the provided Section.' )] -class FindUrlCommand extends Command +class FindUrlCommand { - private URLService $urlService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(URLService $URLService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->urlService = $URLService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDescription('Finds all valid URLs in the provided Section.'); + public function __construct( + private readonly URLService $urlService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); @@ -64,6 +50,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($result->url); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php b/code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php index b8de4edf94..6ba660146d 100644 --- a/code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php +++ b/code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php @@ -9,30 +9,19 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:find_with_aggregation' + name: 'doc:find_with_aggregation', + description: 'Counts content per content type and the value of Selection Field.' )] -class FindWithAggregationCommand extends Command +class FindWithAggregationCommand { - private SearchService $searchService; - - public function __construct(SearchService $searchService) - { - $this->searchService = $searchService; - - parent::__construct(); - } - - protected function configure(): void + public function __construct(private readonly SearchService $searchService) { - $this - ->setDescription('Counts content per content type and the value of Selection Field.'); } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $query = new LocationQuery(); $query->query = new Criterion\ParentLocationId(2); @@ -57,6 +46,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($selection . ': ' . $count); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php b/code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php index 2f05b2c9b9..8d3e51914b 100644 --- a/code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php +++ b/code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php @@ -8,33 +8,22 @@ use Ibexa\Contracts\FormBuilder\FormSubmission\FormSubmissionServiceInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:form-submission' )] -final class FormSubmissionCommand extends Command +final readonly class FormSubmissionCommand { - private UserService $userService; - - private PermissionResolver $permissionResolver; - - private FormSubmissionServiceInterface $formSubmissionService; - - private ContentService $contentService; - - public function __construct(UserService $userService, PermissionResolver $permissionResolver, FormSubmissionServiceInterface $formSubmissionService, ContentService $contentService) - { - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - $this->formSubmissionService = $formSubmissionService; - $this->contentService = $contentService; - - parent::__construct(); + public function __construct( + private UserService $userService, + private PermissionResolver $permissionResolver, + private FormSubmissionServiceInterface $formSubmissionService, + private ContentService $contentService + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); @@ -71,6 +60,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $submission = $this->formSubmissionService->loadById(29); $this->formSubmissionService->delete($submission); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/HideLocationCommand.php b/code_samples/api/public_php_api/src/Command/HideLocationCommand.php index 86ba8dc96a..433a235c1a 100644 --- a/code_samples/api/public_php_api/src/Command/HideLocationCommand.php +++ b/code_samples/api/public_php_api/src/Command/HideLocationCommand.php @@ -5,47 +5,32 @@ use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:hide' + name: 'doc:hide', + description: 'Hides and reveals again selected Location.' )] -class HideLocationCommand extends Command +class HideLocationCommand { - private LocationService $locationService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->locationService = $locationService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDescription('Hides and reveals again selected Location.') - ->setDefinition([ - new InputArgument('location_id', InputArgument::REQUIRED, 'Location ID'), - ]); + public function __construct( + private readonly LocationService $locationService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'Location ID')] int $location_id, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $locationId = (int) $input->getArgument('location_id'); + $locationId = $location_id; $location = $this->locationService->loadLocation($locationId); @@ -55,6 +40,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->locationService->unhideLocation($location); $output->writeln('Location revealed: ' . $locationId); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/MoveContentCommand.php b/code_samples/api/public_php_api/src/Command/MoveContentCommand.php index 12b9f3e95f..2e3dc81b2a 100644 --- a/code_samples/api/public_php_api/src/Command/MoveContentCommand.php +++ b/code_samples/api/public_php_api/src/Command/MoveContentCommand.php @@ -5,55 +5,37 @@ use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:move_content' + name: 'doc:move_content', + description: 'Moves the selected Location with its subtree.' )] -class MoveContentCommand extends Command +class MoveContentCommand { - private LocationService $locationService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(LocationService $locationService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->locationService = $locationService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); + public function __construct( + private readonly LocationService $locationService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function configure(): void - { - $this - ->setDescription('Moves the selected Location with its subtree.') - ->setDefinition([ - new InputArgument('locationId', InputArgument::REQUIRED, 'Location to copy'), - new InputArgument('targetLocationId', InputArgument::REQUIRED, 'Target to copy or move to'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'Location to copy')] int $locationId, + #[Argument(description: 'Target to copy or move to')] int $targetLocationId, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $locationId = (int) $input->getArgument('locationId'); - $targetLocationId = (int) $input->getArgument('targetLocationId'); - $sourceLocation = $this->locationService->loadLocation($locationId); $targetLocation = $this->locationService->loadLocation($targetLocationId); $this->locationService->moveSubtree($sourceLocation, $targetLocation); $output->writeln('Location ' . $locationId . ' moved to ' . $targetLocationId . ' with its subtree.'); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/ObjectStateCommand.php b/code_samples/api/public_php_api/src/Command/ObjectStateCommand.php index a7da6a3ffc..2dda18c2ca 100644 --- a/code_samples/api/public_php_api/src/Command/ObjectStateCommand.php +++ b/code_samples/api/public_php_api/src/Command/ObjectStateCommand.php @@ -6,48 +6,31 @@ use Ibexa\Contracts\Core\Repository\ObjectStateService; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:object_state' + name: 'doc:object_state', + description: 'Creates OS group with provided States and assigned the Lock OS to provided content item' )] -class ObjectStateCommand extends Command +class ObjectStateCommand { - private ContentService $contentService; - - private UserService $userService; - - private ObjectStateService $objectStateService; - - private PermissionResolver $permissionResolver; - - public function __construct(ContentService $contentService, UserService $userService, ObjectStateService $objectStateService, PermissionResolver $permissionResolver) - { - $this->contentService = $contentService; - $this->userService = $userService; - $this->objectStateService = $objectStateService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDescription('Creates OS group with provided States and assigned the Lock OS to provided content item') - ->setDefinition([ - new InputArgument('objectStateGroupIdentifier', InputArgument::REQUIRED, 'Identifier of new OG group to create'), - new InputArgument('objectStateIdentifier', InputArgument::REQUIRED, 'Identifier(s) of a new Object State'), - new InputArgument('contentID', InputArgument::OPTIONAL, 'Content ID'), - ]); + public function __construct( + private readonly ContentService $contentService, + private readonly UserService $userService, + private readonly ObjectStateService $objectStateService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'Identifier of new OG group to create')] string $objectStateGroupIdentifier, + #[Argument(description: 'Identifier(s) of a new Object State')] string $objectStateIdentifier, + #[Argument(description: 'Content ID')] ?int $contentID, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); @@ -57,8 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($objectStateGroup->getName()); $output->writeln($objectState->getName()); - $objectStateGroupIdentifier = $input->getArgument('objectStateGroupIdentifier'); - $objectStateIdentifierList = explode(',', $input->getArgument('objectStateIdentifier')); + $objectStateIdentifierList = explode(',', (string) $objectStateIdentifier); $objectStateGroupStruct = $this->objectStateService->newObjectStateGroupCreateStruct($objectStateGroupIdentifier); $objectStateGroupStruct->defaultLanguageCode = 'eng-GB'; @@ -77,8 +59,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('* ' . $objectState->getName()); } - if ($input->getArgument('contentID')) { - $contentId = (int) $input->getArgument('contentID'); + if ($contentID) { + $contentId = $contentID; $objectStateToAssign = $objectStateIdentifierList[0]; $contentInfo = $this->contentService->loadContentInfo($contentId); $objectStateGroup = $this->objectStateService->loadObjectStateGroupByIdentifier($objectStateGroupIdentifier); @@ -88,6 +70,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Content ' . $contentInfo->name . ' assigned state ' . $objectState->getName()); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/SectionCommand.php b/code_samples/api/public_php_api/src/Command/SectionCommand.php index 1f06cf1152..313129d9da 100644 --- a/code_samples/api/public_php_api/src/Command/SectionCommand.php +++ b/code_samples/api/public_php_api/src/Command/SectionCommand.php @@ -9,58 +9,35 @@ use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Contracts\Core\Repository\Values\Content\LocationQuery; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:section' + name: 'doc:section', + description: 'Creates new section and adds selected content item to it.' )] -class SectionCommand extends Command +class SectionCommand { - private SectionService $sectionService; - - private UserService $userService; - - private SearchService $searchService; - - private ContentService $contentService; - - private PermissionResolver $permissionResolver; - - public function __construct(SectionService $sectionService, UserService $userService, ContentService $contentService, SearchService $searchService, PermissionResolver $permissionResolver) - { - $this->sectionService = $sectionService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - $this->searchService = $searchService; - $this->contentService = $contentService; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDescription('Creates new section and adds selected content item to it.') - ->setDefinition([ - new InputArgument('sectionName', InputArgument::REQUIRED, 'Name of the new Section'), - new InputArgument('sectionIdentifier', InputArgument::REQUIRED, 'Identifier of the new Section'), - new InputArgument('contentId', InputArgument::REQUIRED, 'Content id'), - ]); + public function __construct( + private readonly SectionService $sectionService, + private readonly UserService $userService, + private readonly ContentService $contentService, + private readonly SearchService $searchService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'Name of the new Section')] string $sectionName, + #[Argument(description: 'Identifier of the new Section')] string $sectionIdentifier, + #[Argument(description: 'Content id')] int $contentId, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $sectionName = $input->getArgument('sectionName'); - $sectionIdentifier = $input->getArgument('sectionIdentifier'); - $contentId = (int) $input->getArgument('contentId'); - $sectionCreateStruct = $this->sectionService->newSectionCreateStruct(); $sectionCreateStruct->name = $sectionName; $sectionCreateStruct->identifier = $sectionIdentifier; @@ -90,6 +67,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('* ' . $searchResult->valueObject->name); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/SegmentCommand.php b/code_samples/api/public_php_api/src/Command/SegmentCommand.php index 84d29650fb..eab191596a 100644 --- a/code_samples/api/public_php_api/src/Command/SegmentCommand.php +++ b/code_samples/api/public_php_api/src/Command/SegmentCommand.php @@ -9,34 +9,21 @@ use Ibexa\Segmentation\Value\SegmentGroupCreateStruct; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:segment' )] -class SegmentCommand extends Command +class SegmentCommand { - private SegmentationService $segmentationService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(SegmentationService $segmentationService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->segmentationService = $segmentationService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - - parent::__construct(); - } - - protected function configure(): void - { + public function __construct( + private readonly SegmentationService $segmentationService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); @@ -75,6 +62,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int : 'The user is not assigned to the segment.' )); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/SetMainLocationCommand.php b/code_samples/api/public_php_api/src/Command/SetMainLocationCommand.php index 1d75a60d5d..b24206e287 100644 --- a/code_samples/api/public_php_api/src/Command/SetMainLocationCommand.php +++ b/code_samples/api/public_php_api/src/Command/SetMainLocationCommand.php @@ -5,50 +5,32 @@ use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:set_main_location' + name: 'doc:set_main_location', + description: 'Set a Location as content item\'s main' )] -class SetMainLocationCommand extends Command +class SetMainLocationCommand { - private ContentService $contentService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(ContentService $contentService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->contentService = $contentService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); + public function __construct( + private readonly ContentService $contentService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function configure(): void - { - $this - ->setDescription('Set a Location as content item\'s main') - ->setDefinition([ - new InputArgument('contentId', InputArgument::REQUIRED, 'The Content ID'), - new InputArgument('locationId', InputArgument::REQUIRED, 'One of the Locations of the Content'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'The Content ID')] int $contentId, + #[Argument(description: 'One of the Locations of the Content')] int $locationId, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $contentId = (int) $input->getArgument('contentId'); - $locationId = (int) $input->getArgument('locationId'); - $contentInfo = $this->contentService->loadContentInfo($contentId); $contentUpdateStruct = $this->contentService->newContentMetadataUpdateStruct(); @@ -58,6 +40,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Location ' . $locationId . ' is now the main Location for ' . $contentInfo->name); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/TaxonomyCommand.php b/code_samples/api/public_php_api/src/Command/TaxonomyCommand.php index de0b0bb3b9..4b6f89ecb4 100644 --- a/code_samples/api/public_php_api/src/Command/TaxonomyCommand.php +++ b/code_samples/api/public_php_api/src/Command/TaxonomyCommand.php @@ -9,33 +9,21 @@ use Ibexa\Contracts\Taxonomy\Service\TaxonomyServiceInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:taxonomy' )] -class TaxonomyCommand extends Command +class TaxonomyCommand { - private TaxonomyServiceInterface $taxonomyService; - - private PermissionResolver $permissionResolver; - - private UserService $userService; - public function __construct( - TaxonomyServiceInterface $taxonomyService, - PermissionResolver $permissionResolver, - UserService $userService + private readonly TaxonomyServiceInterface $taxonomyService, + private readonly PermissionResolver $permissionResolver, + private readonly UserService $userService ) { - $this->taxonomyService = $taxonomyService; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - - parent::__construct(); } - public function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); @@ -61,6 +49,6 @@ public function execute(InputInterface $input, OutputInterface $output): int $sibling = $this->taxonomyService->loadEntryByIdentifier('school_desks'); $this->taxonomyService->moveEntryRelativeToSibling($entryToMove, $sibling, TaxonomyServiceInterface::MOVE_POSITION_PREV); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/TranslateContentCommand.php b/code_samples/api/public_php_api/src/Command/TranslateContentCommand.php index 0e33007661..74dff5d8cb 100644 --- a/code_samples/api/public_php_api/src/Command/TranslateContentCommand.php +++ b/code_samples/api/public_php_api/src/Command/TranslateContentCommand.php @@ -5,54 +5,35 @@ use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:translate_content' )] -class TranslateContentCommand extends Command +class TranslateContentCommand { - private ContentService $contentService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(ContentService $contentService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->contentService = $contentService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDefinition([ - new InputArgument('contentId', InputArgument::REQUIRED, 'ID of content to be updated'), - new InputArgument('language', InputArgument::REQUIRED, 'Language to add'), - new InputArgument('nameInNewLanguage', InputArgument::REQUIRED, 'Content name in new language'), - new InputArgument('secondaryLanguage', InputArgument::OPTIONAL, 'Secondary language to add'), - new InputArgument('nameInSecondaryLanguage', InputArgument::OPTIONAL, 'Content name in secondary language'), - ]); + public function __construct( + private readonly ContentService $contentService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'ID of content to be updated')] int $contentId, + #[Argument(description: 'Language to add')] string $language, + #[Argument(description: 'Content name in new language')] string $nameInNewLanguage, + #[Argument(description: 'Secondary language to add')] ?string $secondaryLanguage, + #[Argument(description: 'Content name in secondary language')] ?string $nameInSecondaryLanguage, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $contentId = (int) $input->getArgument('contentId'); - $language = $input->getArgument('language'); - $newName = $input->getArgument('nameInNewLanguage'); - $secondaryLanguage = $input->getArgument('secondaryLanguage'); - $nameInSecondaryLanguage = $input->getArgument('nameInSecondaryLanguage'); + $newName = $nameInNewLanguage; $contentInfo = $this->contentService->loadContentInfo($contentId); $contentDraft = $this->contentService->createContentDraft($contentInfo); @@ -69,6 +50,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->contentService->publishVersion($contentDraft->versionInfo); $output->writeln('Translated ' . $contentInfo->name . ' to ' . $language . ' as ' . $newName); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/TrashContentCommand.php b/code_samples/api/public_php_api/src/Command/TrashContentCommand.php index 88a799273b..b4976bcddd 100644 --- a/code_samples/api/public_php_api/src/Command/TrashContentCommand.php +++ b/code_samples/api/public_php_api/src/Command/TrashContentCommand.php @@ -6,62 +6,41 @@ use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\TrashService; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'doc:trash_content' )] -class TrashContentCommand extends Command +class TrashContentCommand { - private LocationService $locationService; - - private UserService $userService; - - private TrashService $trashService; - - private PermissionResolver $permissionResolver; - - public function __construct(LocationService $locationService, UserService $userService, TrashService $trashService, PermissionResolver $permissionResolver) - { - $this->locationService = $locationService; - $this->userService = $userService; - $this->trashService = $trashService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); + public function __construct( + private readonly LocationService $locationService, + private readonly UserService $userService, + private readonly TrashService $trashService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function configure(): void - { - $this->setDefinition([ - new InputArgument('locationId', InputArgument::REQUIRED, 'Location to trash'), - new InputArgument('newParentId', InputArgument::OPTIONAL, 'New Location to restore under'), - ]) - ->addOption('restore', 'r', InputOption::VALUE_NONE, 'Do you want to restore the content item?'); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Location to trash')] int $locationId, + #[Argument(description: 'New Location to restore under')] ?int $newParentId, + #[Option(shortcut: 'r', description: 'Do you want to restore the content item?')] bool $restore = false + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $locationId = (int) $input->getArgument('locationId'); - if ($input->getArgument('newParentId')) { - $newParentId = (int) $input->getArgument('newParentId'); - } - $location = $this->locationService->loadLocation($locationId); $this->trashService->trash($location); $output->writeln('Location ' . $locationId . ' moved to trash.'); - if ($input->getOption('restore')) { - if ($input->getArgument('newParentId')) { + if ($restore) { + if ($newParentId) { $newParent = $this->locationService->loadLocation($newParentId); } else { $newParent = null; @@ -71,6 +50,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Restored from trash.'); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/UpdateContentCommand.php b/code_samples/api/public_php_api/src/Command/UpdateContentCommand.php index 4bd45f5569..4932fb067b 100644 --- a/code_samples/api/public_php_api/src/Command/UpdateContentCommand.php +++ b/code_samples/api/public_php_api/src/Command/UpdateContentCommand.php @@ -5,50 +5,32 @@ use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:update_content' + name: 'doc:update_content', + description: 'Update provided content item with a new name' )] -class UpdateContentCommand extends Command +class UpdateContentCommand { - private ContentService $contentService; - - private UserService $userService; - - private PermissionResolver $permissionResolver; - - public function __construct(ContentService $contentService, UserService $userService, PermissionResolver $permissionResolver) - { - $this->contentService = $contentService; - $this->userService = $userService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); + public function __construct( + private readonly ContentService $contentService, + private readonly UserService $userService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function configure(): void - { - $this - ->setDescription('Update provided content item with a new name') - ->setDefinition([ - new InputArgument('contentId', InputArgument::REQUIRED, 'Content ID'), - new InputArgument('newName', InputArgument::REQUIRED, 'New name for the updated content item'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'Content ID')] int $contentId, + #[Argument(description: 'New name for the updated content item')] string $newName, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $contentId = (int) $input->getArgument('contentId'); - $newName = $input->getArgument('newName'); - $contentInfo = $this->contentService->loadContentInfo($contentId); $contentDraft = $this->contentService->createContentDraft($contentInfo); @@ -61,6 +43,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Content item ' . $contentId . ' updated with new name: ' . $newName); - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/ViewContentCommand.php b/code_samples/api/public_php_api/src/Command/ViewContentCommand.php index 02ca0536e3..eee9b2c3c0 100644 --- a/code_samples/api/public_php_api/src/Command/ViewContentCommand.php +++ b/code_samples/api/public_php_api/src/Command/ViewContentCommand.php @@ -5,45 +5,28 @@ use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\ContentTypeService; use Ibexa\Contracts\Core\Repository\FieldTypeService; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:view_content' + name: 'doc:view_content', + description: 'Output Field values on provided content item.' )] -class ViewContentCommand extends Command +class ViewContentCommand { - private ContentService $contentService; - - private ContentTypeService $contentTypeService; - - private FieldTypeService $fieldTypeService; - - public function __construct(ContentService $contentService, ContentTypeService $contentTypeService, FieldTypeService $fieldTypeService) - { - $this->contentService = $contentService; - $this->contentTypeService = $contentTypeService; - $this->fieldTypeService = $fieldTypeService; - - parent::__construct(); + public function __construct( + private readonly ContentService $contentService, + private readonly ContentTypeService $contentTypeService, + private readonly FieldTypeService $fieldTypeService + ) { } - protected function configure(): void - { - $this - ->setDescription('Output Field values on provided content item.') - ->setDefinition([ - new InputArgument('contentId', InputArgument::REQUIRED, 'Location ID'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - $contentId = (int) $input->getArgument('contentId'); - + public function __invoke( + #[Argument(description: 'Content ID')] int $contentId, + OutputInterface $output + ): int { $content = $this->contentService->loadContent($contentId); $contentType = $this->contentTypeService->loadContentType($content->contentInfo->contentTypeId); @@ -56,6 +39,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln($valueHash); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php index 35d37c56b8..c54435f572 100644 --- a/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php +++ b/code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php @@ -9,57 +9,34 @@ use Ibexa\Contracts\Core\Repository\URLAliasService; use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:view_metadata' + name: 'doc:view_metadata', + description: 'Output various metadata about a content item.' )] -class ViewContentMetaDataCommand extends Command +class ViewContentMetaDataCommand { - private ContentService $contentService; - - private LocationService $locationService; - - private URLAliasService $urlAliasService; - - private UserService $userService; - - private ObjectStateService $objectStateService; - - private PermissionResolver $permissionResolver; - - public function __construct(ContentService $contentService, LocationService $locationService, URLAliasService $urlAliasService, UserService $userService, ObjectStateService $objectStateService, PermissionResolver $permissionResolver) - { - $this->contentService = $contentService; - $this->locationService = $locationService; - $this->urlAliasService = $urlAliasService; - $this->userService = $userService; - $this->objectStateService = $objectStateService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); + public function __construct( + private readonly ContentService $contentService, + private readonly LocationService $locationService, + private readonly URLAliasService $urlAliasService, + private readonly UserService $userService, + private readonly ObjectStateService $objectStateService, + private readonly PermissionResolver $permissionResolver + ) { } - protected function configure(): void - { - $this - ->setDescription('Output various metadata about a content item.') - ->setDefinition([ - new InputArgument('contentId', InputArgument::REQUIRED, 'An existing content ID'), - ]); - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { + public function __invoke( + #[Argument(description: 'An existing content ID')] int $contentId, + OutputInterface $output + ): int { $user = $this->userService->loadUserByLogin('admin'); $this->permissionResolver->setCurrentUserReference($user); - $contentId = (int) $input->getArgument('contentId'); - // Metadata $contentInfo = $this->contentService->loadContentInfo($contentId); @@ -124,6 +101,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln("Object state: $state->identifier"); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Command/WorkflowCommand.php b/code_samples/api/public_php_api/src/Command/WorkflowCommand.php index 60cf29d89a..7c867a4c5e 100644 --- a/code_samples/api/public_php_api/src/Command/WorkflowCommand.php +++ b/code_samples/api/public_php_api/src/Command/WorkflowCommand.php @@ -5,48 +5,33 @@ use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Workflow\Registry\WorkflowRegistryInterface; use Ibexa\Contracts\Workflow\Service\WorkflowServiceInterface; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:workflow' + name: 'doc:workflow', + description: 'Starts content in the selected workflow and makes the provided transition.' )] -class WorkflowCommand extends Command +class WorkflowCommand { - private WorkflowServiceInterface $workflowService; - - private WorkflowRegistryInterface $workflowRegistry; - - private ContentService $contentService; - - public function __construct(WorkflowServiceInterface $workflowService, WorkflowRegistryInterface $workflowRegistry, ContentService $contentService) - { - $this->contentService = $contentService; - $this->workflowService = $workflowService; - $this->workflowRegistry = $workflowRegistry; - - parent::__construct(); - } - - protected function configure(): void - { - $this - ->setDescription('Starts content in the selected workflow and makes the provided transition.') - ->setDefinition([ - new InputArgument('contentId', InputArgument::REQUIRED, 'Content ID'), - new InputArgument('workflowName', InputArgument::REQUIRED, 'Workflow identifier'), - new InputArgument('transitionName', InputArgument::REQUIRED, 'Transition name'), - ]); + public function __construct( + private readonly WorkflowServiceInterface $workflowService, + private readonly WorkflowRegistryInterface $workflowRegistry, + private readonly ContentService $contentService + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int - { - $contentId = (int) $input->getArgument('contentId'); - $workflowName = $input->getArgument('workflowName'); - $transitionName = $input->getArgument('transitionName'); + public function __invoke( + OutputInterface $output, + #[Argument(description: 'Content ID')] int $contentId, + #[Argument(description: 'Workflow identifier')] string $workflowName, + #[Argument(description: 'Transition name')] string $transitionName + ): int { + $contentId = (int) $contentId; + $workflowName = $workflowName; + $transitionName = $transitionName; $content = $this->contentService->loadContent($contentId); @@ -68,6 +53,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int $output->writeln('Moved ' . $content->getName() . ' through transition ' . $transitionName); } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/api/public_php_api/src/Controller/CustomController.php b/code_samples/api/public_php_api/src/Controller/CustomController.php index 19e87da5ec..1f00f31571 100644 --- a/code_samples/api/public_php_api/src/Controller/CustomController.php +++ b/code_samples/api/public_php_api/src/Controller/CustomController.php @@ -10,11 +10,8 @@ class CustomController extends Controller { - private SearchService $searchService; - - public function __construct(SearchService $searchService) + public function __construct(private readonly SearchService $searchService) { - $this->searchService = $searchService; } public function showContentAction(int $locationId): Response diff --git a/code_samples/api/public_php_api/src/Controller/CustomFilterController.php b/code_samples/api/public_php_api/src/Controller/CustomFilterController.php index 7ec661c0cb..07c057262d 100644 --- a/code_samples/api/public_php_api/src/Controller/CustomFilterController.php +++ b/code_samples/api/public_php_api/src/Controller/CustomFilterController.php @@ -10,11 +10,8 @@ class CustomFilterController extends Controller { - private ContentService $contentService; - - public function __construct(ContentService $contentService) + public function __construct(private readonly ContentService $contentService) { - $this->contentService = $contentService; } public function showChildrenAction(ContentView $view): ContentView diff --git a/code_samples/api/public_php_api/src/Controller/PaginationController.php b/code_samples/api/public_php_api/src/Controller/PaginationController.php index cd468ae2be..ea6fad8694 100644 --- a/code_samples/api/public_php_api/src/Controller/PaginationController.php +++ b/code_samples/api/public_php_api/src/Controller/PaginationController.php @@ -13,11 +13,8 @@ class PaginationController extends Controller { - private SearchService $searchService; - - public function __construct(SearchService $searchService) + public function __construct(private readonly SearchService $searchService) { - $this->searchService = $searchService; } public function showContentAction(Request $request, int $locationId): Response diff --git a/code_samples/api/public_php_api/src/EventSubscriber/MyEventSubcriber.php b/code_samples/api/public_php_api/src/EventSubscriber/MyEventSubcriber.php index 8a82af15e9..6b6c76e671 100644 --- a/code_samples/api/public_php_api/src/EventSubscriber/MyEventSubcriber.php +++ b/code_samples/api/public_php_api/src/EventSubscriber/MyEventSubcriber.php @@ -7,7 +7,7 @@ class MyEventSubcriber implements EventSubscriberInterface { - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ CopyContentEvent::class => ['onCopyContent', 0], diff --git a/code_samples/api/rest_api/create_image.json.php b/code_samples/api/rest_api/create_image.json.php index 18f70d2f8b..501931004e 100644 --- a/code_samples/api/rest_api/create_image.json.php +++ b/code_samples/api/rest_api/create_image.json.php @@ -95,7 +95,7 @@ echo "\t{$responseArray['ErrorMessage']['errorDescription']}\n"; exit(4); } - } catch (HttpException\DecodingExceptionInterface $exception) { + } catch (HttpException\DecodingExceptionInterface) { } $responseHeaders = $response->getInfo('response_headers'); $error = $responseHeaders[0] ?? $responseCode; @@ -131,7 +131,7 @@ echo "\t{$responseArray['ErrorMessage']['errorDescription']}\n"; exit(8); } - } catch (HttpException\DecodingExceptionInterface $exception) { + } catch (HttpException\DecodingExceptionInterface) { } $responseHeaders = $response->getInfo('response_headers'); $error = $responseHeaders[0] ?? $responseCode; diff --git a/code_samples/api/rest_api/src/Rest/Output/ValueObjectVisitorDispatcher.php b/code_samples/api/rest_api/src/Rest/Output/ValueObjectVisitorDispatcher.php index 39782164fc..acd98ee6d6 100644 --- a/code_samples/api/rest_api/src/Rest/Output/ValueObjectVisitorDispatcher.php +++ b/code_samples/api/rest_api/src/Rest/Output/ValueObjectVisitorDispatcher.php @@ -10,19 +10,16 @@ class ValueObjectVisitorDispatcher // extends BaseValueObjectVisitorDispatcher T { private array $visitors; - private BaseValueObjectVisitorDispatcher $valueObjectVisitorDispatcher; - private Visitor $outputVisitor; private Generator $outputGenerator; - public function __construct(iterable $visitors, BaseValueObjectVisitorDispatcher $valueObjectVisitorDispatcher) + public function __construct(iterable $visitors, private readonly BaseValueObjectVisitorDispatcher $valueObjectVisitorDispatcher) { $this->visitors = []; foreach ($visitors as $type => $visitor) { $this->visitors[$type] = $visitor; } - $this->valueObjectVisitorDispatcher = $valueObjectVisitorDispatcher; } public function setOutputVisitor(Visitor $outputVisitor): void @@ -39,7 +36,7 @@ public function setOutputGenerator(Generator $outputGenerator): void public function visit($data) { - $className = get_class($data); + $className = $data::class; if (isset($this->visitors[$className])) { return $this->visitors[$className]->visit($this->outputVisitor, $this->outputGenerator, $data); } diff --git a/code_samples/api/rest_api/src/Rest/ValueObjectVisitor/Greeting.php b/code_samples/api/rest_api/src/Rest/ValueObjectVisitor/Greeting.php index f909993490..85b9dce847 100644 --- a/code_samples/api/rest_api/src/Rest/ValueObjectVisitor/Greeting.php +++ b/code_samples/api/rest_api/src/Rest/ValueObjectVisitor/Greeting.php @@ -8,6 +8,9 @@ class Greeting extends ValueObjectVisitor { + /** + * @param \App\Rest\Values\Greeting $data + */ public function visit(Visitor $visitor, Generator $generator, $data) { $visitor->setHeader('Content-Type', $generator->getMediaType('Greeting')); diff --git a/code_samples/api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php b/code_samples/api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php index 59dbf68fd0..fcc739e4ff 100644 --- a/code_samples/api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php +++ b/code_samples/api/rest_api/src/Rest/ValueObjectVisitor/RestLocation.php @@ -10,13 +10,11 @@ class RestLocation extends BaseRestLocation { - private URLAliasService $urlAliasService; - - public function __construct(URLAliasService $urlAliasService) + public function __construct(private readonly URLAliasService $urlAliasService) { - $this->urlAliasService = $urlAliasService; } + #[\Override] public function visit(Visitor $visitor, Generator $generator, $data): void { // Not using $generator->startObjectElement to not have the XML Generator adding its own media-type attribute with the default vendor diff --git a/code_samples/api/rest_api/src/Rest/Values/Greeting.php b/code_samples/api/rest_api/src/Rest/Values/Greeting.php index 3052899209..7b82ac48b7 100644 --- a/code_samples/api/rest_api/src/Rest/Values/Greeting.php +++ b/code_samples/api/rest_api/src/Rest/Values/Greeting.php @@ -4,13 +4,7 @@ class Greeting { - public string $salutation; - - public string $recipient; - - public function __construct(string $salutation = 'Hello', string $recipient = 'World') + public function __construct(public string $salutation = 'Hello', public string $recipient = 'World') { - $this->salutation = $salutation; - $this->recipient = $recipient; } } diff --git a/code_samples/back_office/calendar/src/Calendar/Holidays/EventSourceFactory.php b/code_samples/back_office/calendar/src/Calendar/Holidays/EventSourceFactory.php index b6136ff6dd..67478c33fd 100644 --- a/code_samples/back_office/calendar/src/Calendar/Holidays/EventSourceFactory.php +++ b/code_samples/back_office/calendar/src/Calendar/Holidays/EventSourceFactory.php @@ -4,17 +4,14 @@ use DateTime; use DateTimeInterface; -use Ibexa\Calendar\EventSource\InMemoryEventSource; use Ibexa\Contracts\Calendar\EventCollection; use Ibexa\Contracts\Calendar\EventSource\EventSourceInterface; +use Ibexa\Contracts\Calendar\EventSource\InMemoryEventSource; class EventSourceFactory { - private EventType $eventType; - - public function __construct(EventType $eventType) + public function __construct(private readonly EventType $eventType) { - $this->eventType = $eventType; } public function createEventSource(): EventSourceInterface diff --git a/code_samples/back_office/calendar/src/Calendar/Holidays/EventType.php b/code_samples/back_office/calendar/src/Calendar/Holidays/EventType.php index 12c0370980..dc6be1db5e 100644 --- a/code_samples/back_office/calendar/src/Calendar/Holidays/EventType.php +++ b/code_samples/back_office/calendar/src/Calendar/Holidays/EventType.php @@ -2,15 +2,15 @@ namespace App\Calendar\Holidays; -use Ibexa\Calendar\EventAction\EventActionCollection; use Ibexa\Contracts\Calendar\Event; +use Ibexa\Contracts\Calendar\EventAction\EventActionCollection; use Ibexa\Contracts\Calendar\EventType\EventTypeInterface; class EventType implements EventTypeInterface { - private const EVENT_TYPE_IDENTIFIER = 'holiday'; + private const string EVENT_TYPE_IDENTIFIER = 'holiday'; - private EventActionCollection $actions; + private readonly EventActionCollection $actions; public function __construct(iterable $actions) { diff --git a/code_samples/back_office/dashboard/article_tab/src/Tab/Dashboard/Everyone/EveryoneArticleTab.php b/code_samples/back_office/dashboard/article_tab/src/Tab/Dashboard/Everyone/EveryoneArticleTab.php index 7c373dae72..9a54be1d5c 100644 --- a/code_samples/back_office/dashboard/article_tab/src/Tab/Dashboard/Everyone/EveryoneArticleTab.php +++ b/code_samples/back_office/dashboard/article_tab/src/Tab/Dashboard/Everyone/EveryoneArticleTab.php @@ -16,20 +16,13 @@ class EveryoneArticleTab extends AbstractTab implements OrderedTabInterface { - protected PagerLocationToDataMapper $pagerLocationToDataMapper; - - protected SearchService $searchService; - public function __construct( Environment $twig, TranslatorInterface $translator, - PagerLocationToDataMapper $pagerLocationToDataMapper, - SearchService $searchService + protected PagerLocationToDataMapper $pagerLocationToDataMapper, + protected SearchService $searchService ) { parent::__construct($twig, $translator); - - $this->pagerLocationToDataMapper = $pagerLocationToDataMapper; - $this->searchService = $searchService; } public function getIdentifier(): string diff --git a/code_samples/back_office/dashboard/src/Command/DashboardCommand.php b/code_samples/back_office/dashboard/src/Command/DashboardCommand.php index 512441effc..4a35b42b38 100644 --- a/code_samples/back_office/dashboard/src/Command/DashboardCommand.php +++ b/code_samples/back_office/dashboard/src/Command/DashboardCommand.php @@ -8,51 +8,42 @@ use Ibexa\Contracts\Core\Repository\Repository; use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Contracts\Dashboard\DashboardServiceInterface; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'doc:dashboard' + name: 'doc:dashboard', + description: 'Set a custom dashboard to user group.' )] -class DashboardCommand extends Command +class DashboardCommand { - private DashboardServiceInterface $dashboardService; + private readonly Locationservice $locationService; - private Locationservice $locationService; + private readonly ContentService $contentService; - private ContentService $contentService; + private readonly UserService $userService; - private UserService $userService; - - private PermissionResolver $permissionResolver; + private readonly PermissionResolver $permissionResolver; public function __construct( - DashboardServiceInterface $dashboardService, + private readonly DashboardServiceInterface $dashboardService, Repository $repository ) { - $this->dashboardService = $dashboardService; $this->locationService = $repository->getLocationService(); $this->contentService = $repository->getContentService(); $this->userService = $repository->getUserService(); $this->permissionResolver = $repository->getPermissionResolver(); - - parent::__construct(); - } - - public function configure(): void - { - $this->setDescription('Set a custom dashboard to user group.') - ->addArgument('dashboard', InputArgument::REQUIRED, 'Location ID of the dashboard model') - ->addArgument('group', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'User Group Content ID(s)'); } - protected function execute(InputInterface $input, OutputInterface $output): int - { - $dashboardModelLocationId = (int)$input->getArgument('dashboard'); - $userGroupLocationIdList = array_map('intval', $input->getArgument('group')); + public function __invoke( + #[Argument(name: 'dashboard', description: 'Location ID of the dashboard model')] string $dashboard, + #[Argument(name: 'group', description: 'User Group Content ID(s)')] string $group, + OutputInterface $output + ): int { + $dashboardModelLocationId = (int)$dashboard; + $userGroupLocationIdList = array_map('intval', explode(',', $group)); foreach ($userGroupLocationIdList as $userGroupLocationId) { try { @@ -68,6 +59,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int } } - return self::SUCCESS; + return Command::SUCCESS; } } diff --git a/code_samples/back_office/images/src/SvgController.php b/code_samples/back_office/images/src/SvgController.php index b2ea7be6d1..3d44e5b33b 100644 --- a/code_samples/back_office/images/src/SvgController.php +++ b/code_samples/back_office/images/src/SvgController.php @@ -16,22 +16,13 @@ class SvgController extends Controller { - private const CONTENT_TYPE_HEADER = 'image/svg+xml'; - - private ContentService $contentService; - - private IOServiceInterface $ioService; - - private TranslationHelper $translationHelper; + private const string CONTENT_TYPE_HEADER = 'image/svg+xml'; public function __construct( - ContentService $contentService, - IOServiceInterface $ioService, - TranslationHelper $translationHelper + private readonly ContentService $contentService, + private readonly IOServiceInterface $ioService, + private readonly TranslationHelper $translationHelper ) { - $this->contentService = $contentService; - $this->ioService = $ioService; - $this->translationHelper = $translationHelper; } /** diff --git a/code_samples/back_office/images/src/SvgExtension.php b/code_samples/back_office/images/src/SvgExtension.php index 48ef14c583..173efcb5c3 100644 --- a/code_samples/back_office/images/src/SvgExtension.php +++ b/code_samples/back_office/images/src/SvgExtension.php @@ -6,33 +6,17 @@ use Symfony\Component\Routing\RouterInterface; use Twig\Extension\AbstractExtension; -use Twig\TwigFunction; class SvgExtension extends AbstractExtension { - protected RouterInterface $router; - /** * SvgExtension constructor. */ - public function __construct(RouterInterface $router) - { - $this->router = $router; - } - - /** - * @return \Twig\TwigFunction[] - */ - public function getFunctions(): array + public function __construct(protected RouterInterface $router) { - return [ - new TwigFunction('ibexa_svg_link', [ - $this, - 'generateLink', - ]), - ]; } + #[\Twig\Attribute\AsTwigFunction('ibexa_svg_link')] public function generateLink(int $contentId, string $fieldIdentifier, string $filename): string { return $this->router->generate('app.svg_download', [ diff --git a/code_samples/back_office/limitation/src/Security/Limitation/CustomLimitationType.php b/code_samples/back_office/limitation/src/Security/Limitation/CustomLimitationType.php index 06030e605a..42d3a1ca63 100644 --- a/code_samples/back_office/limitation/src/Security/Limitation/CustomLimitationType.php +++ b/code_samples/back_office/limitation/src/Security/Limitation/CustomLimitationType.php @@ -9,7 +9,6 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\CriterionInterface; use Ibexa\Contracts\Core\Repository\Values\User\Limitation; use Ibexa\Contracts\Core\Repository\Values\User\UserReference; -use Ibexa\Contracts\Core\Repository\Values\ValueObject; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\Base\Exceptions\InvalidArgumentType; use Ibexa\Core\FieldType\ValidationError; @@ -57,7 +56,7 @@ public function buildValue(array $limitationValues): CustomLimitationValue * * @return bool|null */ - public function evaluate(Limitation $value, UserReference $currentUser, ValueObject $object, array $targets = null): ?bool + public function evaluate(Limitation $value, UserReference $currentUser, object $object, array $targets = null): ?bool { if (!$value instanceof CustomLimitationValue) { throw new InvalidArgumentException('$value', 'Must be of type: CustomLimitationValue'); diff --git a/code_samples/back_office/menu/menu_item/src/Controller/AllContentListController.php b/code_samples/back_office/menu/menu_item/src/Controller/AllContentListController.php index 4feca732a4..787391a8d4 100644 --- a/code_samples/back_office/menu/menu_item/src/Controller/AllContentListController.php +++ b/code_samples/back_office/menu/menu_item/src/Controller/AllContentListController.php @@ -13,14 +13,8 @@ class AllContentListController extends Controller { - private SearchService $searchService; - - private FormFactory $formFactory; - - public function __construct(SearchService $searchService, FormFactory $formFactory) + public function __construct(private readonly SearchService $searchService, private readonly FormFactory $formFactory) { - $this->searchService = $searchService; - $this->formFactory = $formFactory; } public function listAction(int $page = 1): Response @@ -39,7 +33,7 @@ public function listAction(int $page = 1): Response return $this->render('@ibexadesign/all_content_list.html.twig', [ 'totalCount' => $paginator->getNbResults(), 'articles' => $paginator, - 'form_edit' => $editForm->createView(), + 'form_edit' => $editForm, ]); } } diff --git a/code_samples/back_office/menu/menu_item/src/EventSubscriber/MyMenuSubscriber.php b/code_samples/back_office/menu/menu_item/src/EventSubscriber/MyMenuSubscriber.php index 4b2d2e545a..be803e3d9d 100644 --- a/code_samples/back_office/menu/menu_item/src/EventSubscriber/MyMenuSubscriber.php +++ b/code_samples/back_office/menu/menu_item/src/EventSubscriber/MyMenuSubscriber.php @@ -8,7 +8,7 @@ class MyMenuSubscriber implements EventSubscriberInterface { - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ ConfigureMenuEvent::MAIN_MENU => ['onMainMenuConfigure', 0], diff --git a/code_samples/back_office/notifications/src/EventListener/ContentPublishEventListener.php b/code_samples/back_office/notifications/src/EventListener/ContentPublishEventListener.php index e89a5c7d81..c1447f80ba 100644 --- a/code_samples/back_office/notifications/src/EventListener/ContentPublishEventListener.php +++ b/code_samples/back_office/notifications/src/EventListener/ContentPublishEventListener.php @@ -7,16 +7,13 @@ use Ibexa\Contracts\Core\Repository\Values\Notification\CreateStruct; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -final class ContentPublishEventListener implements EventSubscriberInterface +final readonly class ContentPublishEventListener implements EventSubscriberInterface { - private NotificationService $notificationService; - - public function __construct(NotificationService $notificationService) + public function __construct(private NotificationService $notificationService) { - $this->notificationService = $notificationService; } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [PublishVersionEvent::class => 'onPublishVersion']; } diff --git a/code_samples/back_office/notifications/src/Notification/MyRenderer.php b/code_samples/back_office/notifications/src/Notification/MyRenderer.php index cb745cf6ab..fd8beebff6 100644 --- a/code_samples/back_office/notifications/src/Notification/MyRenderer.php +++ b/code_samples/back_office/notifications/src/Notification/MyRenderer.php @@ -11,14 +11,8 @@ class MyRenderer implements NotificationRenderer { - protected Environment $twig; - - protected RouterInterface $router; - - public function __construct(Environment $twig, RouterInterface $router) + public function __construct(protected Environment $twig, protected RouterInterface $router) { - $this->twig = $twig; - $this->router = $router; } public function render(Notification $notification): string diff --git a/code_samples/back_office/online_editor/src/event/subscriber/RichTextBlockSubscriber.php b/code_samples/back_office/online_editor/src/event/subscriber/RichTextBlockSubscriber.php index 6cc97a5edc..924e92ea45 100644 --- a/code_samples/back_office/online_editor/src/event/subscriber/RichTextBlockSubscriber.php +++ b/code_samples/back_office/online_editor/src/event/subscriber/RichTextBlockSubscriber.php @@ -12,15 +12,11 @@ class RichTextBlockSubscriber implements EventSubscriberInterface { - /** @var \Ibexa\FieldTypeRichText\RichText\DOMDocumentFactory */ - private $domDocumentFactory; - /** * @param \Ibexa\FieldTypeRichText\RichText\DOMDocumentFactory $domDocumentFactory */ - public function __construct(DOMDocumentFactory $domDocumentFactory) + public function __construct(private readonly DOMDocumentFactory $domDocumentFactory) { - $this->domDocumentFactory = $domDocumentFactory; } /** diff --git a/code_samples/back_office/search/src/EventSubscriber/MySuggestionEventSubscriber.php b/code_samples/back_office/search/src/EventSubscriber/MySuggestionEventSubscriber.php index 0304243c06..9fe69380df 100644 --- a/code_samples/back_office/search/src/EventSubscriber/MySuggestionEventSubscriber.php +++ b/code_samples/back_office/search/src/EventSubscriber/MySuggestionEventSubscriber.php @@ -15,12 +15,8 @@ class MySuggestionEventSubscriber implements EventSubscriberInterface, LoggerAwa { use LoggerAwareTrait; - private ProductServiceInterface $productService; - - public function __construct( - ProductServiceInterface $productService, - ) { - $this->productService = $productService; + public function __construct(private ProductServiceInterface $productService) + { } public static function getSubscribedEvents(): array @@ -36,14 +32,12 @@ public function onBuildSuggestionCollectionEvent(BuildSuggestionCollectionEvent $suggestionCollection = $event->getSuggestionCollection(); $text = $suggestionQuery->getQuery(); - $words = explode(' ', preg_replace('/\s+/', ' ', $text)); + $words = explode(' ', (string) preg_replace('/\s+/', ' ', $text)); $limit = $suggestionQuery->getLimit(); try { $productQuery = new ProductQuery(null, new Criterion\LogicalOr([ - new Criterion\ProductName(implode(' ', array_map(static function (string $word) { - return "$word*"; - }, $words))), + new Criterion\ProductName(implode(' ', array_map(static fn (string $word) => "$word*", $words))), new Criterion\ProductCode($words), new Criterion\ProductType($words), ]), [], 0, $limit); diff --git a/code_samples/back_office/search/src/Search/Model/Suggestion/ProductSuggestion.php b/code_samples/back_office/search/src/Search/Model/Suggestion/ProductSuggestion.php index a054e5550c..6e8be68e4d 100644 --- a/code_samples/back_office/search/src/Search/Model/Suggestion/ProductSuggestion.php +++ b/code_samples/back_office/search/src/Search/Model/Suggestion/ProductSuggestion.php @@ -7,7 +7,7 @@ class ProductSuggestion extends Suggestion { - private Product $product; + private readonly Product $product; public function __construct( float $score, diff --git a/code_samples/back_office/search/src/Search/SortingDefinition/Provider/SectionNameSortingDefinitionProvider.php b/code_samples/back_office/search/src/Search/SortingDefinition/Provider/SectionNameSortingDefinitionProvider.php index 04cdecaded..82db0c90ef 100644 --- a/code_samples/back_office/search/src/Search/SortingDefinition/Provider/SectionNameSortingDefinitionProvider.php +++ b/code_samples/back_office/search/src/Search/SortingDefinition/Provider/SectionNameSortingDefinitionProvider.php @@ -10,13 +10,10 @@ use JMS\TranslationBundle\Translation\TranslationContainerInterface; use Symfony\Contracts\Translation\TranslatorInterface; -final class SectionNameSortingDefinitionProvider implements SortingDefinitionProviderInterface, TranslationContainerInterface +final readonly class SectionNameSortingDefinitionProvider implements SortingDefinitionProviderInterface, TranslationContainerInterface { - private TranslatorInterface $translator; - - public function __construct(TranslatorInterface $translator) + public function __construct(private TranslatorInterface $translator) { - $this->translator = $translator; } public function getSortingDefinitions(): array diff --git a/code_samples/back_office/settings/src/Setting/Unit.php b/code_samples/back_office/settings/src/Setting/Unit.php index 4a4eeaabe9..dd524ccf85 100644 --- a/code_samples/back_office/settings/src/Setting/Unit.php +++ b/code_samples/back_office/settings/src/Setting/Unit.php @@ -25,17 +25,14 @@ public function getDescription(): string public function getDisplayValue(string $storageValue): string { - switch ($storageValue) { - case self::METRIC_OPTION: - return 'Metric'; - case self::IMPERIAL_OPTION: - return 'Imperial'; - default: - throw new InvalidArgumentException( - '$storageValue', - sprintf('There is no \'%s\' option', $storageValue) - ); - } + return match ($storageValue) { + self::METRIC_OPTION => 'Metric', + self::IMPERIAL_OPTION => 'Imperial', + default => throw new InvalidArgumentException( + '$storageValue', + sprintf('There is no \'%s\' option', $storageValue) + ), + }; } public function getDefaultValue(): string diff --git a/code_samples/back_office/thumbnails/src/Strategy/StaticThumbnailStrategy.php b/code_samples/back_office/thumbnails/src/Strategy/StaticThumbnailStrategy.php index 1cd431c64a..76cd57d9d4 100644 --- a/code_samples/back_office/thumbnails/src/Strategy/StaticThumbnailStrategy.php +++ b/code_samples/back_office/thumbnails/src/Strategy/StaticThumbnailStrategy.php @@ -9,14 +9,10 @@ use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; -final class StaticThumbnailStrategy implements ThumbnailStrategy +final readonly class StaticThumbnailStrategy implements ThumbnailStrategy { - /** @var string */ - private $staticThumbnail; - - public function __construct(string $staticThumbnail) + public function __construct(private string $staticThumbnail) { - $this->staticThumbnail = $staticThumbnail; } public function getThumbnail(ContentType $contentType, array $fields, ?VersionInfo $versionInfo = null): ?Thumbnail diff --git a/code_samples/customer_portal/src/Corporate/EventSubscriber/ApplicationDetailsViewSubscriber.php b/code_samples/customer_portal/src/Corporate/EventSubscriber/ApplicationDetailsViewSubscriber.php index 16c510d16d..a3aa625019 100644 --- a/code_samples/customer_portal/src/Corporate/EventSubscriber/ApplicationDetailsViewSubscriber.php +++ b/code_samples/customer_portal/src/Corporate/EventSubscriber/ApplicationDetailsViewSubscriber.php @@ -13,15 +13,11 @@ final class ApplicationDetailsViewSubscriber extends AbstractViewSubscriber { - private FormFactoryInterface $formFactory; - public function __construct( SiteAccessServiceInterface $siteAccessService, - FormFactoryInterface $formFactory + private readonly FormFactoryInterface $formFactory ) { parent::__construct($siteAccessService); - - $this->formFactory = $formFactory; } /** diff --git a/code_samples/customer_portal/src/Corporate/EventSubscriber/VerifyStateEventSubscriber.php b/code_samples/customer_portal/src/Corporate/EventSubscriber/VerifyStateEventSubscriber.php index 5091fbee10..54a85470e1 100644 --- a/code_samples/customer_portal/src/Corporate/EventSubscriber/VerifyStateEventSubscriber.php +++ b/code_samples/customer_portal/src/Corporate/EventSubscriber/VerifyStateEventSubscriber.php @@ -15,24 +15,15 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\Form\FormFactoryInterface; -final class VerifyStateEventSubscriber implements EventSubscriberInterface +final readonly class VerifyStateEventSubscriber implements EventSubscriberInterface { - private const VERIFY_STATE = 'verify'; - - private FormFactoryInterface $formFactory; - - private HandlerInterface $applicationStateHandler; - - private TranslatableNotificationHandlerInterface $notificationHandler; + private const string VERIFY_STATE = 'verify'; public function __construct( - FormFactoryInterface $formFactory, - HandlerInterface $applicationStateHandler, - TranslatableNotificationHandlerInterface $notificationHandler + private FormFactoryInterface $formFactory, + private HandlerInterface $applicationStateHandler, + private TranslatableNotificationHandlerInterface $notificationHandler ) { - $this->formFactory = $formFactory; - $this->applicationStateHandler = $applicationStateHandler; - $this->notificationHandler = $notificationHandler; } public static function getSubscribedEvents(): array diff --git a/code_samples/customer_portal/src/Form/VerifyType.php b/code_samples/customer_portal/src/Form/VerifyType.php index 95d4685134..0326c304ac 100644 --- a/code_samples/customer_portal/src/Form/VerifyType.php +++ b/code_samples/customer_portal/src/Form/VerifyType.php @@ -13,9 +13,9 @@ final class VerifyType extends AbstractType { - private const FIELD_APPLICATION = 'application'; - private const FIELD_NOTES = 'notes'; - private const FIELD_VERIFY = 'verify'; + private const string FIELD_APPLICATION = 'application'; + private const string FIELD_NOTES = 'notes'; + private const string FIELD_VERIFY = 'verify'; public function buildForm( FormBuilderInterface $builder, diff --git a/code_samples/data_migration/src/Migrations/Action/AssignSection.php b/code_samples/data_migration/src/Migrations/Action/AssignSection.php index 635658a5e4..876c51491a 100644 --- a/code_samples/data_migration/src/Migrations/Action/AssignSection.php +++ b/code_samples/data_migration/src/Migrations/Action/AssignSection.php @@ -6,16 +6,12 @@ use Ibexa\Migration\ValueObject\Step\Action; -final class AssignSection implements Action +final readonly class AssignSection implements Action { - public const TYPE = 'assign_section'; + public const string TYPE = 'assign_section'; - /** @var string */ - private $sectionIdentifier; - - public function __construct(string $sectionIdentifier) + public function __construct(private string $sectionIdentifier) { - $this->sectionIdentifier = $sectionIdentifier; } /** diff --git a/code_samples/data_migration/src/Migrations/Action/AssignSectionExecutor.php b/code_samples/data_migration/src/Migrations/Action/AssignSectionExecutor.php index 9a19f1ad17..d633c01cee 100644 --- a/code_samples/data_migration/src/Migrations/Action/AssignSectionExecutor.php +++ b/code_samples/data_migration/src/Migrations/Action/AssignSectionExecutor.php @@ -8,20 +8,10 @@ use Ibexa\Migration\StepExecutor\ActionExecutor\ExecutorInterface; use Ibexa\Migration\ValueObject; -final class AssignSectionExecutor implements ExecutorInterface +final readonly class AssignSectionExecutor implements ExecutorInterface { - /** @var \Ibexa\Contracts\Core\Repository\SectionService */ - private $sectionService; - - /** @var \Ibexa\Contracts\Core\Repository\ContentService */ - private $contentService; - - public function __construct( - ContentService $contentService, - SectionService $sectionService - ) { - $this->sectionService = $sectionService; - $this->contentService = $contentService; + public function __construct(private ContentService $contentService, private SectionService $sectionService) + { } /** diff --git a/code_samples/data_migration/src/Migrations/Step/ReplaceNameStep.php b/code_samples/data_migration/src/Migrations/Step/ReplaceNameStep.php index d846d1b083..64bbe53d68 100644 --- a/code_samples/data_migration/src/Migrations/Step/ReplaceNameStep.php +++ b/code_samples/data_migration/src/Migrations/Step/ReplaceNameStep.php @@ -6,7 +6,7 @@ use Ibexa\Migration\ValueObject\Step\StepInterface; -final class ReplaceNameStep implements StepInterface +final readonly class ReplaceNameStep implements StepInterface { private string $replacement; diff --git a/code_samples/data_migration/src/Migrations/Step/ReplaceNameStepExecutor.php b/code_samples/data_migration/src/Migrations/Step/ReplaceNameStepExecutor.php index 0f033f192c..394e3dfd01 100644 --- a/code_samples/data_migration/src/Migrations/Step/ReplaceNameStepExecutor.php +++ b/code_samples/data_migration/src/Migrations/Step/ReplaceNameStepExecutor.php @@ -12,12 +12,8 @@ final class ReplaceNameStepExecutor extends AbstractStepExecutor { - private ContentService $contentService; - - public function __construct( - ContentService $contentService - ) { - $this->contentService = $contentService; + public function __construct(private readonly ContentService $contentService) + { } protected function doHandle(StepInterface $step) @@ -38,7 +34,7 @@ protected function doHandle(StepInterface $step) continue; } - if (str_contains($field->value, 'Company Name')) { + if (str_contains((string) $field->value, 'Company Name')) { $newValue = str_replace('Company Name', $step->getReplacement(), $field->value); $struct->setField($field->fieldDefIdentifier, new Value($newValue)); } @@ -48,7 +44,7 @@ protected function doHandle(StepInterface $step) $content = $this->contentService->createContentDraft($contentItem->contentInfo); $content = $this->contentService->updateContent($content->getVersionInfo(), $struct); $this->contentService->publishVersion($content->getVersionInfo()); - } catch (\Throwable $e) { + } catch (\Throwable) { // Ignore } } diff --git a/code_samples/discounts/src/Command/ManageDiscountsCommand.php b/code_samples/discounts/src/Command/ManageDiscountsCommand.php index 8852f5b5df..88221cafad 100644 --- a/code_samples/discounts/src/Command/ManageDiscountsCommand.php +++ b/code_samples/discounts/src/Command/ManageDiscountsCommand.php @@ -20,36 +20,20 @@ use Ibexa\Discounts\Value\DiscountRule\FixedAmount; use Ibexa\DiscountsCodes\Value\DiscountCondition\IsValidDiscountCode; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -final class ManageDiscountsCommand extends Command +#[\Symfony\Component\Console\Attribute\AsCommand(name: 'discounts:manage')] +final readonly class ManageDiscountsCommand { - protected static $defaultName = 'discounts:manage'; - - private DiscountServiceInterface $discountService; - - private DiscountCodeServiceInterface $discountCodeService; - - private PermissionResolver $permissionResolver; - - private UserService $userService; - public function __construct( - UserService $userSerice, - PermissionResolver $permissionResolver, - DiscountServiceInterface $discountService, - DiscountCodeServiceInterface $discountCodeService + private UserService $userService, + private PermissionResolver $permissionResolver, + private DiscountServiceInterface $discountService, + private DiscountCodeServiceInterface $discountCodeService ) { - $this->userService = $userSerice; - $this->discountService = $discountService; - $this->discountCodeService = $discountCodeService; - $this->permissionResolver = $permissionResolver; - - parent::__construct(); } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $this->permissionResolver->setCurrentUserReference( $this->userService->loadUserByLogin('admin') diff --git a/code_samples/field_types/2dpoint_ft/src/FieldType/Point2D/Type.php b/code_samples/field_types/2dpoint_ft/src/FieldType/Point2D/Type.php index 7dc5dc9e53..2219c9ae36 100644 --- a/code_samples/field_types/2dpoint_ft/src/FieldType/Point2D/Type.php +++ b/code_samples/field_types/2dpoint_ft/src/FieldType/Point2D/Type.php @@ -19,6 +19,7 @@ public function getFieldTypeIdentifier(): string return 'point2d'; } + #[\Override] public function getSettingsSchema(): array { return [ @@ -31,7 +32,7 @@ public function getSettingsSchema(): array public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data): void { - $definition = $data->fieldDefinition; + $definition = $data->getFieldDefinition(); $fieldForm->add('value', Point2DType::class, [ 'required' => $definition->isRequired, 'label' => $definition->getName(), diff --git a/code_samples/field_types/2dpoint_ft/src/FieldType/Point2D/Value.php b/code_samples/field_types/2dpoint_ft/src/FieldType/Point2D/Value.php index 422da756ee..0d9cfa5dcf 100644 --- a/code_samples/field_types/2dpoint_ft/src/FieldType/Point2D/Value.php +++ b/code_samples/field_types/2dpoint_ft/src/FieldType/Point2D/Value.php @@ -50,7 +50,7 @@ public function setY(?float $y): void $this->y = $y; } - public function __toString() + public function __toString(): string { return "({$this->x}, {$this->y})"; } diff --git a/code_samples/field_types/2dpoint_ft/steps/step_1/Value.php b/code_samples/field_types/2dpoint_ft/steps/step_1/Value.php index 985a415ab7..5d6e5bdbf9 100644 --- a/code_samples/field_types/2dpoint_ft/steps/step_1/Value.php +++ b/code_samples/field_types/2dpoint_ft/steps/step_1/Value.php @@ -7,16 +7,8 @@ final class Value implements ValueInterface { - /** @var float|null */ - private $x; - - /** @var float|null */ - private $y; - - public function __construct(?float $x = null, ?float $y = null) + public function __construct(private ?float $x = null, private ?float $y = null) { - $this->x = $x; - $this->y = $y; } public function getX(): ?float @@ -39,7 +31,7 @@ public function setY(?float $y): void $this->y = $y; } - public function __toString() + public function __toString(): string { return "({$this->x}, {$this->y})"; } diff --git a/code_samples/field_types/2dpoint_ft/steps/step_3/Type.php b/code_samples/field_types/2dpoint_ft/steps/step_3/Type.php index 3619c4e028..9e0bbc346d 100644 --- a/code_samples/field_types/2dpoint_ft/steps/step_3/Type.php +++ b/code_samples/field_types/2dpoint_ft/steps/step_3/Type.php @@ -18,7 +18,7 @@ public function getFieldTypeIdentifier(): string public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data): void { - $definition = $data->fieldDefinition; + $definition = $data->getFieldDefinition(); $fieldForm->add('value', Point2DType::class, [ 'required' => $definition->isRequired, 'label' => $definition->getName(), diff --git a/code_samples/field_types/2dpoint_ft/steps/step_6/Type.php b/code_samples/field_types/2dpoint_ft/steps/step_6/Type.php index 14a5b9209d..617411f67e 100644 --- a/code_samples/field_types/2dpoint_ft/steps/step_6/Type.php +++ b/code_samples/field_types/2dpoint_ft/steps/step_6/Type.php @@ -15,6 +15,7 @@ public function getFieldTypeIdentifier(): string return 'point2d'; } + #[\Override] public function getSettingsSchema(): array { return [ @@ -27,7 +28,7 @@ public function getSettingsSchema(): array public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data): void { - $definition = $data->fieldDefinition; + $definition = $data->getFieldDefinition(); $fieldForm->add('value', Point2DType::class, [ 'required' => $definition->isRequired, 'label' => $definition->getName(), diff --git a/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Comparison/HelloWorldComparisonEngine.php b/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Comparison/HelloWorldComparisonEngine.php index 1467f4d827..60fdf5ca71 100644 --- a/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Comparison/HelloWorldComparisonEngine.php +++ b/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Comparison/HelloWorldComparisonEngine.php @@ -7,16 +7,11 @@ use Ibexa\Contracts\VersionComparison\Engine\FieldTypeComparisonEngine; use Ibexa\Contracts\VersionComparison\FieldType\FieldTypeComparisonValue; use Ibexa\Contracts\VersionComparison\Result\ComparisonResult; -use Ibexa\VersionComparison\Engine\Value\StringComparisonEngine; -final class HelloWorldComparisonEngine implements FieldTypeComparisonEngine +final readonly class HelloWorldComparisonEngine implements FieldTypeComparisonEngine { - /** @var \Ibexa\VersionComparison\Engine\Value\StringComparisonEngine */ - private \Ibexa\VersionComparison\Engine\Value\StringComparisonEngine $stringValueComparisonEngine; - - public function __construct(StringComparisonEngine $stringValueComparisonEngine) + public function __construct(private \Ibexa\VersionComparison\Engine\Value\StringComparisonEngine $stringValueComparisonEngine) { - $this->stringValueComparisonEngine = $stringValueComparisonEngine; } /** diff --git a/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Comparison/HelloWorldComparisonResult.php b/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Comparison/HelloWorldComparisonResult.php index 8c03b8e4d9..a8bab2d2f7 100644 --- a/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Comparison/HelloWorldComparisonResult.php +++ b/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Comparison/HelloWorldComparisonResult.php @@ -7,14 +7,10 @@ use Ibexa\Contracts\VersionComparison\Result\ComparisonResult; use Ibexa\VersionComparison\Result\Value\StringComparisonResult; -final class HelloWorldComparisonResult implements ComparisonResult +final readonly class HelloWorldComparisonResult implements ComparisonResult { - /** @var \Ibexa\VersionComparison\Result\Value\StringComparisonResult */ - private \Ibexa\VersionComparison\Result\Value\StringComparisonResult $stringDiff; - - public function __construct(StringComparisonResult $stringDiff) + public function __construct(private \Ibexa\VersionComparison\Result\Value\StringComparisonResult $stringDiff) { - $this->stringDiff = $stringDiff; } public function getHelloWorldDiff(): StringComparisonResult diff --git a/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Type.php b/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Type.php index 09db13dd83..62e5e121ae 100644 --- a/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Type.php +++ b/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Type.php @@ -17,7 +17,7 @@ public function getFieldTypeIdentifier(): string public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data): void { - $definition = $data->fieldDefinition; + $definition = $data->getFieldDefinition(); $fieldForm->add('value', HelloWorldType::class, [ 'required' => $definition->isRequired, diff --git a/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Value.php b/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Value.php index 80c34031a6..5810b42304 100644 --- a/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Value.php +++ b/code_samples/field_types/generic_ft/src/FieldType/HelloWorld/Value.php @@ -10,7 +10,7 @@ final class Value implements ValueInterface /** * @Assert\NotBlank() */ - private ?string $name; + private ?string $name = null; public function getName(): ?string { @@ -22,7 +22,7 @@ public function setName(?string $name): void $this->name = $name; } - public function __toString() + public function __toString(): string { return "Hello {$this->name}!"; } diff --git a/code_samples/forms/custom_form_attribute/src/FormBuilder/FieldType/Field/Mapper/CheckboxWithRichtextDescriptionFieldMapper.php b/code_samples/forms/custom_form_attribute/src/FormBuilder/FieldType/Field/Mapper/CheckboxWithRichtextDescriptionFieldMapper.php index 710d55279e..015ee0e76e 100644 --- a/code_samples/forms/custom_form_attribute/src/FormBuilder/FieldType/Field/Mapper/CheckboxWithRichtextDescriptionFieldMapper.php +++ b/code_samples/forms/custom_form_attribute/src/FormBuilder/FieldType/Field/Mapper/CheckboxWithRichtextDescriptionFieldMapper.php @@ -10,6 +10,7 @@ class CheckboxWithRichtextDescriptionFieldMapper extends GenericFieldMapper /** * {@inheritdoc} */ + #[\Override] protected function mapFormOptions(Field $field, array $constraints): array { $options = parent::mapFormOptions($field, $constraints); diff --git a/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php b/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php index ab4060a679..a5603b63f6 100644 --- a/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php +++ b/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/CheckboxWithRichtextDescriptionType.php @@ -13,7 +13,8 @@ class CheckboxWithRichtextDescriptionType extends AbstractType /** * @return string|null */ - public function getParent() + #[\Override] + public function getParent(): ?string { return CheckboxType::class; } @@ -21,7 +22,8 @@ public function getParent() /** * @return string */ - public function getBlockPrefix() + #[\Override] + public function getBlockPrefix(): string { return 'checkbox_with_richtext_description'; } diff --git a/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/FieldAttribute/AttributeRichtextDescriptionType.php b/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/FieldAttribute/AttributeRichtextDescriptionType.php index bb5101a2fd..4162e9471b 100644 --- a/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/FieldAttribute/AttributeRichtextDescriptionType.php +++ b/code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/FieldAttribute/AttributeRichtextDescriptionType.php @@ -10,7 +10,8 @@ class AttributeRichtextDescriptionType extends AbstractType /** * @return string|null */ - public function getParent() + #[\Override] + public function getParent(): ?string { return RichTextType::class; } @@ -18,7 +19,8 @@ public function getParent() /** * @return string */ - public function getBlockPrefix() + #[\Override] + public function getBlockPrefix(): string { return 'field_configuration_attribute_richtext'; } diff --git a/code_samples/forms/custom_form_field/src/FormBuilder/Field/Mapper/CountryFieldMapper.php b/code_samples/forms/custom_form_field/src/FormBuilder/Field/Mapper/CountryFieldMapper.php index 5f7f765243..32d4b9774a 100644 --- a/code_samples/forms/custom_form_field/src/FormBuilder/Field/Mapper/CountryFieldMapper.php +++ b/code_samples/forms/custom_form_field/src/FormBuilder/Field/Mapper/CountryFieldMapper.php @@ -7,6 +7,7 @@ class CountryFieldMapper extends GenericFieldMapper { + #[\Override] protected function mapFormOptions(Field $field, array $constraints): array { $options = parent::mapFormOptions($field, $constraints); diff --git a/code_samples/front/custom_query_type/src/QueryType/LatestContentQueryType.php b/code_samples/front/custom_query_type/src/QueryType/LatestContentQueryType.php index 7dee3868ec..2c73561ddc 100644 --- a/code_samples/front/custom_query_type/src/QueryType/LatestContentQueryType.php +++ b/code_samples/front/custom_query_type/src/QueryType/LatestContentQueryType.php @@ -25,7 +25,7 @@ public function getQuery(array $parameters = []) 'sortClauses' => [ new Query\SortClause\DatePublished(Query::SORT_DESC), ], - 'limit' => isset($parameters['limit']) ? $parameters['limit'] : 10, + 'limit' => $parameters['limit'] ?? 10, ]); } diff --git a/code_samples/front/custom_query_type/src/QueryType/OptionsBasedLatestContentQueryType.php b/code_samples/front/custom_query_type/src/QueryType/OptionsBasedLatestContentQueryType.php index f3b987e6ad..3b0060bfc1 100644 --- a/code_samples/front/custom_query_type/src/QueryType/OptionsBasedLatestContentQueryType.php +++ b/code_samples/front/custom_query_type/src/QueryType/OptionsBasedLatestContentQueryType.php @@ -27,7 +27,7 @@ protected function doGetQuery(array $parameters) 'sortClauses' => [ new Query\SortClause\DatePublished(Query::SORT_DESC), ], - 'limit' => isset($parameters['limit']) ? $parameters['limit'] : 10, + 'limit' => $parameters['limit'] ?? 10, ]); } diff --git a/code_samples/front/embed_content/src/Controller/RelationController.php b/code_samples/front/embed_content/src/Controller/RelationController.php index b0cd9aa5be..ebeaac939d 100644 --- a/code_samples/front/embed_content/src/Controller/RelationController.php +++ b/code_samples/front/embed_content/src/Controller/RelationController.php @@ -8,14 +8,8 @@ class RelationController { - private ContentService $contentService; - - private LocationService $locationService; - - public function __construct(ContentService $contentService, LocationService $locationService) + public function __construct(private readonly ContentService $contentService, private readonly LocationService $locationService) { - $this->contentService = $contentService; - $this->locationService = $locationService; } public function showContentAction(View $view, $locationId): View diff --git a/code_samples/front/layouts/breadcrumbs/src/Controller/BreadcrumbController.php b/code_samples/front/layouts/breadcrumbs/src/Controller/BreadcrumbController.php index e178da4048..4cbe2bc0e1 100644 --- a/code_samples/front/layouts/breadcrumbs/src/Controller/BreadcrumbController.php +++ b/code_samples/front/layouts/breadcrumbs/src/Controller/BreadcrumbController.php @@ -11,14 +11,8 @@ class BreadcrumbController extends Controller { - private LocationService $locationService; - - private SearchService $searchService; - - public function __construct(LocationService $locationService, SearchService $searchService) + public function __construct(private readonly LocationService $locationService, private readonly SearchService $searchService) { - $this->locationService = $locationService; - $this->searchService = $searchService; } public function showBreadcrumbsAction($locationId): Response diff --git a/code_samples/front/layouts/menu/src/Menu/MenuBuilder.php b/code_samples/front/layouts/menu/src/Menu/MenuBuilder.php index 977724de5f..9266372cf2 100644 --- a/code_samples/front/layouts/menu/src/Menu/MenuBuilder.php +++ b/code_samples/front/layouts/menu/src/Menu/MenuBuilder.php @@ -7,11 +7,8 @@ class MenuBuilder { - private FactoryInterface $factory; - - public function __construct(FactoryInterface $factory) + public function __construct(private readonly FactoryInterface $factory) { - $this->factory = $factory; } public function buildMenu(): ItemInterface diff --git a/code_samples/front/render_content_in_php/src/Command/ViewCommand.php b/code_samples/front/render_content_in_php/src/Command/ViewCommand.php index 7c8222d0d0..bf8e240fd2 100644 --- a/code_samples/front/render_content_in_php/src/Command/ViewCommand.php +++ b/code_samples/front/render_content_in_php/src/Command/ViewCommand.php @@ -5,48 +5,31 @@ use Ibexa\Core\MVC\Symfony\View\Builder\ContentViewBuilder; use Ibexa\Core\MVC\Symfony\View\Renderer\TemplateRenderer; use Symfony\Component\Console\Attribute\AsCommand; -use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Attribute\Option; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( - name: 'app:view' + name: 'app:view', + description: 'Render the view of a content item' )] -class ViewCommand extends Command +class ViewCommand { - private ContentViewBuilder $contentViewBuilder; - - private TemplateRenderer $templateRenderer; - - public function __construct( - ContentViewBuilder $contentViewBuilder, - TemplateRenderer $templateRenderer - ) { - $this->contentViewBuilder = $contentViewBuilder; - $this->templateRenderer = $templateRenderer; - - parent::__construct(); - } - - protected function configure(): void + public function __construct(private readonly ContentViewBuilder $contentViewBuilder, private readonly TemplateRenderer $templateRenderer) { - $this->setDescription('Render the view of a content item') - ->addOption('content-id', 'c', InputOption::VALUE_OPTIONAL, 'Content ID') - ->addOption('location-id', 'l', InputOption::VALUE_OPTIONAL, 'Location ID') - ->addOption('view-type', 't', InputOption::VALUE_OPTIONAL, 'View Type', 'line'); } - protected function execute(InputInterface $input, OutputInterface $output): int - { - $contentId = $input->getOption('content-id'); - $locationId = $input->getOption('location-id'); + public function __invoke( + OutputInterface $output, + #[Option(name: 'content_id')] int $contentId = 52, + #[Option(name: 'location_id')] int $locationId = 2, + #[Option(name: 'view_type')] string $viewType = 'embed' + ): int { if (empty($contentId) && empty($locationId)) { throw new \InvalidArgumentException('No Content ID nor Location ID given'); } $viewParameters = [ - 'viewType' => $input->getOption('view-type'), + 'viewType' => $viewType, '_controller' => 'ibexa_content:viewAction', ]; diff --git a/code_samples/front/shop/checkout/src/Controller/Checkout/OnePageCheckout.php b/code_samples/front/shop/checkout/src/Controller/Checkout/OnePageCheckout.php index f52d8d355b..3bc1896bb3 100644 --- a/code_samples/front/shop/checkout/src/Controller/Checkout/OnePageCheckout.php +++ b/code_samples/front/shop/checkout/src/Controller/Checkout/OnePageCheckout.php @@ -44,7 +44,7 @@ public function __invoke( return $this->render( '@storefront/checkout/checkout.html.twig', [ - 'form' => $form->createView(), + 'form' => $form, 'checkout' => $checkout, ] ); diff --git a/code_samples/front/shop/checkout/src/Controller/Checkout/Step/SelectSeatStepController.php b/code_samples/front/shop/checkout/src/Controller/Checkout/Step/SelectSeatStepController.php index bc36d0fdce..b2479c371a 100644 --- a/code_samples/front/shop/checkout/src/Controller/Checkout/Step/SelectSeatStepController.php +++ b/code_samples/front/shop/checkout/src/Controller/Checkout/Step/SelectSeatStepController.php @@ -30,7 +30,7 @@ public function __invoke( 'layout' => $this->getSeatsLayout(), 'current_step' => $step, 'checkout' => $checkout, - 'form' => $form->createView(), + 'form' => $form, ] ); } diff --git a/code_samples/front/shop/shipping/src/ShippingMethodType/CustomerNotNullValidator.php b/code_samples/front/shop/shipping/src/ShippingMethodType/CustomerNotNullValidator.php index e162d29fc0..da4e59ba1e 100644 --- a/code_samples/front/shop/shipping/src/ShippingMethodType/CustomerNotNullValidator.php +++ b/code_samples/front/shop/shipping/src/ShippingMethodType/CustomerNotNullValidator.php @@ -12,7 +12,7 @@ final class CustomerNotNullValidator implements OptionsValidatorInterface, TranslationContainerInterface { - public const MESSAGE = 'Customer identifier value cannot be null'; + public const string MESSAGE = 'Customer identifier value cannot be null'; public function validateOptions(OptionsBag $options): array { diff --git a/code_samples/front/shop/shipping/src/ShippingMethodType/Form/Type/CustomShippingMethodOptionsType.php b/code_samples/front/shop/shipping/src/ShippingMethodType/Form/Type/CustomShippingMethodOptionsType.php index 365f1a2156..d331e37781 100644 --- a/code_samples/front/shop/shipping/src/ShippingMethodType/Form/Type/CustomShippingMethodOptionsType.php +++ b/code_samples/front/shop/shipping/src/ShippingMethodType/Form/Type/CustomShippingMethodOptionsType.php @@ -13,6 +13,7 @@ final class CustomShippingMethodOptionsType extends AbstractType implements TranslationContainerInterface { + #[\Override] public function getBlockPrefix(): string { return 'ibexa_shipping_method_custom'; diff --git a/code_samples/front/shop/shipping/src/ShippingMethodType/Storage/StorageSchema.php b/code_samples/front/shop/shipping/src/ShippingMethodType/Storage/StorageSchema.php index 4417a749c0..96470cb038 100644 --- a/code_samples/front/shop/shipping/src/ShippingMethodType/Storage/StorageSchema.php +++ b/code_samples/front/shop/shipping/src/ShippingMethodType/Storage/StorageSchema.php @@ -8,7 +8,7 @@ final class StorageSchema extends AbstractOptionsStorageSchema { - public const TABLE_NAME = 'ibexa_shipping_method_region_custom'; - public const COLUMN_ID = 'id'; - public const COLUMN_CUSTOMER_ID = 'customer_id'; + public const string TABLE_NAME = 'ibexa_shipping_method_region_custom'; + public const string COLUMN_ID = 'id'; + public const string COLUMN_CUSTOMER_ID = 'customer_id'; } diff --git a/code_samples/front/shop/storefront/src/EventSubscriber/BreadcrumbsMenuSubscriber.php b/code_samples/front/shop/storefront/src/EventSubscriber/BreadcrumbsMenuSubscriber.php index 5aa1e016f4..5bd8acf1b0 100644 --- a/code_samples/front/shop/storefront/src/EventSubscriber/BreadcrumbsMenuSubscriber.php +++ b/code_samples/front/shop/storefront/src/EventSubscriber/BreadcrumbsMenuSubscriber.php @@ -10,7 +10,7 @@ class BreadcrumbsMenuSubscriber implements EventSubscriberInterface { - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ BreadcrumbsMenuBuilder::PRODUCT_MENU => ['onBreadcrumbsMenuConfigure', 0], diff --git a/code_samples/front/view_matcher/src/View/Matcher/Owner.php b/code_samples/front/view_matcher/src/View/Matcher/Owner.php index 106d55bcd7..9c21e12141 100644 --- a/code_samples/front/view_matcher/src/View/Matcher/Owner.php +++ b/code_samples/front/view_matcher/src/View/Matcher/Owner.php @@ -13,14 +13,11 @@ class Owner implements MatcherInterface { - private UserService $userService; - /** @var string[] */ private array $matchingUserLogins; - public function __construct(UserService $userService) + public function __construct(private readonly UserService $userService) { - $this->userService = $userService; } /** diff --git a/code_samples/multisite/automated_translation/src/AutomatedTranslation/AiClient.php b/code_samples/multisite/automated_translation/src/AutomatedTranslation/AiClient.php index e423edb643..817bfa8af0 100644 --- a/code_samples/multisite/automated_translation/src/AutomatedTranslation/AiClient.php +++ b/code_samples/multisite/automated_translation/src/AutomatedTranslation/AiClient.php @@ -14,14 +14,8 @@ final class AiClient implements ClientInterface /** @var array */ private array $supportedLanguages; - private ActionServiceInterface $actionService; - - private ActionConfigurationServiceInterface $actionConfigurationService; - - public function __construct(ActionServiceInterface $actionService, ActionConfigurationServiceInterface $actionConfigurationService) + public function __construct(private readonly ActionServiceInterface $actionService, private readonly ActionConfigurationServiceInterface $actionConfigurationService) { - $this->actionService = $actionService; - $this->actionConfigurationService = $actionConfigurationService; } public function setConfiguration(array $configuration): void diff --git a/code_samples/multisite/siteaccess/AcmeExampleExtension.php b/code_samples/multisite/siteaccess/AcmeExampleExtension.php index 3c56d8023a..230b330026 100644 --- a/code_samples/multisite/siteaccess/AcmeExampleExtension.php +++ b/code_samples/multisite/siteaccess/AcmeExampleExtension.php @@ -11,7 +11,7 @@ final class AcmeExampleExtension extends Extension { - public const ACME_CONFIG_DIR = __DIR__ . '/../../../config/acme'; + public const string ACME_CONFIG_DIR = __DIR__ . '/../../../config/acme'; /** * @throws \Exception @@ -54,6 +54,7 @@ static function ($scopeSettings, $currentScope, ContextualizerInterface $context } /** @param array $config */ + #[\Override] public function getConfiguration(array $config, ContainerBuilder $container): Configuration { return new Configuration(); diff --git a/code_samples/page/custom_attribute/src/Block/Attribute/MyStringAttributeType.php b/code_samples/page/custom_attribute/src/Block/Attribute/MyStringAttributeType.php index 9a9fe33d03..34604db561 100644 --- a/code_samples/page/custom_attribute/src/Block/Attribute/MyStringAttributeType.php +++ b/code_samples/page/custom_attribute/src/Block/Attribute/MyStringAttributeType.php @@ -7,12 +7,14 @@ class MyStringAttributeType extends AbstractType { - public function getParent() + #[\Override] + public function getParent(): ?string { return TextType::class; } - public function getBlockPrefix() + #[\Override] + public function getBlockPrefix(): string { return 'my_string_attribute'; } diff --git a/code_samples/page/custom_page_block/src/Event/Subscriber/BlockEmbedEventEventSubscriber.php b/code_samples/page/custom_page_block/src/Event/Subscriber/BlockEmbedEventEventSubscriber.php index a86ae91b47..157c55ced7 100644 --- a/code_samples/page/custom_page_block/src/Event/Subscriber/BlockEmbedEventEventSubscriber.php +++ b/code_samples/page/custom_page_block/src/Event/Subscriber/BlockEmbedEventEventSubscriber.php @@ -9,11 +9,8 @@ class BlockEmbedEventEventSubscriber implements EventSubscriberInterface { - private ContentService $contentService; - - public function __construct(ContentService $contentService) + public function __construct(private readonly ContentService $contentService) { - $this->contentService = $contentService; } public static function getSubscribedEvents(): array diff --git a/code_samples/page/page_listener/src/Block/Listener/MyBlockListener.php b/code_samples/page/page_listener/src/Block/Listener/MyBlockListener.php index 25aa71cc3e..716cba8645 100644 --- a/code_samples/page/page_listener/src/Block/Listener/MyBlockListener.php +++ b/code_samples/page/page_listener/src/Block/Listener/MyBlockListener.php @@ -8,7 +8,7 @@ class MyBlockListener implements EventSubscriberInterface { - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ BlockRenderEvents::getBlockPreRenderEventName('event') => 'onBlockPreRender', diff --git a/code_samples/recent_activity/src/Command/ActivityLogContextTestCommand.php b/code_samples/recent_activity/src/Command/ActivityLogContextTestCommand.php index d4c93ccd5f..b8f8b243a8 100644 --- a/code_samples/recent_activity/src/Command/ActivityLogContextTestCommand.php +++ b/code_samples/recent_activity/src/Command/ActivityLogContextTestCommand.php @@ -10,10 +10,9 @@ use Ibexa\Contracts\Core\Repository\PermissionResolver; use Ibexa\Contracts\Core\Repository\UserService; use Ibexa\Contracts\Core\Repository\Values\Content\LocationCreateStruct; +use Symfony\Component\Console\Attribute\Argument; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -21,46 +20,22 @@ name: 'doc:test:activity-log-context', description: 'Test activity log context usage' )] -class ActivityLogContextTestCommand extends Command +class ActivityLogContextTestCommand { - private ActivityLogServiceInterface $activityLogService; - - private ContentService $contentService; - - private ContentTypeService $contentTypeService; - - private EventDispatcherInterface $eventDispatcher; - - private PermissionResolver $permissionResolver; - - private UserService $userService; - public function __construct( - ActivityLogServiceInterface $activityLogService, - ContentService $contentService, - ContentTypeService $contentTypeService, - EventDispatcherInterface $eventDispatcher, - PermissionResolver $permissionResolver, - UserService $userService + private readonly ActivityLogServiceInterface $activityLogService, + private readonly ContentService $contentService, + private readonly ContentTypeService $contentTypeService, + private readonly EventDispatcherInterface $eventDispatcher, + private readonly PermissionResolver $permissionResolver, + private readonly UserService $userService ) { - $this->activityLogService = $activityLogService; - $this->contentService = $contentService; - $this->contentTypeService = $contentTypeService; - $this->eventDispatcher = $eventDispatcher; - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - - parent::__construct(); - } - - protected function configure(): void - { - $this->addArgument('id', InputArgument::REQUIRED, 'A test number'); } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(#[Argument(name: 'id', description: 'A test number')] + string $id, OutputInterface $output): int { - $id = $input->getArgument('id'); + $id = $id; $this->permissionResolver->setCurrentUserReference($this->userService->loadUserByLogin('admin')); $this->activityLogService->prepareContext('my_feature', 'Operation description'); diff --git a/code_samples/recent_activity/src/Command/DispatchMyFeatureEventCommand.php b/code_samples/recent_activity/src/Command/DispatchMyFeatureEventCommand.php index 2b6e1baafa..e8004be454 100644 --- a/code_samples/recent_activity/src/Command/DispatchMyFeatureEventCommand.php +++ b/code_samples/recent_activity/src/Command/DispatchMyFeatureEventCommand.php @@ -6,7 +6,6 @@ use App\MyFeature\MyFeature; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -14,18 +13,13 @@ name: 'app:test:throw-my-feature-event', description: 'Throw/Dispatch a MyFeatureEvent' )] -class DispatchMyFeatureEventCommand extends Command +class DispatchMyFeatureEventCommand { - private EventDispatcherInterface $eventDispatcher; - - public function __construct(EventDispatcherInterface $eventDispatcher) + public function __construct(private readonly EventDispatcherInterface $eventDispatcher) { - $this->eventDispatcher = $eventDispatcher; - - parent::__construct(); } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(OutputInterface $output): int { $event = new MyFeatureEvent(new MyFeature(['id' => 123, 'name' => 'Logged Name']), 'simulate'); $this->eventDispatcher->dispatch($event); diff --git a/code_samples/recent_activity/src/Command/MonitorRecentContentCreationCommand.php b/code_samples/recent_activity/src/Command/MonitorRecentContentCreationCommand.php index 52808377f9..fe8c30145c 100644 --- a/code_samples/recent_activity/src/Command/MonitorRecentContentCreationCommand.php +++ b/code_samples/recent_activity/src/Command/MonitorRecentContentCreationCommand.php @@ -11,32 +11,22 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; #[AsCommand( name: 'app:monitor-content-creation', description: 'List last 10 log entry groups with creations in the last hour' )] -class MonitorRecentContentCreationCommand extends Command +class MonitorRecentContentCreationCommand { - private ActivityLogServiceInterface $activityLogService; - - private PermissionResolver $permissionResolver; - - private UserService $userService; - - public function __construct(ActivityLogServiceInterface $activityLogService, PermissionResolver $permissionResolver, UserService $userService) - { - $this->permissionResolver = $permissionResolver; - $this->userService = $userService; - $this->activityLogService = $activityLogService; - - parent::__construct(); + public function __construct( + private readonly ActivityLogServiceInterface $activityLogService, + private readonly PermissionResolver $permissionResolver, + private readonly UserService $userService + ) { } - protected function execute(InputInterface $input, OutputInterface $output): int + public function __invoke(SymfonyStyle $io): int { $query = new Query([ new Criterion\ObjectCriterion(Content::class), @@ -44,8 +34,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int new Criterion\LoggedAtCriterion(new \DateTime('- 1 hour'), Criterion\LoggedAtCriterion::GTE), ], [new LoggedAtSortClause(LoggedAtSortClause::DESC)], 0, 10); - $io = new SymfonyStyle($input, $output); - $this->permissionResolver->setCurrentUserReference($this->userService->loadUserByLogin('admin')); foreach ($this->activityLogService->findGroups($query) as $activityLogGroup) { diff --git a/code_samples/recent_activity/src/Event/MyFeatureEvent.php b/code_samples/recent_activity/src/Event/MyFeatureEvent.php index 53dbfcb8cf..b5bd8e1090 100644 --- a/code_samples/recent_activity/src/Event/MyFeatureEvent.php +++ b/code_samples/recent_activity/src/Event/MyFeatureEvent.php @@ -6,14 +6,8 @@ class MyFeatureEvent extends Event { - private object $object; - - private string $action; - - public function __construct(object $object, string $action) + public function __construct(private readonly object $object, private readonly string $action) { - $this->object = $object; - $this->action = $action; } public function getObject(): object diff --git a/code_samples/recent_activity/src/EventSubscriber/MyFeatureEventSubscriber.php b/code_samples/recent_activity/src/EventSubscriber/MyFeatureEventSubscriber.php index ca8a93bcf6..812875614c 100644 --- a/code_samples/recent_activity/src/EventSubscriber/MyFeatureEventSubscriber.php +++ b/code_samples/recent_activity/src/EventSubscriber/MyFeatureEventSubscriber.php @@ -8,11 +8,8 @@ class MyFeatureEventSubscriber implements EventSubscriberInterface { - private ActivityLogServiceInterface $activityLogService; - - public function __construct(ActivityLogServiceInterface $activityLogService) + public function __construct(private readonly ActivityLogServiceInterface $activityLogService) { - $this->activityLogService = $activityLogService; } public static function getSubscribedEvents(): array @@ -26,7 +23,7 @@ public function onMyFeatureEvent(MyFeatureEvent $event): void { /** @var \App\MyFeature\MyFeature $object */ $object = $event->getObject(); - $className = get_class($object); + $className = $object::class; $id = (string)$object->id; $action = $event->getAction(); $activityLog = $this->activityLogService->build($className, $id, $action); diff --git a/code_samples/recent_activity/src/EventSubscriber/MyFeaturePostActivityListLoadEventSubscriber.php b/code_samples/recent_activity/src/EventSubscriber/MyFeaturePostActivityListLoadEventSubscriber.php index 93d87e8a7b..619ff17f6e 100644 --- a/code_samples/recent_activity/src/EventSubscriber/MyFeaturePostActivityListLoadEventSubscriber.php +++ b/code_samples/recent_activity/src/EventSubscriber/MyFeaturePostActivityListLoadEventSubscriber.php @@ -11,12 +11,8 @@ class MyFeaturePostActivityListLoadEventSubscriber implements EventSubscriberInterface { - private MyFeatureService $myFeatureService; - - public function __construct( - MyFeatureService $myFeatureService - ) { - $this->myFeatureService = $myFeatureService; + public function __construct(private readonly MyFeatureService $myFeatureService) + { } public static function getSubscribedEvents(): array @@ -47,7 +43,7 @@ public function loadMyFeature(PostActivityGroupListLoadEvent $event): void } $log->setRelatedObject($visitedIds[$id]); - } catch (NotFoundException|UnauthorizedException $e) { + } catch (NotFoundException|UnauthorizedException) { $visitedIds[$id] = null; } } diff --git a/code_samples/search/custom/src/GroupResolver/ContentTypeGroupGroupResolver.php b/code_samples/search/custom/src/GroupResolver/ContentTypeGroupGroupResolver.php index fd38f72dcb..a707b331c5 100644 --- a/code_samples/search/custom/src/GroupResolver/ContentTypeGroupGroupResolver.php +++ b/code_samples/search/custom/src/GroupResolver/ContentTypeGroupGroupResolver.php @@ -8,13 +8,10 @@ use Ibexa\Contracts\Elasticsearch\ElasticSearch\Index\Group\GroupResolverInterface; use Ibexa\Contracts\Elasticsearch\Mapping\BaseDocument; -final class ContentTypeGroupGroupResolver implements GroupResolverInterface +final readonly class ContentTypeGroupGroupResolver implements GroupResolverInterface { - private Handler $contentTypeHandler; - - public function __construct(Handler $contentTypeHandler) + public function __construct(private Handler $contentTypeHandler) { - $this->contentTypeHandler = $contentTypeHandler; } public function resolveDocumentGroup(BaseDocument $document): string diff --git a/code_samples/search/custom/src/Query/Aggregation/Elasticsearch/PriorityRangeAggregationVisitor.php b/code_samples/search/custom/src/Query/Aggregation/Elasticsearch/PriorityRangeAggregationVisitor.php index f2d0acfb1e..7782ff33b6 100644 --- a/code_samples/search/custom/src/Query/Aggregation/Elasticsearch/PriorityRangeAggregationVisitor.php +++ b/code_samples/search/custom/src/Query/Aggregation/Elasticsearch/PriorityRangeAggregationVisitor.php @@ -9,6 +9,9 @@ use Ibexa\Contracts\Elasticsearch\Query\AggregationVisitor; use Ibexa\Contracts\Elasticsearch\Query\LanguageFilter; +/** + * @phpstan-template TRangeAggregation of \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\AbstractRangeAggregation + */ final class PriorityRangeAggregationVisitor implements AggregationVisitor { public function supports(Aggregation $aggregation, LanguageFilter $languageFilter): bool @@ -17,7 +20,7 @@ public function supports(Aggregation $aggregation, LanguageFilter $languageFilte } /** - * @param \App\Query\Aggregation\PriorityRangeAggregation $aggregation + * @param \App\Query\Aggregation\PriorityRangeAggregation $aggregation * * @return array> */ diff --git a/code_samples/search/custom/src/Query/Aggregation/PriorityRangeAggregation.php b/code_samples/search/custom/src/Query/Aggregation/PriorityRangeAggregation.php index 8f65e1794b..2952020fcd 100644 --- a/code_samples/search/custom/src/Query/Aggregation/PriorityRangeAggregation.php +++ b/code_samples/search/custom/src/Query/Aggregation/PriorityRangeAggregation.php @@ -7,6 +7,11 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\AbstractRangeAggregation; use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\LocationAggregation; +/** + * @phpstan-template TValue + * + * @phpstan-extends \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\AbstractRangeAggregation + */ final class PriorityRangeAggregation extends AbstractRangeAggregation implements LocationAggregation { } diff --git a/code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationResultExtractor.php b/code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationResultExtractor.php index ba87eda5cf..a81fb9b743 100644 --- a/code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationResultExtractor.php +++ b/code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationResultExtractor.php @@ -24,7 +24,7 @@ public function extract(Aggregation $aggregation, array $languageFilter, stdClas { $entries = []; foreach ($data as $key => $bucket) { - if ($key === 'count' || strpos($key, '_') === false) { + if ($key === 'count' || !str_contains($key, '_')) { continue; } [$from, $to] = explode('_', $key, 2); diff --git a/code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationVisitor.php b/code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationVisitor.php index d78f1a58f6..4f669dc70f 100644 --- a/code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationVisitor.php +++ b/code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationVisitor.php @@ -8,6 +8,9 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation; use Ibexa\Contracts\Solr\Query\AggregationVisitor; +/** + * @phpstan-template TRangeAggregation of \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\AbstractRangeAggregation + */ final class PriorityRangeAggregationVisitor implements AggregationVisitor { public function canVisit(Aggregation $aggregation, array $languageFilter): bool @@ -16,7 +19,7 @@ public function canVisit(Aggregation $aggregation, array $languageFilter): bool } /** - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Query\Aggregation\AbstractRangeAggregation $aggregation + * @param \App\Query\Aggregation\PriorityRangeAggregation $aggregation */ public function visit( AggregationVisitor $dispatcherVisitor, @@ -27,7 +30,7 @@ public function visit( foreach ($aggregation->getRanges() as $range) { $from = $this->formatRangeValue($range->getFrom()); $to = $this->formatRangeValue($range->getTo()); - $rangeFacets["${from}_${to}"] = [ + $rangeFacets["{$from}_{$to}"] = [ 'type' => 'query', 'q' => sprintf('priority_i:[%s TO %s}', $from, $to), ]; diff --git a/code_samples/search/custom/src/Query/Criterion/Solr/CameraManufacturerVisitor.php b/code_samples/search/custom/src/Query/Criterion/Solr/CameraManufacturerVisitor.php index f385d5db1d..c4cf00e598 100644 --- a/code_samples/search/custom/src/Query/Criterion/Solr/CameraManufacturerVisitor.php +++ b/code_samples/search/custom/src/Query/Criterion/Solr/CameraManufacturerVisitor.php @@ -10,7 +10,7 @@ final class CameraManufacturerVisitor extends CriterionVisitor { - public function canVisit(CriterionInterface $criterion) + public function canVisit(CriterionInterface $criterion): bool { return $criterion instanceof CameraManufacturerCriterion; } @@ -18,12 +18,10 @@ public function canVisit(CriterionInterface $criterion) /** * @param \App\Query\Criterion\CameraManufacturerCriterion $criterion */ - public function visit(CriterionInterface $criterion, CriterionVisitor $subVisitor = null) + public function visit(CriterionInterface $criterion, ?CriterionVisitor $subVisitor = null): string { $expressions = array_map( - function ($value): string { - return 'exif_camera_manufacturer_id:"' . $this->escapeQuote((string) $value) . '"'; - }, + fn ($value): string => 'exif_camera_manufacturer_id:"' . $this->escapeQuote((string) $value) . '"', $criterion->value ); diff --git a/code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php b/code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php index 6eae611537..b3e07061eb 100644 --- a/code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php +++ b/code_samples/search/custom/src/Search/FieldMapper/WebinarEventTitleFulltextFieldMapper.php @@ -10,25 +10,17 @@ class WebinarEventTitleFulltextFieldMapper extends ContentFieldMapper { - protected ContentHandler $contentHandler; - - protected LocationHandler $locationHandler; - - public function __construct( - ContentHandler $contentHandler, - LocationHandler $locationHandler - ) { - $this->contentHandler = $contentHandler; - $this->locationHandler = $locationHandler; + public function __construct(protected ContentHandler $contentHandler, protected LocationHandler $locationHandler) + { } - public function accept(Content $content) + public function accept(Content $content): bool { // ContentType with ID 42 is webinar event return $content->versionInfo->contentInfo->contentTypeId == 42; } - public function mapFields(Content $content) + public function mapFields(Content $content): array { $mainLocationId = $content->versionInfo->contentInfo->mainLocationId; $location = $this->locationHandler->load($mainLocationId); diff --git a/code_samples/tutorials/page_tutorial/src/Event/RandomBlockListener.php b/code_samples/tutorials/page_tutorial/src/Event/RandomBlockListener.php index 69d412a9b0..8d04f283fb 100644 --- a/code_samples/tutorials/page_tutorial/src/Event/RandomBlockListener.php +++ b/code_samples/tutorials/page_tutorial/src/Event/RandomBlockListener.php @@ -16,23 +16,14 @@ class RandomBlockListener implements EventSubscriberInterface { - private ContentService $contentService; - - private LocationService $locationService; - - private SearchService $searchService; - public function __construct( - ContentService $contentService, - LocationService $locationService, - SearchService $searchService + private readonly ContentService $contentService, + private readonly LocationService $locationService, + private readonly SearchService $searchService ) { - $this->contentService = $contentService; - $this->locationService = $locationService; - $this->searchService = $searchService; } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ BlockRenderEvents::getBlockPreRenderEventName('random') => 'onBlockPreRender', diff --git a/code_samples/user_management/oauth_google/src/OAuth/GoogleResourceOwnerMapper.php b/code_samples/user_management/oauth_google/src/OAuth/GoogleResourceOwnerMapper.php index 33128465fb..cbd1d14a74 100644 --- a/code_samples/user_management/oauth_google/src/OAuth/GoogleResourceOwnerMapper.php +++ b/code_samples/user_management/oauth_google/src/OAuth/GoogleResourceOwnerMapper.php @@ -17,35 +17,17 @@ final class GoogleResourceOwnerMapper extends ResourceOwnerToExistingOrNewUserMapper { - private const PROVIDER_PREFIX = 'google:'; - - private OAuth2UserService $oauthUserService; - - private LanguageResolver $languageResolver; - - private UserService $userService; - - /** @var string|null */ - private ?string $contentTypeIdentifier; - - /** @var string|null */ - private ?string $parentGroupRemoteId; + private const string PROVIDER_PREFIX = 'google:'; public function __construct( Repository $repository, - OAuth2UserService $oauthUserService, - LanguageResolver $languageResolver, - UserService $userService, - ?string $contentTypeIdentifier = null, - ?string $parentGroupRemoteId = null + private readonly OAuth2UserService $oauthUserService, + private readonly LanguageResolver $languageResolver, + private readonly UserService $userService, + private readonly ?string $contentTypeIdentifier = null, + private readonly ?string $parentGroupRemoteId = null ) { parent::__construct($repository); - - $this->oauthUserService = $oauthUserService; - $this->languageResolver = $languageResolver; - $this->userService = $userService; - $this->contentTypeIdentifier = $contentTypeIdentifier; - $this->parentGroupRemoteId = $parentGroupRemoteId; } /** @@ -54,8 +36,8 @@ public function __construct( protected function loadUser( ResourceOwnerInterface $resourceOwner, UserProviderInterface $userProvider - ): ?UserInterface { - return $userProvider->loadUserByUsername($this->getUsername($resourceOwner)); + ): UserInterface { + return $userProvider->loadUserByIdentifier($this->getUsername($resourceOwner)); } /** @@ -64,7 +46,7 @@ protected function loadUser( protected function createUser( ResourceOwnerInterface $resourceOwner, UserProviderInterface $userProvider - ): ?UserInterface { + ): UserInterface { $userCreateStruct = $this->oauthUserService->newOAuth2UserCreateStruct( $this->getUsername($resourceOwner), $resourceOwner->getEmail(), @@ -82,7 +64,7 @@ protected function createUser( $this->userService->createUser($userCreateStruct, $parentGroups); - return $userProvider->loadUserByUsername($this->getUsername($resourceOwner)); + return $userProvider->loadUserByIdentifier($this->getUsername($resourceOwner)); } private function getOAuth2UserContentType(Repository $repository): ?ContentType diff --git a/code_samples/workflow/custom_workflow/src/EventListener/ApprovedTransitionListener.php b/code_samples/workflow/custom_workflow/src/EventListener/ApprovedTransitionListener.php index ed7f5af3e2..1e6d72e701 100644 --- a/code_samples/workflow/custom_workflow/src/EventListener/ApprovedTransitionListener.php +++ b/code_samples/workflow/custom_workflow/src/EventListener/ApprovedTransitionListener.php @@ -10,11 +10,8 @@ class ApprovedTransitionListener extends AbstractTransitionWorkflowActionListener { - private NotificationInterface $notificationHandler; - - public function __construct(NotificationInterface $notificationHandler) + public function __construct(private readonly NotificationInterface $notificationHandler) { - $this->notificationHandler = $notificationHandler; } public function getIdentifier(): string diff --git a/code_samples/workflow/custom_workflow/src/EventListener/LegalTransitionListener.php b/code_samples/workflow/custom_workflow/src/EventListener/LegalTransitionListener.php index 85f63f55b8..067f46ee14 100644 --- a/code_samples/workflow/custom_workflow/src/EventListener/LegalTransitionListener.php +++ b/code_samples/workflow/custom_workflow/src/EventListener/LegalTransitionListener.php @@ -10,11 +10,8 @@ class LegalTransitionListener extends AbstractTransitionWorkflowActionListener { - private NotificationInterface $notificationHandler; - - public function __construct(NotificationInterface $notificationHandler) + public function __construct(private readonly NotificationInterface $notificationHandler) { - $this->notificationHandler = $notificationHandler; } public function getIdentifier(): string @@ -25,7 +22,7 @@ public function getIdentifier(): string public function onWorkflowEvent(TransitionEvent $event): void { $metadata = $this->getActionMetadata($event->getWorkflow(), $event->getTransition()); - $message = $metadata['data']['message']; + $message = $metadata['data']['message'] ?? ''; $this->notificationHandler->info( $message, diff --git a/code_samples/workflow/strategy/NewWorkflow.php b/code_samples/workflow/strategy/NewWorkflow.php index ac4a240d25..6d15c010ce 100644 --- a/code_samples/workflow/strategy/NewWorkflow.php +++ b/code_samples/workflow/strategy/NewWorkflow.php @@ -11,7 +11,7 @@ final class NewWorkflow implements WorkflowStrategyInterface { - private const IDENTIFIER = 'new_workflow'; + private const string IDENTIFIER = 'new_workflow'; public function getWorkflow(CartInterface $cart): WorkflowInterface { diff --git a/code_samples/workflow/strategy/NewWorkflowConditionalStep.php b/code_samples/workflow/strategy/NewWorkflowConditionalStep.php index d055c879e0..1fa93235d7 100644 --- a/code_samples/workflow/strategy/NewWorkflowConditionalStep.php +++ b/code_samples/workflow/strategy/NewWorkflowConditionalStep.php @@ -11,7 +11,7 @@ final class NewWorkflowConditionalStep implements WorkflowStrategyInterface { - private const IDENTIFIER = 'new_workflow'; + private const string IDENTIFIER = 'new_workflow'; public function getWorkflow(CartInterface $cart): WorkflowInterface { diff --git a/composer.json b/composer.json index b24e245968..f4f318a534 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,12 @@ "url": "https://updates.ibexa.co" } ], + "require": { + "php": "^8.3" + }, "require-dev": { "ibexa/automated-translation": "5.0.x-dev", - "ibexa/code-style": "^1.0", + "ibexa/code-style": "~2.0.0", "friendsofphp/php-cs-fixer": "^3.30", "phpstan/phpstan": "^2.0", "phpstan/phpstan-symfony": "^2.0", diff --git a/docs/ai_actions/extend_ai_actions.md b/docs/ai_actions/extend_ai_actions.md index b07ed511bb..8286527bf7 100644 --- a/docs/ai_actions/extend_ai_actions.md +++ b/docs/ai_actions/extend_ai_actions.md @@ -14,7 +14,7 @@ For example, you can create a handler that connects to a translation model and u You can execute AI Actions by using the [ActionServiceInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionServiceInterface.html) service, as in the following example: ``` php -[[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php', 105, 124) =]] +[[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php', 81, 100) =]] ``` The `GenerateAltTextAction` is a built-in action that implements the [ActionInterface](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionInterface.html), takes an [Image](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-Action-DataType-Image.html) as an input, and generates the alternative text in the response. @@ -43,7 +43,7 @@ You can influence the execution of an Action with two events: Below you can find the full example of a Symfony Command, together with a matching service definition. The command finds the images modified in the last 24 hours, and adds the alternative text to them if it's missing. -``` php hl_lines="91 104-129" +``` php hl_lines="67 80-105" [[= include_file('code_samples/ai_actions/src/Command/AddMissingAltTextCommand.php') =]] ``` @@ -77,7 +77,7 @@ See [Action Configuration Search Criteria reference](action_configuration_criter The following example creates a new Action Configuration: ``` php hl_lines="3 17" -[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 62, 79) =]] +[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 40, 58) =]] ``` Actions Configurations are tied to a specific Action Type and are translatable. @@ -88,7 +88,7 @@ Reuse existing Action Configurations to simplify the execution of AI Actions. You can pass one directly to the `ActionServiceInterface::execute()` method: ``` php hl_lines="7-8" -[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 80, 88) =]] +[[= include_file('code_samples/ai_actions/src/Command/ActionConfigurationCreateCommand.php', 59, 67) =]] ``` The passed Action Configuration is only taken into account if the Action Context was not passed to the Action directly using the [ActionInterface::setActionContext()](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ConnectorAi-ActionInterface.html#method_hasActionContext) method. @@ -116,7 +116,7 @@ Create a class implementing the [ActionHandlerInterface](/api/php_api/php_api_re See the code sample below, together with a matching service definition: -``` php hl_lines="21 29-32 34-69 71-74" +``` php hl_lines="17 23-26 28-63 65-68" [[= include_file('code_samples/ai_actions/src/AI/Handler/LLaVaTextToTextActionHandler.php') =]] ``` diff --git a/docs/api/php_api/php_api.md b/docs/api/php_api/php_api.md index c194d34865..c1d5308242 100644 --- a/docs/api/php_api/php_api.md +++ b/docs/api/php_api/php_api.md @@ -126,7 +126,7 @@ While [using `sudo()`](#using-sudo) is the recommended option, you can also set To identify as a different user, you need to use the `UserService` together with `PermissionResolver` (in the example `admin` is the login of the administrator user): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 55, 57) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 36, 38) =]] ``` !!! tip diff --git a/docs/commerce/cart/cart_api.md b/docs/commerce/cart/cart_api.md index 0d6855db34..ab6d467661 100644 --- a/docs/commerce/cart/cart_api.md +++ b/docs/commerce/cart/cart_api.md @@ -23,7 +23,7 @@ From the developer's perspective, carts and entries are referenced with a UUID i To access a single cart, use the `CartServiceInterface::getCart` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 88, 91) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 61, 64) =]] ``` ## Get multiple carts @@ -35,7 +35,7 @@ It follows the same search Query pattern as other APIs: [[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 10, 11) =]] // ... -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 74, 83) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 47, 56) =]] ``` ## Create cart @@ -46,7 +46,7 @@ To create a cart, use the `CartServiceInterface::createCart` method and provide [[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 8, 9) =]] // ... -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 95, 104) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 68, 76) =]] ``` ## Update cart metadata @@ -59,7 +59,7 @@ To update cart metadata, use the `CartServiceInterface::updateCartMetadata` meth [[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 9, 10) =]] // ... -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 107, 114) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 80, 87) =]] ``` You can also use this method to change cart ownership: @@ -80,8 +80,8 @@ $cart = $cartService->updateCartMetadata($cart, $updateMetadataStruct); To delete a cart permanently, use the `CartServiceInterface::deleteCart` method and pass the `CartInterface` object: ``` php -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 88, 89) =]] -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 149, 150) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 61, 62) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 122, 123) =]] ``` ## Empty cart @@ -89,8 +89,8 @@ To delete a cart permanently, use the `CartServiceInterface::deleteCart` method To remove all products from the cart in a single operation, use the `CartServiceInterface::emptyCart` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 88, 89) =]] -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 116, 117) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 61, 62) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 89, 91) =]] ``` ## Check cart validity @@ -101,8 +101,8 @@ To validate the cart, use the `CartServiceInterface::validateCart` method. Validation is done with help from the `symfony/validator` component, and the method returns a `Symfony\Component\Validator\ConstraintViolationListInterface` object. ``` php -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 88, 89) =]] -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 119, 120) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 61, 62) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 92, 93) =]] ``` ## Add entry to cart @@ -114,8 +114,8 @@ Then pass it to the `CartServiceInterface::addEntry` method: [[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 11, 12) =]] // ... -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 88, 89) =]] -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 124, 131) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 61, 62) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 97, 104) =]] ``` ## Remove entry from cart @@ -123,11 +123,8 @@ Then pass it to the `CartServiceInterface::addEntry` method: To remove an entry from the cart, use the `CartServiceInterface::removeEntry` method. ``` php -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 11, 12) =]] -// ... - -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 88, 89) =]] -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 134, 137) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 61, 62) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 107, 110) =]] ``` ## Update entry metadata @@ -138,10 +135,9 @@ To change entry metadata, use the `CartServiceInterface::updateEntry` method and ``` php [[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 12, 13) =]] // ... - -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 88, 89) =]] -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 129, 130) =]] -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 139, 147) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 61, 62) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 107, 108) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 112, 120) =]] ``` ## Adding context data @@ -188,5 +184,5 @@ To combine the contents of multiple shopping carts into a target cart, use the ` This operation is helpful when you want to consolidate items from a reorder cart and a current cart into a single order. ```php -[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 151, 164) =]] +[[= include_file('code_samples/api/commerce/src/Command/CartCommand.php', 124, 137) =]] ``` diff --git a/docs/commerce/checkout/checkout_api.md b/docs/commerce/checkout/checkout_api.md index b45f220587..6de1c2b39b 100644 --- a/docs/commerce/checkout/checkout_api.md +++ b/docs/commerce/checkout/checkout_api.md @@ -22,7 +22,7 @@ From the developer's perspective, checkouts are referenced with an UUID identifi To access a single checkout, use the `CheckoutServiceInterface::getCheckout` method: ``` php -[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 32, 33) =]] +[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 26, 27) =]] ``` ## Get single checkout for specific cart @@ -31,7 +31,7 @@ To fetch checkout for a cart that already exists, use the `CheckoutServiceInterf You can use it when you want to initiate the checkout process right after products are successfully added to a cart. ``` php -[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 26, 30) =]] +[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 20, 24) =]] ``` ## Create checkout @@ -39,7 +39,7 @@ You can use it when you want to initiate the checkout process right after produc To create a checkout, use the `CheckoutServiceInterface::createCheckout` method and provide it with a `CheckoutCreateStruct` struct that contains a `CartInterface` object. ``` php -[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 35, 41) =]] +[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 29, 35) =]] ``` ## Update checkout @@ -53,7 +53,7 @@ To update the checkout, use the `CheckoutServiceInterface::updateCheckout` metho All data is placed in session storage. ``` php -[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 43, 45) =]] +[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 37, 39) =]] ``` ## Delete checkout @@ -61,5 +61,5 @@ All data is placed in session storage. To delete a checkout from the session, use the `CheckoutServiceInterface::deleteCheckout` method: ``` php -[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 47, 48) =]] +[[= include_file('code_samples/api/commerce/src/Controller/CustomCheckoutController.php', 41, 42) =]] ``` diff --git a/docs/commerce/order_management/order_management_api.md b/docs/commerce/order_management/order_management_api.md index 9fc9bd0f4f..460a606cd2 100644 --- a/docs/commerce/order_management/order_management_api.md +++ b/docs/commerce/order_management/order_management_api.md @@ -19,7 +19,7 @@ To get orders and manage them, use the [`Ibexa\Contracts\OrderManagement\OrderSe To access a single order by using its string identifier, use the [`OrderServiceInterface::getOrderByIdentifier`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-OrderManagement-OrderServiceInterface.html#method_getOrderByIdentifier) method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 61, 65) =]] +[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 45, 49) =]] ``` ### Get single order by ID @@ -27,7 +27,7 @@ To access a single order by using its string identifier, use the [`OrderServiceI To access a single order by using its numerical ID, use the [`OrderServiceInterface::getOrder`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-OrderManagement-OrderServiceInterface.html#method_getOrder) method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 67, 72) =]] +[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 51, 55) =]] ``` ## Get multiple orders @@ -36,10 +36,10 @@ To fetch multiple orders, use the [`OrderServiceInterface::findOrders`](/api/php It follows the same search query pattern as other APIs: ``` php -[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 8, 9) =]][[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 10, 14) =]] +[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 8, 14) =]] // ... -[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 120, 130) =]] +[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 104, 113) =]] ``` ## Create order @@ -47,7 +47,7 @@ It follows the same search query pattern as other APIs: To create an order, use the [`OrderServiceInterface::createOrder`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-OrderManagement-OrderServiceInterface.html#method_createOrder) method and provide it with the [`Ibexa\Contracts\OrderManagement\Value\Struct\OrderCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-OrderManagement-Value-Struct-OrderCreateStruct.html) object that contains a list of products, purchased quantities, product, total prices, and tax amounts. ``` php -[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 101, 113) =]] +[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 85, 96) =]] ``` ## Update order @@ -57,5 +57,5 @@ You could do it to support a scenario when, for example, the order is processed To update order information, use the [`OrderServiceInterface::updateOrder`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-OrderManagement-OrderServiceInterface.html#method_updateOrder) method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 114, 119) =]] +[[= include_file('code_samples/api/commerce/src/Command/OrderCommand.php', 98, 102) =]] ``` diff --git a/docs/commerce/payment/extend_payment.md b/docs/commerce/payment/extend_payment.md index feb410f7a7..33ed3045bd 100644 --- a/docs/commerce/payment/extend_payment.md +++ b/docs/commerce/payment/extend_payment.md @@ -94,11 +94,11 @@ When you create a payment, you can attach custom data to it, for example, you ca You add custom data by using the `setContext` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 97, 109) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 75, 87) =]] ``` Then, you retrieve it with the `getContext` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 70, 74) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 48, 52) =]] ``` diff --git a/docs/commerce/payment/payment_api.md b/docs/commerce/payment/payment_api.md index 93d416df7f..5a0f1a2b70 100644 --- a/docs/commerce/payment/payment_api.md +++ b/docs/commerce/payment/payment_api.md @@ -17,7 +17,7 @@ You can change that by providing a custom payment identifier in `Ibexa\Contracts To access a single payment by using its numerical ID, use the `PaymentServiceInterface::getPayment` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 64, 68) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 42, 46) =]] ``` ### Get single payment by identifier @@ -25,7 +25,7 @@ To access a single payment by using its numerical ID, use the `PaymentServiceInt To access a single payment by using its string identifier, use the `PaymentServiceInterface::getPaymentByIdentifier` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 70, 72) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 48, 50) =]] ``` ## Get multiple payments @@ -34,7 +34,7 @@ To fetch multiple payments, use the `PaymentServiceInterface::findPayments` meth It follows the same search query pattern as other APIs: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 79, 95) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 57, 73) =]] ``` ## Create payment @@ -42,8 +42,7 @@ It follows the same search query pattern as other APIs: To create a payment, use the `PaymentServiceInterface::createPayment` method and provide it with the `Ibexa\Contracts\Payment\Payment\PaymentCreateStruct` object that takes the following arguments: `method`, `order` and `amount`. ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 101, 105) =]] -[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 108, 112) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 75, 89) =]] ``` ## Update payment @@ -54,7 +53,7 @@ The `Ibexa\Contracts\Payment\Payment\PaymentUpdateStruct` object takes the follo To update payment information, use the `PaymentServiceInterface::updatePayment` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 113, 119) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 91, 97) =]] ``` ## Delete payment @@ -62,5 +61,5 @@ To update payment information, use the `PaymentServiceInterface::updatePayment` To delete a payment from the system, use the `PaymentServiceInterface::deletePayment` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 121, 122) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentCommand.php', 99, 100) =]] ``` diff --git a/docs/commerce/payment/payment_method_api.md b/docs/commerce/payment/payment_method_api.md index 00856a67aa..15ba615304 100644 --- a/docs/commerce/payment/payment_method_api.md +++ b/docs/commerce/payment/payment_method_api.md @@ -26,7 +26,7 @@ From the developer's perspective, payment methods are referenced with identifier To access a single payment method by using its string identifier, use the `PaymentMethodService::getPaymentMethodByIdentifier` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 56, 60) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 44, 48) =]] ``` ### Get single payment method by ID @@ -34,7 +34,7 @@ To access a single payment method by using its string identifier, use the `Payme To access a single payment method by using its numerical ID, use the `PaymentMethodService::getPaymentMethod` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 50, 54) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 38, 42) =]] ``` ## Get multiple payment methods @@ -44,7 +44,7 @@ To fetch multiple payment methods, use the `PaymentMethodService::findPaymentMet It follows the same search query pattern as other APIs: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 62, 79) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 50, 68) =]] ``` ## Create payment method @@ -59,7 +59,7 @@ To create a payment method, use the `PaymentMethodService::createPaymentMethod` - `options` object. ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 62, 63) =]][[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 81, 91) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 50, 51) =]][[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 69, 79) =]] ``` ## Update payment method @@ -70,14 +70,14 @@ An `Ibexa\Contracts\Payment\PaymentMethod\PaymentMethodUpdateStruct` object can To update payment method information, use the `PaymentMethodServiceInterface::updatePaymentMethod` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 93, 103) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 81, 91) =]] ``` ## Delete payment method To delete a payment method from the system, use the `PaymentMethodService::deletePayment` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 105, 111) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 93, 99) =]] ``` ## Check whether payment method is used @@ -85,5 +85,5 @@ To delete a payment method from the system, use the `PaymentMethodService::delet To check whether a payment method is used, for example, before you delete it, use the `PaymentMethodService::isPaymentMethodUsed` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 113, 126) =]] +[[= include_file('code_samples/api/commerce/src/Command/PaymentMethodCommand.php', 101, 114) =]] ``` diff --git a/docs/commerce/shipping_management/shipment_api.md b/docs/commerce/shipping_management/shipment_api.md index 3d6140a151..3d86bd4f18 100644 --- a/docs/commerce/shipping_management/shipment_api.md +++ b/docs/commerce/shipping_management/shipment_api.md @@ -16,7 +16,7 @@ From the developer's perspective, shipments are referenced with a UUID identifie To access a single shipment by using its string identifier, use the `ShipmentService::getShipmentByIdentifier` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 73, 82) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 55, 64) =]] ``` ### Get single shipment by id @@ -24,7 +24,7 @@ To access a single shipment by using its string identifier, use the `ShipmentSer To access a single shipment by using its numerical id, use the `ShipmentService::getShipment` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 61, 71) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 43, 53) =]] ``` ## Get multiple shipments @@ -33,7 +33,7 @@ To fetch multiple shipments, use the `ShipmentService::findShipments` method. It follows the same search query pattern as other APIs: ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 84, 103) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 66, 85) =]] ``` ## Create shipment @@ -41,7 +41,7 @@ It follows the same search query pattern as other APIs: To create a shipment, use the `ShipmentService::createShipment` method and provide it with an `Ibexa\Contracts\Shipping\Value\ShipmentCreateStruct` object that takes two parameters, a `shippingMethod` string and a `Money` object. ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 105, 119) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 87, 101) =]] ``` ## Update shipment @@ -51,7 +51,7 @@ You could do it to support a scenario when, for example, the shipment is process To update shipment information, use the `ShipmentService::updateShipment` method: ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 121, 132) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 103, 114) =]] ``` ## Delete shipment @@ -59,5 +59,5 @@ To delete a shipment from the system, use the `ShipmentService::deleteShipment` ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 134, 135) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShipmentCommand.php', 116, 117) =]] ``` diff --git a/docs/commerce/shipping_management/shipping_method_api.md b/docs/commerce/shipping_management/shipping_method_api.md index a869cd3570..b08f787fcf 100644 --- a/docs/commerce/shipping_management/shipping_method_api.md +++ b/docs/commerce/shipping_management/shipping_method_api.md @@ -17,7 +17,7 @@ To access a shipping method by using its identifier, use the `ShippingMethodServ The method takes a string as `$identifier` parameter and uses a prioritized language from SiteAccess settings unless you pass another language as `forcedLanguage`. ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 65, 75) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 50, 60) =]] ``` ### Get shipping method by ID @@ -26,7 +26,7 @@ To access a shipping method by using its ID, use the `ShippingMethodServiceInter The method takes a string as `$id` parameter and uses a prioritized language from SiteAccess settings unless you pass another language as `forcedLanguage`. ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 53, 63) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 38, 48) =]] ``` ## Get multiple shipping methods @@ -35,7 +35,7 @@ To fetch multiple shipping methods, use the `ShippingMethodServiceInterface::get It follows the same search query pattern as other APIs: ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 77, 95) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 62, 80) =]] ``` ## Create shipping method @@ -43,7 +43,7 @@ It follows the same search query pattern as other APIs: To create a shipping method, use the `ShippingMethodServiceInterface::createShippingMethod` method and provide it with the `Ibexa\Contracts\Shipping\Value\ShippingMethodCreateStruct` object that you created by using the `newShippingMethodCreateStruct` method. ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 97, 120) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 82, 105) =]] ``` ## Update shipping method @@ -51,7 +51,7 @@ To create a shipping method, use the `ShippingMethodServiceInterface::createShip To update a shipping method, use the `ShippingMethodServiceInterface::updateShippingMethod` method and provide it with the `Ibexa\Contracts\Shipping\Value\ShippingMethodUpdateStruct` object that you created by using the `newShippingMethodUpdateStruct` method. ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 122, 137) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 107, 121) =]] ``` ## Delete shipping method @@ -59,7 +59,7 @@ To update a shipping method, use the `ShippingMethodServiceInterface::updateShip To update a shipping method, use the `ShippingMethodServiceInterface::deleteShippingMethod` method. ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 138, 144) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 123, 129) =]] ``` ## Delete shipping method translation @@ -67,5 +67,5 @@ To update a shipping method, use the `ShippingMethodServiceInterface::deleteShip To delete shipping method translation, use the `ShippingMethodServiceInterface::deleteShippingMethodTranslation` method. ``` php -[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 146, 155) =]] +[[= include_file('code_samples/api/commerce/src/Command/ShippingMethodCommand.php', 131, 140) =]] ``` diff --git a/docs/content_management/content_api/browsing_content.md b/docs/content_management/content_api/browsing_content.md index 03fcbcd953..ebd3fc7163 100644 --- a/docs/content_management/content_api/browsing_content.md +++ b/docs/content_management/content_api/browsing_content.md @@ -25,16 +25,12 @@ This value object provides primitive fields, such as `contentTypeId`, `published You can also use it to request other Content-related value objects from various services: -``` php hl_lines="10" -// ... -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 4, 5) =]] -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 20, 22) =]] -// ... -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 55, 57) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 63, 72) =]] +``` php hl_lines="1" +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 40, 48) =]] ``` -`ContentInfo` is loaded from the [`ContentService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html) (line 9). +`ContentInfo` is loaded from the [`ContentService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html). It provides you with basic content metadata such as modification and publication dates or main language code. !!! note "Retrieving content information in a controller" @@ -46,7 +42,7 @@ It provides you with basic content metadata such as modification and publication To get the locations of a content item you need to make use of the [`LocationService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 73, 77) =]] } +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 50, 54) =]] } ``` [`LocationService::loadLocations`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_loadLocations) uses `ContentInfo` to get all the locations of a content item. @@ -60,7 +56,7 @@ The [`URLAliasService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-C [`URLAliasService::reverseLookup`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-URLAliasService.html#method_reverseLookup) gets the location's main [URL alias](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-URLAlias.html): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 73, 76) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 77, 80) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 50, 53) =]][[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 54, 57) =]] ``` ### Content type @@ -68,7 +64,7 @@ The [`URLAliasService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-C You can retrieve the content type of a content item through the [`getContentType`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentInfo.html#method_getContentType) method of the ContentInfo object: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 82, 84) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 59, 61) =]] ``` ### Versions @@ -76,13 +72,13 @@ You can retrieve the content type of a content item through the [`getContentType To iterate over the versions of a content item, use the [`ContentService::loadVersions`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadVersions) method, which returns an array of `VersionInfo` value objects. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 86, 92) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 63, 69) =]] ``` You can additionally provide the `loadVersions` method with the version status to get only versions of a specific status, for example: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 93, 94) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 70, 71) =]] ``` !!! note @@ -98,7 +94,7 @@ This method loads only the specified subset of relations to improve performance You can get the current version's `VersionInfo` using [`ContentService::loadVersionInfo`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadVersionInfo). ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 105, 112) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 82, 89) =]] ``` You can also specify the version number as the second argument to get Relations for a specific version: @@ -117,7 +113,7 @@ It also holds the [relation type](content_relations.md), and the optional field You can use the `getOwner` method of the `ContentInfo` object to load the content item's owner as a `User` value object. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 114, 115) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 91, 92) =]] ``` To get the creator of the current version and not the content item's owner, you need to use the `creatorId` property from the current version's `VersionInfo` object. @@ -127,7 +123,7 @@ To get the creator of the current version and not the content item's owner, you You can find the section to which a content item belongs through the [`getSection`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentInfo.html#method_getSection) method of the ContentInfo object: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 117, 118) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 94, 95) =]] ``` !!! note @@ -142,23 +138,23 @@ You need to provide it with the object state group. All object state groups can be retrieved through [`loadObjectStateGroups`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ObjectStateService.html#method_loadObjectStateGroups). ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 120, 125) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentMetaDataCommand.php', 97, 102) =]] ``` ## Viewing content with fields To retrieve the fields of the selected content item, you can use the following command: -```php hl_lines="9-10 12-19" -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 4, 7) =]] // ... -[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentCommand.php', 42, 60) =]] -} +```php hl_lines="27 30-31 33-40" +[[= include_file('code_samples/api/public_php_api/src/Command/ViewContentCommand.php') =]] ``` -Line 9 shows how [`ContentService::loadContent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadContent) loads the content item provided to the command. -Line 10 makes use of the [`ContentTypeService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentTypeService.html) to retrieve the content type of the requested item. +The example shows how to: + +- use [`ContentService::loadContent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_loadContent) loads the content item provided to the command +- use the [`ContentTypeService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentTypeService.html) to retrieve the content type of the requested item +- iterate over fields defined by the content type -Lines 12-19 iterate over fields defined by the content type. For each field they print out its identifier, and then using [`FieldTypeService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-FieldTypeService.html) retrieve the field's value and print it out to the console. ## Viewing content in different languages @@ -182,12 +178,12 @@ $contentService->loadContent($content->id, Language::ALL); To go through all the content items contained in a subtree, you need to use the [`LocationService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html). ``` php hl_lines="5 15" -[[= include_file('code_samples/api/public_php_api/src/Command/BrowseLocationsCommand.php', 35, 54) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/BrowseLocationsCommand.php', 21, 40) =]] ``` -`loadLocation` (line 15) returns a value object, here a `Location`. +`loadLocation` returns a value object, here a `Location`. -[`LocationService::loadLocationChildren`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_loadLocationChildren) (line 5) returns a [`LocationList`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-LocationList.html) value object that you can iterate over. +[`LocationService::loadLocationChildren`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_loadLocationChildren) returns a [`LocationList`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-LocationList.html) value object that you can iterate over. !!! note diff --git a/docs/content_management/content_api/creating_content.md b/docs/content_management/content_api/creating_content.md index 7f8997a167..05149b4b80 100644 --- a/docs/content_management/content_api/creating_content.md +++ b/docs/content_management/content_api/creating_content.md @@ -21,17 +21,17 @@ Value objects such as content items are read-only, so to create or modify them y returns a new [`ContentCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentCreateStruct.html) object. ``` php hl_lines="2-3 5" -[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 62, 71) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 40, 50) =]] ``` -This command creates a draft using [`ContentService::createContent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_createContent) (line 7). +This command creates a draft using [`ContentService::createContent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_createContent). This method must receive a `ContentCreateStruct` and an array of location structs. -`ContentCreateStruct` (which extends `ContentStruct`) is created through [`ContentService::newContentCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_newContentCreateStruct) (line 2), +`ContentCreateStruct` (which extends `ContentStruct`) is created through [`ContentService::newContentCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_newContentCreateStruct), which receives the content type and the primary language for the content item. For information about translating a content item into other languages, see [Translating content](#translating-content). -[`ContentStruct::setField`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentStruct.html#method_setField) (line 3) enables you to define the field values. +[`ContentStruct::setField`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentStruct.html#method_setField) enables you to define the field values. When the field accepts a simple value, you can provide it directly, as in the example above. For some field types, for example [images](#creating-an-image), you need to provide an instance of a Value type. @@ -42,7 +42,7 @@ Therefore, when creating a content item of the Image type (or any other content the `ContentCreateStruct` is slightly more complex than in the previous example: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CreateImageCommand.php', 61, 74) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CreateImageCommand.php', 39, 51) =]] ``` Value of the Image field type contains the path to the image file and other basic information based on the input file. @@ -66,7 +66,7 @@ To publish it, use [`ContentService::publishVersion`](/api/php_api/php_api_refer This method must get the [`VersionInfo`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-VersionInfo.html) object of a draft version. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 73, 74) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentCommand.php', 52, 53) =]] ``` ## Updating content @@ -76,7 +76,7 @@ and pass it to [`ContentService::updateContent`](/api/php_api/php_api_reference/ This method works on a draft, so to publish your changes you need to use [`ContentService::publishVersion`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html#method_publishVersion) as well: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/UpdateContentCommand.php', 52, 60) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/UpdateContentCommand.php', 33, 42) =]] ``` ## Translating content @@ -86,15 +86,15 @@ Content [translations](languages.md#language-versions) are created per version. To translate a content item to a new language, you need to update it and provide a new `initialLanguageCode`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 57, 62) =]] -[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 67, 69) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 37, 43) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 48, 51) =]] ``` You can also update content in multiple languages at once using the `setField` method's third argument. Only one language can still be set as a version's initial language: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 64, 65) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TranslateContentCommand.php', 45, 46) =]] ``` ### Deleting a translation diff --git a/docs/content_management/content_api/managing_content.md b/docs/content_management/content_api/managing_content.md index 858c023f52..567ea756e2 100644 --- a/docs/content_management/content_api/managing_content.md +++ b/docs/content_management/content_api/managing_content.md @@ -22,8 +22,8 @@ Creating a new location, like creating content, requires using a struct, because To add a new location to existing content you need to create a [`LocationCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-LocationCreateStruct.html) and pass it to the [`LocationService::createLocation`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_createLocation) method: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 55, 56) =]] -[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 60, 62) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 35, 36) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 40, 42) =]] ``` `LocationCreateStruct` must receive the parent location ID. @@ -32,7 +32,7 @@ It sets the `parentLocationId` property of the new location. You can also provide other properties for the location, otherwise they're set to their defaults: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 57, 59) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/AddLocationToContentCommand.php', 37, 39) =]] ``` ### Changing the main location @@ -41,7 +41,7 @@ When a content item has more that one location, one location is always considere You can change the main location using [`ContentService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentService.html), by updating the `ContentInfo` with a [`ContentUpdateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-ContentUpdateStruct.html) that sets the new main location: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SetMainLocationCommand.php', 53, 57) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SetMainLocationCommand.php', 33, 39) =]] ``` ### Hiding and revealing locations @@ -49,7 +49,7 @@ You can change the main location using [`ContentService`](/api/php_api/php_api_r To hide or reveal (unhide) a location you need to make use of [`LocationService::hideLocation`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_hideLocation) or [`LocationService::unhideLocation`:](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_unhideLocation) ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/HideLocationCommand.php', 51, 52) =]][[= include_file('code_samples/api/public_php_api/src/Command/HideLocationCommand.php', 54, 55) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/HideLocationCommand.php', 34, 41) =]] ``` See [location visibility](locations.md#location-visibility) for detailed information on the behavior of visible and hidden Locations. @@ -66,14 +66,14 @@ Content which has more locations is still available in its other locations. If you delete the [main location](#changing-the-main-location) of a content item that has more locations, another location becomes the main one. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/DeleteContentCommand.php', 49, 50) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/DeleteContentCommand.php', 31, 34) =]] ``` To send the location and its subtree to Trash, use [`TrashService::trash`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-TrashService.html#method_trash). Items in Trash can be later [restored, or deleted permanently](#trash). ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/TrashContentCommand.php', 59, 60) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TrashContentCommand.php', 36, 39) =]] ``` ### Moving and copying a subtree @@ -81,7 +81,7 @@ Items in Trash can be later [restored, or deleted permanently](#trash). You can move a location with its whole subtree using [`LocationService::moveSubtree`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_moveSubtree): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/MoveContentCommand.php', 51, 54) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/MoveContentCommand.php', 33, 37) =]] ``` [`LocationService::copySubtree`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LocationService.html#method_copySubtree) is used in the same way, but it copies the location and its subtree instead of moving it. @@ -108,7 +108,7 @@ You must provide the method with the ID of the object in Trash. Trash location is identical to the origin location of the object. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/TrashContentCommand.php', 69, 70) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TrashContentCommand.php', 48, 49) =]] ``` The content item is restored under its previous location. @@ -138,13 +138,14 @@ In this case you use [`ContentTypeCreateStruct`](/api/php_api/php_api_reference/ A content type must have at least one name, in the main language, and at least one field definition. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 64, 74) =]][[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 81, 90) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 48, 58) =]][[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 65, 74) =]] + ``` You can specify more details of the field definition in the create struct, for example: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 72, 82) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 56, 67) =]] ``` ### Copying content types @@ -152,7 +153,7 @@ You can specify more details of the field definition in the create struct, for e To copy a content type, use [`ContentTypeService::copyContentType`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ContentTypeService.html#method_copyContentType): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 94, 95) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 78, 79) =]] ``` The copy is automatically getting an identifier based on the original content type identifier and the copy's ID, for example: `copy_of_folder_21`. @@ -160,7 +161,7 @@ The copy is automatically getting an identifier based on the original content ty To change the identifier of the copy, use a [`ContentTypeUpdateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ContentType-ContentTypeUpdateStruct.html): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 95, 101) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php', 79, 85) =]] ``` ## Calendar events @@ -177,19 +178,19 @@ To get a list of events for a specified time period, use the `CalendarServiceInt You need to provide the method with an EventQuery, which takes a date range and a count as the minimum of parameters: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 44, 55) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 31, 42) =]] ``` You can also get the first and last event in the list by using the `first()` and `last()` methods of an `EventCollection` (`Ibexa\Contracts\Calendar\EventCollection`): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 56, 58) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 43, 45) =]] ``` You can process the events in a collection using the `find(Closure $predicate)`, `filter(Closure $predicate)`, `map(Closure $callback)` or `slice(int $offset, ?int $length = null)` methods of `EventCollection`, for example: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 59, 62) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 46, 50) =]] ``` ### Performing calendar actions @@ -199,9 +200,5 @@ You must pass an `Ibexa\Contracts\Calendar\EventAction\EventActionContext` insta `EventActionContext` defines events on which the action is performed, and action-specific parameters, for example, a new date: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 64, 66) =]] -``` - -``` php -$context = new UnscheduleEventActionContext($eventCollection); +[[= include_file('code_samples/api/public_php_api/src/Command/CalendarCommand.php', 51, 55) =]] ``` diff --git a/docs/content_management/content_management_api/bookmark_api.md b/docs/content_management/content_management_api/bookmark_api.md index 63f5ba6176..8f57d51d51 100644 --- a/docs/content_management/content_management_api/bookmark_api.md +++ b/docs/content_management/content_management_api/bookmark_api.md @@ -13,17 +13,17 @@ description: You can use the PHP API to view the bookmark list, and add or remov To view a list of all bookmarks, use [`BookmarkService::loadBookmarks`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-BookmarkService.html#method_loadBookmarks): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/BookmarkCommand.php', 48, 55) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/BookmarkCommand.php', 42, 48) =]] ``` You can add a bookmark to a content item by providing its Location object to the [`BookmarkService::createBookmark`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-BookmarkService.html#method_createBookmark) method: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/BookmarkCommand.php', 42, 45) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/BookmarkCommand.php', 38, 40) =]] ``` You can remove a bookmark from a location with [`BookmarkService::deleteBookmark`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-BookmarkService.html#method_deleteBookmark): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/BookmarkCommand.php', 57, 58) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/BookmarkCommand.php', 51, 51) =]] ``` diff --git a/docs/content_management/content_management_api/object_state_api.md b/docs/content_management/content_management_api/object_state_api.md index 8d907897cf..7f65271c04 100644 --- a/docs/content_management/content_management_api/object_state_api.md +++ b/docs/content_management/content_management_api/object_state_api.md @@ -18,7 +18,7 @@ You can manage Object states by using the PHP API by using `ObjectStateService`. You can use the [`ObjectStateService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ObjectStateService.html) to get information about object state groups or object states. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ObjectStateCommand.php', 48, 53) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ObjectStateCommand.php', 41, 46) =]] ``` ## Creating object states @@ -26,7 +26,7 @@ You can use the [`ObjectStateService`](/api/php_api/php_api_reference/classes/Ib To create an object state group and add object states to it, you need to make use of the [`ObjectStateService`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ObjectStateService.html): ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ObjectStateCommand.php', 57, 61) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ObjectStateCommand.php', 50, 54) =]] ``` [`ObjectStateService::createObjectStateGroup`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ObjectStateService.html#method_createObjectStateGroup) takes as argument an [`ObjectStateGroupCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-ObjectState-ObjectStateGroupCreateStruct.html), in which you need to specify the identifier, default language and at least one name for the group. @@ -34,7 +34,7 @@ To create an object state group and add object states to it, you need to make us To create an object state inside a group, use [`ObjectStateService::newObjectStateCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-ObjectStateService.html#method_newObjectStateCreateStruct) and provide it with an `ObjectStateCreateStruct`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ObjectStateCommand.php', 63, 67) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ObjectStateCommand.php', 56, 60) =]] ``` ## Assigning object state @@ -43,5 +43,5 @@ To assign an object state to a content item, use [`ObjectStateService::setConten Provide it with a `ContentInfo` object of the content item, the object state group and the object state: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/ObjectStateCommand.php', 77, 82) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/ObjectStateCommand.php', 71, 75) =]] ``` diff --git a/docs/content_management/content_management_api/section_api.md b/docs/content_management/content_management_api/section_api.md index fff9973e03..f93c0760f2 100644 --- a/docs/content_management/content_management_api/section_api.md +++ b/docs/content_management/content_management_api/section_api.md @@ -17,7 +17,7 @@ You can manage sections by using the PHP API by using `SectionService`. To create a new section, you need to make use of the [`SectionCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-SectionCreateStruct.html) and pass it to the [`SectionService::createSection`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-SectionService.html#method_createSection) method: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 58, 62) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 48, 52) =]] ``` ## Getting section information @@ -25,7 +25,7 @@ To create a new section, you need to make use of the [`SectionCreateStruct`](/ap You can use `SectionService` to retrieve section information such as whether it's in use: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 76, 81) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 66, 71) =]] ``` ## Listing content in a section @@ -34,7 +34,7 @@ To list content items assigned to a section you need to make a [query](search_ap You can also use the query to get the total number of assigned content items: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 69, 75) =]][[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 82, 86) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 59, 65) =]][[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 72, 76) =]] ``` ## Assigning section to content @@ -43,7 +43,7 @@ To assign content to a section, use the [`SectionService::assignSection`](/api/p You need to provide it with the `ContentInfo` object of the content item, and the [`Section`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-Section.html) object: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 64, 67) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SectionCommand.php', 54, 57) =]] ``` Assigning a section to content doesn't automatically assign it to the content item's children. diff --git a/docs/content_management/data_migration/data_migration_api.md b/docs/content_management/data_migration/data_migration_api.md index 53a17c8a6b..507a3e7387 100644 --- a/docs/content_management/data_migration/data_migration_api.md +++ b/docs/content_management/data_migration/data_migration_api.md @@ -11,13 +11,13 @@ You can use the PHP API to manage and run [data migrations](data_migration.md). To list all migration files available in the directory defined in configuration (by default, `src/Migrations/Ibexa`), use the `MigrationService:listMigrations()` method: ``` php -[[= include_file('code_samples/api/migration/src/Command/MigrationCommand.php', 35, 38) =]] +[[= include_file('code_samples/api/migration/src/Command/MigrationCommand.php', 29, 32) =]] ``` To get a single migration file by its name, use the `MigrationService:findOneByName()` method: ``` php -[[= include_file('code_samples/api/migration/src/Command/MigrationCommand.php', 40, 41) =]] +[[= include_file('code_samples/api/migration/src/Command/MigrationCommand.php', 34, 35) =]] ``` ## Running migration files @@ -25,7 +25,7 @@ To get a single migration file by its name, use the `MigrationService:findOneByN To run migration file(s), use either `MigrationService:executeOne()` or `MigrationService:executeAll()`: ``` php -[[= include_file('code_samples/api/migration/src/Command/MigrationCommand.php', 42, 44) =]] +[[= include_file('code_samples/api/migration/src/Command/MigrationCommand.php', 36, 38) =]] ``` Both `executeOne()` and `executeAll()` can take an optional parameter: the login of the User that you want to execute the migrations as. @@ -35,5 +35,5 @@ Both `executeOne()` and `executeAll()` can take an optional parameter: the login To add a new migration file, use the `MigrationService:add()` method: ``` php -[[= include_file('code_samples/api/migration/src/Command/MigrationCommand.php', 28, 34) =]] +[[= include_file('code_samples/api/migration/src/Command/MigrationCommand.php', 22, 28) =]] ``` diff --git a/docs/content_management/forms/form_api.md b/docs/content_management/forms/form_api.md index c0c9930445..925f089962 100644 --- a/docs/content_management/forms/form_api.md +++ b/docs/content_management/forms/form_api.md @@ -14,13 +14,13 @@ To manage form submissions created in the [Form Builder](form_builder_guide.md), To get existing form submissions, use `FormSubmissionServiceInterface::loadByContent()` (which takes a `ContentInfo` object as parameter), or `FormSubmissionServiceInterface::loadById()`. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 54, 55) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 46, 46) =]] ``` Through this object, you can get information about submissions, such as their total number, and submission contents. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 55, 66) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 48, 56) =]] ``` ### Creating form submissions @@ -35,7 +35,7 @@ This method takes: - the array of form field values ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 40, 53) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 32, 44) =]] ``` ### Deleting form submissions @@ -43,5 +43,5 @@ This method takes: You can delete a form submission by using the `FormSubmissionServiceInterface::delete()` method. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 66, 68) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FormSubmissionCommand.php', 58, 59) =]] ``` diff --git a/docs/content_management/taxonomy/taxonomy_api.md b/docs/content_management/taxonomy/taxonomy_api.md index 3a46b2322f..aa5f85e69c 100644 --- a/docs/content_management/taxonomy/taxonomy_api.md +++ b/docs/content_management/taxonomy/taxonomy_api.md @@ -14,7 +14,7 @@ Or pass entry identifier (with optionally a taxonomy identifier), and use `TaxonomyServiceInterface::loadEntryByIdentifier()`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 43, 46) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 35, 37) =]] ``` !!! note @@ -37,7 +37,7 @@ The default taxonomy identifier is given by `TaxonomyConfiguration::getDefaultTa The default limit is 30. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 41, 42) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 33, 33) =]] ``` To see how many entries is there, use `TaxonomyServiceInterface::countAllEntries()` with optionally a taxonomy identifier. @@ -47,7 +47,7 @@ provide it with the entry object, and optionally specify the limit of results an The default limit is 30: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 48, 53) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 40, 44) =]] ``` ## Managing taxonomy entries @@ -56,7 +56,7 @@ You can move a taxonomy entry to a different parent by using `TaxonomyServiceInt Provide the method with two objects: the entry that you want to move and the new parent entry: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 54, 58) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 46, 49) =]] ``` You can also move a taxonomy entry by passing its target sibling entry to `TaxonomyServiceInterface::moveEntry()`. @@ -64,7 +64,7 @@ The method takes as parameters the entry you want to move, the future sibling, and a `position` parameter, which is either `TaxonomyServiceInterface::MOVE_POSITION_NEXT` or `TaxonomyServiceInterface::MOVE_POSITION_PREV`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 59, 61) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/TaxonomyCommand.php', 51, 52) =]] ``` !!! note diff --git a/docs/content_management/url_management/url_api.md b/docs/content_management/url_management/url_api.md index 94d93a1476..cc8188c003 100644 --- a/docs/content_management/url_management/url_api.md +++ b/docs/content_management/url_management/url_api.md @@ -19,9 +19,9 @@ in which you need to specify: ```php // ... -[[= include_file('code_samples/api/public_php_api/src/Command/FindUrlCommand.php', 7, 10) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindUrlCommand.php', 6, 10) =]] // ... -[[= include_file('code_samples/api/public_php_api/src/Command/FindUrlCommand.php', 41, 56) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindUrlCommand.php', 32, 51) =]] ``` ## URL search reference diff --git a/docs/content_management/workflow/workflow_api.md b/docs/content_management/workflow/workflow_api.md index d6c46a6975..157d436373 100644 --- a/docs/content_management/workflow/workflow_api.md +++ b/docs/content_management/workflow/workflow_api.md @@ -25,7 +25,7 @@ but the implementation in workflow service extends them, for example by providin To get information about a specific workflow for a content item, use `WorkflowServiceInterface::loadWorkflowMetadataForContent`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 58, 63) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 49, 53) =]] ``` !!! tip @@ -36,7 +36,7 @@ To get information about a specific workflow for a content item, use `WorkflowSe To get a list of all workflows that can be used for a given content item, use `WorkflowRegistry`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 52, 53) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 43, 46) =]] ``` ## Applying workflow transitions @@ -44,14 +44,14 @@ To get a list of all workflows that can be used for a given content item, use `W To place a content item in a workflow, use `WorkflowService::start`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 57, 58) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 48, 48) =]] ``` To apply a transition to a content item, use `Workflow::apply`. Additionally, you can check if the transition is possible for the given object using `WorkflowService::can`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 64, 69) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/WorkflowCommand.php', 55, 59) =]] ``` !!! tip diff --git a/docs/multisite/languages/language_api.md b/docs/multisite/languages/language_api.md index 7b5f850fcc..c7db05ce2c 100644 --- a/docs/multisite/languages/language_api.md +++ b/docs/multisite/languages/language_api.md @@ -11,7 +11,7 @@ You can manage languages configured in the system with PHP API by using [`Langua To get a list of all languages in the system use [`LanguageService::loadLanguages`:](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LanguageService.html#method_loadLanguage) ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/AddLanguageCommand.php', 42, 47) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/AddLanguageCommand.php', 29, 35) =]] ``` ## Creating a language @@ -20,5 +20,5 @@ To create a new language, you need to create a [`LanguageCreateStruct`](/api/php Then, use [`LanguageService::createLanguage`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-LanguageService.html#method_createLanguage) and pass the `LanguageCreateStruct` to it: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/AddLanguageCommand.php', 48, 52) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/AddLanguageCommand.php', 34, 39) =]] ``` diff --git a/docs/pim/catalog_api.md b/docs/pim/catalog_api.md index 2caa8d2ede..763bba807a 100644 --- a/docs/pim/catalog_api.md +++ b/docs/pim/catalog_api.md @@ -11,7 +11,7 @@ To get information about product catalogs and manage them, use `CatalogServiceIn To get a single catalog, use `Ibexa\Contracts\ProductCatalog\CatalogServiceInterface::getCatalog()` and provide it with catalog ID, or `CatalogServiceInterface::getCatalogByIdentifier()` and pass the identifier: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/CatalogCommand.php', 81, 83) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/CatalogCommand.php', 58, 60) =]] ``` ## Get products in catalog @@ -20,7 +20,7 @@ To get products from a catalog, request the product query from the catalog objec Then, create a new `ProductQuery` based on it and run a product search with `ProductServiceInterface::findProduct()`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/CatalogCommand.php', 85, 91) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/CatalogCommand.php', 62, 68) =]] ``` ## Create catalog @@ -29,7 +29,7 @@ To create a catalog, you need to prepare a `CatalogCreateStruct` that contains: Then, pass this struct to `CatalogServiceInterface::createCatalog()`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/CatalogCommand.php', 71, 79) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/CatalogCommand.php', 48, 56) =]] ``` ## Update catalog @@ -39,5 +39,5 @@ You must pass the catalog object and a `CatalogUpdateStruct` to the method. In the following example, you update the catalog to publish it: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/CatalogCommand.php', 93, 97) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/CatalogCommand.php', 70, 74) =]] ``` diff --git a/docs/pim/price_api.md b/docs/pim/price_api.md index 6d26b2cee5..de75960938 100644 --- a/docs/pim/price_api.md +++ b/docs/pim/price_api.md @@ -12,13 +12,13 @@ To access a currency object by its code, use `CurrencyServiceInterface::getCurre To access a whole list of currencies, use `CurrencyServiceInterface::findCurrencies`. ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/CurrencyCommand.php', 52, 61) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/CurrencyCommand.php', 34, 42) =]] ``` To create a new currency, use `CurrencyServiceInterface::createCurrency()` and provide it with a `CurrencyCreateStruct` with code, number of fractional digits and a flag indicating if the currency is enabled: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/CurrencyCommand.php', 67, 71) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/CurrencyCommand.php', 50, 53) =]] ``` ## Prices @@ -28,19 +28,19 @@ To manage prices, use `ProductPriceService`. To retrieve the price of a product in the currency for the current context, use `Product::getPrice()`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 79, 82) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 50, 53) =]] ``` To retrieve the price of a product in a specific currency, use `ProductPriceService::getPriceByProductAndCurrency`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 83, 86) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 54, 57) =]] ``` To get all prices (in different currencies) for a given product, use `ProductPriceService::findPricesByProductCode`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 97, 103) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 68, 74) =]] ``` To load price definitions that match given criteria, use `ProductPriceServiceInterface::findPrices`: @@ -48,14 +48,14 @@ To load price definitions that match given criteria, use `ProductPriceServiceInt ``` php [[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 12, 16) =]] // ... -[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 104, 114) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 75, 85) =]] ``` You can also use `ProductPriceService` to create or modify existing prices. For example, to create a new price for a given currency, use `ProductPriceService::createProductPrice` and provide it with a `ProductPriceCreateStruct` object: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 79, 85) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 61, 65) =]] ``` !!! note @@ -80,7 +80,7 @@ To resolve a price of a product in the currency for the current context, use eit ``` php [[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 7, 8) =]][[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 11, 12) =]] // ... -[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 115, 119) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductPriceCommand.php', 86, 90) =]] ``` ## VAT @@ -89,17 +89,17 @@ To get information about the VAT categories and rates configured in the system, VAT is configured per region, so you also need to use `RegionServiceInterface` to get the relevant region object. ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/VatCommand.php', 54, 55) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/VatCommand.php', 33, 34) =]] ``` To get information about all VAT categories configured for the selected region, use `VatServiceInterface::getVatCategories()`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/VatCommand.php', 56, 61) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/VatCommand.php', 34, 40) =]] ``` To get a single VAT category, use `VatServiceInterface::getVatCategoryByIdentifier()` and provide it with the region object and the identifier of the VAT category: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/VatCommand.php', 62, 64) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/VatCommand.php', 41, 42) =]] ``` diff --git a/docs/pim/product_api.md b/docs/pim/product_api.md index e2cb59219c..5418115dea 100644 --- a/docs/pim/product_api.md +++ b/docs/pim/product_api.md @@ -21,7 +21,7 @@ month_change: false Get an individual product by using the `ProductServiceInterface::getProduct()` method: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 73, 76) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 43, 46) =]] ``` Find multiple products with `ProductServiceInterface::findProducts()`. @@ -29,7 +29,7 @@ Find multiple products with `ProductServiceInterface::findProducts()`. Provide the method with optional filter, query or Sort Clauses. ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 77, 87) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 46, 57) =]] ``` See [Product Search Criteria](product_search_criteria.md) and [Product Sort Clauses](product_sort_clauses.md) references for more information about how to use the [`ProductQuery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-Product-ProductQuery.html) class. @@ -39,7 +39,7 @@ See [Product Search Criteria](product_search_criteria.md) and [Product Sort Clau To create, update and delete products, use the `LocalProductServiceInterface`. ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 98, 102) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 68, 72) =]] ``` To create a product, use `LocalProductServiceInterface::newProductCreateStruct()` to get a [`ProductCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Local-Values-Product-ProductCreateStruct.html). @@ -47,13 +47,13 @@ Provide the method with the product type object and the main language code. You also need to set (at least) the code for the product and the required Field of the underlying content type, `name`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 88, 95) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 58, 65) =]] ``` To delete a product, use `LocalProductServiceInterface::deleteProduct()`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 125, 126) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 95, 96) =]] ``` ### Product variants @@ -65,13 +65,13 @@ A `ProductVariantQuery` lets you define the offset and limit of the variant quer The default offset is 0, and limit is 25. ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 62, 65) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 40, 43) =]] ``` From a variant ([`ProductVariantInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-ProductVariantInterface.html)), you can access the attributes that are used to generate the variant by using `ProductVariantInterface::getDiscriminatorAttributes()`. ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 66, 73) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 44, 51) =]] ``` #### Creating variants @@ -81,7 +81,7 @@ This method takes the product and an array of [`ProductVariantCreateStruct`](/ap `ProductVariantCreateStruct` specifies the attribute values and the code for the new variant. ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 75, 81) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductVariantCommand.php', 53, 60) =]] ``` ### Product assets @@ -91,14 +91,14 @@ You can get assets assigned to a product by using [`AssetServiceInterface`](/api Use `AssetServiceInterface` to get a single asset by providing the product object and the assets's ID as parameters: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductAssetCommand.php', 59, 61) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductAssetCommand.php', 37, 40) =]] ``` To get all assets assigned to a product, use `AssetServiceInterface::findAssets()`. You can retrieve the tags (corresponding to attribute values) of assets with the `AssetInterface::getTags()` method: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductAssetCommand.php', 62, 71) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductAssetCommand.php', 40, 49) =]] ``` ## Product types @@ -108,13 +108,13 @@ To work with product types, use [`ProductTypeServiceInterface`](/api/php_api/php Get a product type object by using `ProductTypeServiceInterface::getProductType()`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 48, 49) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 31, 32) =]] ``` You can also get a list of product types with `ProductTypeServiceInterface::findProductTypes()`: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 52, 57) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductTypeCommand.php', 35, 40) =]] ``` ## Product availability @@ -128,14 +128,14 @@ Get the availability object with `ProductAvailabilityServiceInterface::getAvaila You can then use `ProductAvailabilityServiceInterface::getStock()` to get the stock number for the product: ```php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 109, 114) =]] } +[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 79, 84) =]] } ``` To change availability for a product, use `ProductAvailabilityServiceInterface::updateProductAvailability()` with a [`ProductAvailabilityUpdateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-Availability-ProductAvailabilityUpdateStruct.html) and provide it with the product object. The second parameter defines whether product is available, and the third whether its stock is infinite. The fourth parameter is the stock number: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 117, 120) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/ProductCommand.php', 87, 90) =]] ``` ## Attributes @@ -146,24 +146,24 @@ To get information about product attribute groups, use the [`AttributeGroupServi `AttributeGroupServiceInterface::findAttributeGroups()` gets attribute groups, all of them or filtered with an optional [`AttributeGroupQuery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Values-AttributeGroup-AttributeGroupQuery.html) object: ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 75, 76) =]] -[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 96, 102) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 47, 48) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 68, 73) =]] ``` To create an attribute group, use `LocalAttributeGroupServiceinterface::createAttributeGroup()` and provide it with an [`AttributeGroupCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Local-Values-AttributeGroup-AttributeGroupCreateStruct.html): ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 69, 75) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 42, 46) =]] ``` To get information about product attributes, use the [`AttributeDefinitionServiceInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-AttributeDefinitionServiceInterface.html), or [`LocalAttributeDefinitionServiceInterface`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Local-LocalAttributeDefinitionServiceInterface.html) to modify attributes. ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 81, 85) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 54, 56) =]] ``` To create an attribute, use `LocalAttributeGroupServiceinterface::createAttributeDefinition()` and provide it with an [`AttributeDefinitionCreateStruct`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-ProductCatalog-Local-Values-AttributeDefinition-AttributeDefinitionCreateStruct.html): ``` php -[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 86, 94) =]] +[[= include_file('code_samples/api/product_catalog/src/Command/AttributeCommand.php', 59, 65) =]] ``` diff --git a/docs/search/search_api.md b/docs/search/search_api.md index 47238e952d..0de5fabc5c 100644 --- a/docs/search/search_api.md +++ b/docs/search/search_api.md @@ -22,18 +22,15 @@ The service should be [injected into the constructor of your command or controll To search through content you need to create a [`LocationQuery`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-Values-Content-LocationQuery.html) and provide your Search Criteria as a series of Criterion objects. -For example, to search for all content of a selected content type, use one Criterion, [`Criterion\ContentTypeIdentifier`](contenttypeidentifier_criterion.md) (line 14). +For example, to search for all content of a selected content type, use one Criterion, [`Criterion\ContentTypeIdentifier`](contenttypeidentifier_criterion.md) (line 12). The following command takes the content type identifier as an argument and lists all results: -``` php hl_lines="14 16" -// ... -[[= include_file('code_samples/api/public_php_api/src/Command/FindContentCommand.php', 4, 7) =]]// ... -[[= include_file('code_samples/api/public_php_api/src/Command/FindContentCommand.php', 16, 18) =]] // ... -[[= include_file('code_samples/api/public_php_api/src/Command/FindContentCommand.php', 36, 52) =]]} +``` php hl_lines="25 28-31" +[[= include_file('code_samples/api/public_php_api/src/Command/FindContentCommand.php') =]] ``` -[`SearchService::findContentInfo`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-SearchService.html#method_findContentInfo) (line 16) +[`SearchService::findContentInfo`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-SearchService.html#method_findContentInfo) (line 14) retrieves [`ContentInfo`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Persistence-Content-ContentInfo.html) objects of the found content items. You can also use [`SearchService::findContent`](/api/php_api/php_api_reference/classes/Ibexa-Contracts-Core-Repository-SearchService.html#method_findContent) to get full Content objects, together with their field information. @@ -116,19 +113,14 @@ It doesn't use the `SearchService` and isn't based on indexed data. For example, the following command lists all content items under the specified parent location and sorts them by name in descending order: -``` php hl_lines="13-16" -// ... -[[= include_file('code_samples/api/public_php_api/src/Command/FilterCommand.php', 4, 9) =]] -// ... -[[= include_file('code_samples/api/public_php_api/src/Command/FilterCommand.php', 37, 57) =]] +``` php hl_lines="26 29-34" +[[= include_file('code_samples/api/public_php_api/src/Command/FilterCommand.php') =]] ``` The same Filter can be applied to find locations instead of content items, for example: -``` php hl_lines="17" -// ... -[[= include_file('code_samples/api/public_php_api/src/Command/FilterLocationCommand.php', 4, 9) =]]// ... -[[= include_file('code_samples/api/public_php_api/src/Command/FilterLocationCommand.php', 37, 57) =]] +``` php hl_lines="26 29-34" +[[= include_file('code_samples/api/public_php_api/src/Command/FilterLocationCommand.php') =]] ``` !!! caution @@ -178,20 +170,16 @@ $filter You can use the `SearchService` or repository filtering in a controller, as long as you provide the required parameters. For example, in the code below, `locationId` is provided to list all children of a location by using the `SearchService`. -``` php hl_lines="22-24" -// ... -[[= include_file('code_samples/api/public_php_api/src/Controller/CustomController.php', 4, 12) =]] // ... -[[= include_file('code_samples/api/public_php_api/src/Controller/CustomController.php', 19, 35) =]] +``` php hl_lines="19-20 22 28-30" +[[= include_file('code_samples/api/public_php_api/src/Controller/CustomController.php') =]] ``` -The rendering of results is then relegated to [templates](templates.md) (lines 22-24). +The rendering of results is then relegated to [templates](templates.md). When using Repository filtering, provide the results of `ContentService::find()` as parameters to the view: -``` php hl_lines="19" -// ... -[[= include_file('code_samples/api/public_php_api/src/Controller/CustomFilterController.php', 4, 12) =]] // ... -[[= include_file('code_samples/api/public_php_api/src/Controller/CustomFilterController.php', 19, 34) =]] +``` php hl_lines="23-27" +[[= include_file('code_samples/api/public_php_api/src/Controller/CustomFilterController.php') =]] ``` ### Paginating search results @@ -199,10 +187,7 @@ When using Repository filtering, provide the results of `ContentService::find()` To paginate search or filtering results, it's recommended to use the [Pagerfanta library](https://github.com/BabDev/Pagerfanta) and [[[= product_name =]]'s adapters for it.](https://github.com/ibexa/core/blob/main/src/lib/Pagination/Pagerfanta/Pagerfanta.php) ``` php -// ... [[= include_file('code_samples/api/public_php_api/src/Controller/PaginationController.php', 8, 15) =]] // ... -[[= include_file('code_samples/api/public_php_api/src/Controller/PaginationController.php', 22, 32) =]] -[[= include_file('code_samples/api/public_php_api/src/Controller/PaginationController.php', 33, 43) =]] ``` Pagination can then be rendered for example using the following template: @@ -237,23 +222,25 @@ For more information and examples, see [PagerFanta documentation](https://www.ba For more complex searches, you need to combine multiple Criteria. You can do it using logical operators: `LogicalAnd`, `LogicalOr`, and `LogicalNot`. -``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 48, 54) =]][[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 58, 59) =]] -[[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 65, 70) =]] +``` php hl_lines="3-7 10" +[[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 30, 31) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 32, 36) =]][[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 39, 40) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 46, 51) =]] ``` This example takes three parameters from a command — `$text`, `$contentTypeId`, and `$locationId`. It then combines them using `Criterion\LogicalAnd` to search for content items -that belong to a specific subtree, have the chosen content type and contain the provided text (lines 3-6). +that belong to a specific subtree, have the chosen content type and contain the provided text. -This also shows that you can get the total number of search results using the `totalCount` property of search results (line 9). +This also shows that you can get the total number of search results using the `totalCount` property of search results. You can also nest different operators to construct more complex queries. The example below uses the `LogicalNot` operator to search for all content containing a given phrase that doesn't belong to the provided Section: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 50, 51) =]][[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 53, 58) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 36, 39) =]] + ``` ### Combining independent Criteria @@ -286,7 +273,7 @@ To sort the results of a query, use one of more [Sort Clauses](sort_clause_refer For example, to order search results by their publicationg date, from oldest to newest, and then alphabetically by content name, add the following Sort Clauses to the query: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 60, 64) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindComplexCommand.php', 41, 45) =]] ``` !!! tip @@ -305,7 +292,7 @@ For a list of supported Criteria and Sort Clauses, see [Search in trash referenc Searching through the trashed content items operates directly on the database, therefore you cannot use external search engines, such as Solr or Elasticsearch, and it's impossible to reindex the data. ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FindInTrashCommand.php', 39, 46) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindInTrashCommand.php', 25, 32) =]] ``` !!! caution @@ -324,7 +311,7 @@ With aggregations you can find the count of search results or other result infor To do this, you use of the query's `$aggregations` property: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 39, 44) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 28, 33) =]] ``` The name of the aggregation must be unique in the given query. @@ -332,13 +319,13 @@ The name of the aggregation must be unique in the given query. Access the results by using the `get()` method of the aggregation: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 48, 49) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 37, 38) =]] ``` Aggregation results contain the name of the result and the count of found items: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 51, 54) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 40, 43) =]] ``` With field aggregations you can group search results according to the value of a specific field. @@ -347,14 +334,14 @@ In this case the aggregation takes the content type identifier and the field ide The following example creates an aggregation named `selection` that groups results according to the value of the `topic` field in the `article` content type: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 44, 45) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 33, 34) =]] ``` With term aggregation you can define additional limits to the results. The following example limits the number of terms returned to 5 and only considers terms that have 10 or more results: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 39, 42) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/FindWithAggregationCommand.php', 28, 31) =]] ``` To use a range aggregation, you must provide a `ranges` array containing a set of `Range` objects that define the borders of the specific range sets. diff --git a/docs/users/oauth_client.md b/docs/users/oauth_client.md index 47e741d2e5..393f0f0039 100644 --- a/docs/users/oauth_client.md +++ b/docs/users/oauth_client.md @@ -84,11 +84,11 @@ The following example shows how to create a Resource Owner mapper for the `googl Create a resource owner mapper for Google login in `src/OAuth/GoogleResourceOwnerMapper.php`. The mapper extends `ResourceOwnerToExistingOrNewUserMapper`, which enables it to create a new user in the repository if the user doesn't exist yet. -The mapper loads a user (line 51) or creates a new one (line 61), based on the information from `resourceOwner`, that's the OAuth2 authorization server. +The mapper loads a user (line 40) or creates a new one (line 49), based on the information from `resourceOwner`, that's the OAuth2 authorization server. -The new username is set with a `google:` prefix (lines 19, 109), to avoid conflicts with users registered in a regular way. +The new username is set with a `google:` prefix (lines 20, 91), to avoid conflicts with users registered in a regular way. -``` php hl_lines="20 54 64 109" +``` php hl_lines="20 40 67 91" [[= include_file('code_samples/user_management/oauth_google/src/OAuth/GoogleResourceOwnerMapper.php') =]] ``` diff --git a/docs/users/segment_api.md b/docs/users/segment_api.md index a025b2ebe7..749aecd82f 100644 --- a/docs/users/segment_api.md +++ b/docs/users/segment_api.md @@ -15,13 +15,13 @@ To load a segment group, use `SegmentationService::loadSegmentGroupByIdentifier( Get all segments assigned to the group with `SegmentationService::loadSegmentsAssignedToGroup()`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 54, 62) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 46, 52) =]] ``` Similarly, you can load a segment by using `SegmentationService::loadSegmentByIdentifier()`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 62, 63) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 54, 54) =]] ``` ## Checking assignment @@ -29,7 +29,7 @@ Similarly, you can load a segment by using `SegmentationService::loadSegmentById You can check whether a user is assigned to a segment with `SegmentationService::isUserAssignedToSegment()`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 66, 71) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 58, 62) =]] ``` ## Assigning users @@ -37,7 +37,7 @@ You can check whether a user is assigned to a segment with `SegmentationService: To assign a user to a segment, use `SegmentationService::assignUserToSegment()`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 64, 65) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 56, 56) =]] ``` ## Creating segments @@ -47,13 +47,13 @@ Each segment must be assigned to a segment group. To create a segment group, use `SegmentationService::createSegmentGroup()` and provide it with a `SegmentGroupCreateStruct`: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 38, 45) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 30, 36) =]] ``` To add a segment, use `SegmentationService::createSegment()` and provide it with a `SegmentCreateStruct`, which takes an existing group as one of the parameters: ``` php -[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 46, 53) =]] +[[= include_file('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 38, 44) =]] ``` ## Updating segments diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index c19c052141..94b21757c7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -54,18 +54,6 @@ parameters: count: 1 path: code_samples/api/public_php_api/src/Command/CalendarCommand.php - - - message: '#^Variable \$copyIdentifier might not be defined\.$#' - identifier: variable.undefined - count: 3 - path: code_samples/api/public_php_api/src/Command/CreateContentTypeCommand.php - - - - message: '#^Parameter \#1 \$messages of method Symfony\\Component\\Console\\Output\\OutputInterface\:\:writeln\(\) expects iterable\\|string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: code_samples/api/public_php_api/src/Command/FilterLocationCommand.php - - message: '#^Access to protected property Ibexa\\Contracts\\Core\\Repository\\Values\\URL\\URL\:\:\$url\.$#' identifier: property.protected @@ -288,18 +276,6 @@ parameters: count: 1 path: code_samples/back_office/search/src/EventSubscriber/MySuggestionEventSubscriber.php - - - message: '#^Parameter \#2 \$string of function explode expects string, string\|null given\.$#' - identifier: argument.type - count: 1 - path: code_samples/back_office/search/src/EventSubscriber/MySuggestionEventSubscriber.php - - - - message: '#^Method App\\Setting\\Group\\MyGroup\:\:__construct\(\) has parameter \$values with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: code_samples/back_office/settings/src/Setting/Group/MyGroup.php - - message: '#^Method App\\Setting\\Unit\:\:mapFieldForm\(\) has parameter \$formBuilder with generic interface Symfony\\Component\\Form\\FormBuilderInterface but does not specify its types\: TData$#' identifier: missingType.generics @@ -456,12 +432,6 @@ parameters: count: 1 path: code_samples/field_types/generic_ft/src/Form/Type/HelloWorldType.php - - - message: '#^Method App\\FormBuilder\\FieldType\\Field\\Mapper\\CheckboxWithRichtextDescriptionFieldMapper\:\:mapFormOptions\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: code_samples/forms/custom_form_attribute/src/FormBuilder/FieldType/Field/Mapper/CheckboxWithRichtextDescriptionFieldMapper.php - - message: '#^Class App\\FormBuilder\\Form\\Type\\CheckboxWithRichtextDescriptionType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#' identifier: missingType.generics @@ -474,12 +444,6 @@ parameters: count: 1 path: code_samples/forms/custom_form_attribute/src/FormBuilder/Form/Type/FieldAttribute/AttributeRichtextDescriptionType.php - - - message: '#^Method App\\FormBuilder\\Field\\Mapper\\CountryFieldMapper\:\:mapFormOptions\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: code_samples/forms/custom_form_field/src/FormBuilder/Field/Mapper/CountryFieldMapper.php - - message: '#^Method App\\QueryType\\LatestContentQueryType\:\:getQuery\(\) has parameter \$parameters with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -642,30 +606,12 @@ parameters: count: 1 path: code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationResultExtractor.php - - - message: '#^Method App\\Query\\Aggregation\\Solr\\PriorityRangeAggregationResultExtractor\:\:canVisit\(\) has parameter \$languageFilter with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationResultExtractor.php - - - - message: '#^Method App\\Query\\Aggregation\\Solr\\PriorityRangeAggregationResultExtractor\:\:extract\(\) has parameter \$languageFilter with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationResultExtractor.php - - message: '#^Method App\\Query\\Aggregation\\Solr\\PriorityRangeAggregationVisitor\:\:formatRangeValue\(\) has parameter \$value with no type specified\.$#' identifier: missingType.parameter count: 1 path: code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationVisitor.php - - - message: '#^Method App\\Query\\Aggregation\\Solr\\PriorityRangeAggregationVisitor\:\:visit\(\) should return array\ but returns array\\>\|string\>\.$#' - identifier: return.type - count: 1 - path: code_samples/search/custom/src/Query/Aggregation/Solr/PriorityRangeAggregationVisitor.php - - message: '#^Method App\\Query\\Criterion\\Elasticsearch\\CameraManufacturerVisitor\:\:visit\(\) return type has no value type specified in iterable type array\.$#' identifier: missingType.iterableValue @@ -738,24 +684,12 @@ parameters: count: 1 path: code_samples/tutorials/page_tutorial_starting_point/src/QueryType/MenuQueryType.php - - - message: '#^Call to an undefined method Symfony\\Component\\Security\\Core\\User\\UserProviderInterface\\:\:loadUserByUsername\(\)\.$#' - identifier: method.notFound - count: 2 - path: code_samples/user_management/oauth_google/src/OAuth/GoogleResourceOwnerMapper.php - - message: '#^Parameter \#2 \$email of method Ibexa\\Contracts\\OAuth2Client\\Repository\\OAuth2UserService\:\:newOAuth2UserCreateStruct\(\) expects string, string\|null given\.$#' identifier: argument.type count: 1 path: code_samples/user_management/oauth_google/src/OAuth/GoogleResourceOwnerMapper.php - - - message: '#^Offset ''data'' might not exist on array\|null\.$#' - identifier: offsetAccess.notFound - count: 1 - path: code_samples/workflow/custom_workflow/src/EventListener/LegalTransitionListener.php - - message: '#^Parameter \#2 \$transition of method Ibexa\\Contracts\\Workflow\\Event\\Action\\AbstractTransitionWorkflowActionListener\:\:getActionMetadata\(\) expects Symfony\\Component\\Workflow\\Transition, Symfony\\Component\\Workflow\\Transition\|null given\.$#' identifier: argument.type diff --git a/rector.php b/rector.php new file mode 100644 index 0000000000..571c2cf6bb --- /dev/null +++ b/rector.php @@ -0,0 +1,29 @@ +withPaths([ + __DIR__ . '/code_samples', + ]) + ->withPhpSets() + ->withSets([ + IbexaSetList::IBEXA_50->value, + SymfonySetList::SYMFONY_60, + SymfonySetList::SYMFONY_61, + SymfonySetList::SYMFONY_62, + SymfonySetList::SYMFONY_63, + SymfonySetList::SYMFONY_64, + SymfonySetList::SYMFONY_70, + SymfonySetList::SYMFONY_71, + SymfonySetList::SYMFONY_72, + SymfonySetList::SYMFONY_73, + ]);