Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions code_samples/collaboration/config/services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
parameters:

services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/'

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones

App\Collaboration\Cart\Persistence\Gateway\DatabaseGateway:
arguments:
$connection: '@ibexa.persistence.connection'
tags:
- name: 'ibexa.collaboration.persistence.session.gateway'
discriminator: !php/const App\Collaboration\Cart\Persistence\Gateway\DatabaseGateway::DISCRIMINATOR

App\Collaboration\Cart\Persistence\Mapper:
tags:
- name: 'ibexa.collaboration.persistence.session.mapper'
discriminator: !php/const App\Collaboration\Cart\Persistence\Gateway\DatabaseGateway::DISCRIMINATOR

App\Collaboration\Cart\Mapper\CartSessionDomainMapper:
tags:
- name: 'ibexa.collaboration.service.session.domain.mapper'
type: App\Collaboration\Cart\Persistence\Values\CartSession

App\Collaboration\Cart\Mapper\CartSessionPersistenceMapper:
tags:
- name: 'ibexa.collaboration.service.session.persistence.mapper'
type: !php/const App\Collaboration\Cart\CartSessionType::IDENTIFIER

App\Collaboration\Cart\PermissionResolverDecorator:
decorates: Ibexa\Contracts\ProductCatalog\PermissionResolverInterface

App\Collaboration\Cart\CartResolverDecorator:
decorates: Ibexa\Contracts\Cart\CartResolverInterface
7 changes: 7 additions & 0 deletions code_samples/collaboration/ibexa_collaboration_cart.mysql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE ibexa_collaboration_cart (
id INT NOT NULL PRIMARY KEY,
cart_identifier VARCHAR(255) NOT NULL,
CONSTRAINT ibexa_collaboration_cart_ibexa_collaboration_id_fk
FOREIGN KEY (id) REFERENCES ibexa_collaboration (id)
ON DELETE CASCADE
) COLLATE = utf8mb4_general_ci;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE ibexa_collaboration_cart (
id INTEGER NOT NULL PRIMARY KEY,
cart_identifier VARCHAR(255) NOT NULL,

Check warning on line 3 in code_samples/collaboration/ibexa_collaboration_cart.postgresql.sql

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use VARCHAR2 instead of VARCHAR.

See more on https://sonarcloud.io/project/issues?id=ezsystems_developer-documentation&issues=AZzR-IRx4HV4zSmyrryr&open=AZzR-IRx4HV4zSmyrryr&pullRequest=3078
CONSTRAINT ibexa_collaboration_cart_ibexa_collaboration_id_fk
FOREIGN KEY (id) REFERENCES ibexa_collaboration (id)
ON DELETE CASCADE
);
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart;

Expand All @@ -15,7 +9,7 @@
use Ibexa\Contracts\Core\Repository\Values\User\User;
use Symfony\Component\HttpFoundation\RequestStack;

final class CartResolverDecorator implements CartResolverInterface
final readonly class CartResolverDecorator implements CartResolverInterface
{
public function __construct(
private CartResolverInterface $innerCartResolver,
Expand Down Expand Up @@ -45,7 +39,7 @@ private function getSharedCart(): ?CartInterface
}

return $session->getCart();
} catch (NotFoundException|\Ibexa\ProductCatalog\Exception\UnauthorizedException $e) {
} catch (NotFoundException|\Ibexa\ProductCatalog\Exception\UnauthorizedException) {
return null;
}
}
Expand Down
14 changes: 2 additions & 12 deletions code_samples/collaboration/src/Collaboration/Cart/CartSession.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart;

Expand All @@ -16,22 +10,18 @@

final class CartSession extends AbstractSession
{
private CartInterface $cart;

public function __construct(
int $id,
CartInterface $cart,
private readonly CartInterface $cart,
string $token,
User $owner,
ParticipantCollectionInterface $participants,
bool $isActive,
bool $hasPublicLink,
DateTimeInterface $createdAt,
DateTimeInterface $updatedAt
) {

Check warning on line 23 in code_samples/collaboration/src/Collaboration/Cart/CartSession.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function has 8 parameters, which is greater than the 7 authorized.

See more on https://sonarcloud.io/project/issues?id=ezsystems_developer-documentation&issues=AZzSCWz3-1fHOE7RRFxu&open=AZzSCWz3-1fHOE7RRFxu&pullRequest=3078
parent::__construct($id, $token, $owner, $participants, $isActive, $hasPublicLink, $createdAt, $updatedAt);

$this->cart = $cart;
}

public function getCart(): CartInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart;

Expand All @@ -13,13 +7,9 @@

final class CartSessionCreateStruct extends AbstractSessionCreateStruct
{
private CartInterface $cart;

public function __construct(CartInterface $cart)
public function __construct(private CartInterface $cart)
{
parent::__construct();

$this->cart = $cart;
}

public function getCart(): CartInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart;

use Ibexa\Contracts\Collaboration\Session\SessionScopeInterface;

final class CartSessionType implements SessionScopeInterface
{
public const SCOPE_VIEW = 'view';
public const SCOPE_EDIT = 'edit';
public const string SCOPE_VIEW = 'view';
public const string SCOPE_EDIT = 'edit';

public const IDENTIFIER = 'cart';
public const string IDENTIFIER = 'cart';

private function __construct()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart\Mapper;

Expand All @@ -14,7 +8,7 @@
use Ibexa\Core\Repository\ProxyFactory\ProxyGeneratorInterface;
use ProxyManager\Proxy\LazyLoadingInterface;

final class CartProxyMapper implements CartProxyMapperInterface
final readonly class CartProxyMapper implements CartProxyMapperInterface
{
public function __construct(
private Repository $repository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart\Mapper;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart\Mapper;

Expand All @@ -20,7 +14,7 @@
* \App\Collaboration\Cart\Persistence\Values\CartSession
* >
*/
final class CartSessionDomainMapper implements SessionDomainMapperInterface
final readonly class CartSessionDomainMapper implements SessionDomainMapperInterface
{
public function __construct(
private CartProxyMapperInterface $cartProxyMapper,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart\Mapper;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart;

Expand All @@ -20,14 +14,14 @@

final class PermissionResolverDecorator implements PermissionResolverInterface
{
public const COLLABORATION_SESSION_ID = 'collaboration_session';
public const string COLLABORATION_SESSION_ID = 'collaboration_session';

private bool $nested = false;

public function __construct(
private PermissionResolverInterface $innerPermissionResolver,
private SessionServiceInterface $sessionService,
private RequestStack $requestStack,
private readonly PermissionResolverInterface $innerPermissionResolver,
private readonly SessionServiceInterface $sessionService,
private readonly RequestStack $requestStack,
) {
}

Expand Down Expand Up @@ -70,8 +64,8 @@
if ($session !== null) {
try {
return $cart->getId() === $session->getCart()->getId();
} catch (NotFoundException $e) {
} catch (NotFoundException) {
}

Check warning on line 68 in code_samples/collaboration/src/Collaboration/Cart/PermissionResolverDecorator.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Either remove or fill this block of code.

See more on https://sonarcloud.io/project/issues?id=ezsystems_developer-documentation&issues=AZzSCXMb-1fHOE7RRFxv&open=AZzSCXMb-1fHOE7RRFxv&pullRequest=3078
}
} finally {
$this->nested = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart\Persistence\Gateway;

Expand All @@ -30,7 +24,7 @@
*/
final class DatabaseGateway extends AbstractDoctrineDatabase implements GatewayInterface
{
public const DISCRIMINATOR = 'cart';
public const string DISCRIMINATOR = 'cart';

protected function buildMetadata(): DoctrineSchemaMetadataInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
<?php declare(strict_types=1);

namespace App\Collaboration\Cart\Persistence\Gateway;

final class DatabaseSchema
{
public const TABLE_NAME = 'ibexa_collaboration_cart';
public const string TABLE_NAME = 'ibexa_collaboration_cart';

public const COLUMN_ID = 'id';
public const COLUMN_CART_IDENTIFIER = 'cart_identifier';
public const string COLUMN_ID = 'id';
public const string COLUMN_CART_IDENTIFIER = 'cart_identifier';

private function __construct()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php declare(strict_types=1);

namespace App\Collaboration\Cart\Persistence;

use App\Collaboration\Cart\Persistence\Values\CartSession;
use Ibexa\Collaboration\Persistence\Session\Inner\MapperInterface;
use Ibexa\Collaboration\Persistence\Values\AbstractSession;

/**
* @phpstan-type TRow array{
* id: int,
* token: string,
* owner_id: int,
* is_active: bool,
* has_public_link: bool,
* created_at: \DateTimeImmutable,
* updated_at: \DateTimeImmutable,
* cart_cart_identifier: string,
* }
*
* @template-implements \Ibexa\Collaboration\Persistence\Session\Inner\MapperInterface<TRow>
*/
final class Mapper implements MapperInterface
{
public function extractFromRow(array $row): AbstractSession
{
return new CartSession(
$row['id'],
$row['cart_cart_identifier'],
$row['token'],
$row['owner_id'],
$row['is_active'],
$row['has_public_link'],
$row['created_at'],
$row['updated_at']
);
}
}
Loading
Loading