File tree Expand file tree Collapse file tree 6 files changed +30
-8
lines changed
code_samples/collaboration/src Expand file tree Collapse file tree 6 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -35,12 +35,15 @@ public function resolveCart(?User $user = null): CartInterface
3535
3636 private function getSharedCart (): ?CartInterface
3737 {
38- /** @var \App\Collaboration\Cart\CartSession $session */
3938 try {
4039 $ session = $ this ->sessionService ->getSessionByToken (
4140 $ this ->requestStack ->getSession ()->get (PermissionResolverDecorator::COLLABORATION_SESSION_ID )
4241 );
4342
43+ if (!$ session instanceof CartSession) {
44+ return null ;
45+ }
46+
4447 return $ session ->getCart ();
4548 } catch (NotFoundException |\Ibexa \ProductCatalog \Exception \UnauthorizedException $ e ) {
4649 return null ;
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ public function createCartProxy(string $identifier): CartInterface
3333 &$ initializer
3434 ) use ($ identifier ): bool {
3535 $ initializer = null ;
36- $ wrappedObject = $ this ->repository ->sudo (fn () => $ this ->cartService ->getCart ($ identifier ));
36+ $ wrappedObject = $ this ->repository ->sudo (fn (): CartInterface => $ this ->cartService ->getCart ($ identifier ));
3737
3838 return true ;
3939 };
Original file line number Diff line number Diff line change @@ -25,12 +25,20 @@ final class CartSessionPersistenceMapper implements SessionPersistenceMapperInte
2525 public function toPersistenceCreateStruct (
2626 SessionCreateStruct $ createStruct
2727 ): PersistenceSessionCreateStruct {
28+ $ token = $ createStruct ->getToken ();
29+ $ owner = $ createStruct ->getOwner ();
30+ $ hasPublicLink = $ createStruct ->hasPublicLink ();
31+
32+ assert ($ token !== null );
33+ assert ($ owner !== null );
34+ assert ($ hasPublicLink !== null );
35+
2836 return new CartSessionCreateStruct (
29- $ createStruct -> getToken () ,
37+ $ token ,
3038 $ createStruct ->getCart ()->getIdentifier (),
31- $ createStruct -> getOwner () ->getUserId (),
39+ $ owner ->getUserId (),
3240 $ createStruct ->isActive (),
33- $ createStruct -> hasPublicLink () ,
41+ $ hasPublicLink ,
3442 new \DateTimeImmutable (),
3543 new \DateTimeImmutable ()
3644 );
Original file line number Diff line number Diff line change @@ -33,7 +33,8 @@ public function __construct(
3333
3434 public function canUser (PolicyInterface $ policy ): bool
3535 {
36- if ($ this ->nested === false && $ this ->isCartPolicy ($ policy ) && $ this ->isSharedCart ($ policy ->getObject ())) {
36+ $ object = $ policy ->getObject ();
37+ if ($ this ->nested === false && $ this ->isCartPolicy ($ policy ) && $ object instanceof CartInterface && $ this ->isSharedCart ($ object )) {
3738 return true ;
3839 }
3940
@@ -42,7 +43,8 @@ public function canUser(PolicyInterface $policy): bool
4243
4344 public function assertPolicy (PolicyInterface $ policy ): void
4445 {
45- if ($ this ->nested === false && $ this ->isCartPolicy ($ policy ) && $ this ->isSharedCart ($ policy ->getObject ())) {
46+ $ object = $ policy ->getObject ();
47+ if ($ this ->nested === false && $ this ->isCartPolicy ($ policy ) && $ object instanceof CartInterface && $ this ->isSharedCart ($ object )) {
4648 return ;
4749 }
4850
Original file line number Diff line number Diff line change 1414use Ibexa \Contracts \Cart \CartResolverInterface ;
1515use Ibexa \Contracts \Collaboration \Participant \ExternalParticipantCreateStruct ;
1616use Ibexa \Contracts \Collaboration \SessionServiceInterface ;
17+ use InvalidArgumentException ;
1718use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
1819use Symfony \Component \HttpFoundation \Request ;
1920use Symfony \Component \HttpFoundation \Response ;
@@ -52,10 +53,15 @@ public function __invoke(Request $request): Response
5253 new CartSessionCreateStruct ($ cart )
5354 );
5455
56+ $ email = $ data ->getEmail ();
57+ if ($ email === null ) {
58+ throw new InvalidArgumentException ('Email cannot be null ' );
59+ }
60+
5561 $ this ->sessionService ->addParticipant (
5662 $ session ,
5763 new ExternalParticipantCreateStruct (
58- $ data -> getEmail () ,
64+ $ email ,
5965 CartSessionType::SCOPE_EDIT
6066 )
6167 );
Original file line number Diff line number Diff line change 1414use Symfony \Component \Form \FormBuilderInterface ;
1515use Symfony \Component \OptionsResolver \OptionsResolver ;
1616
17+ /**
18+ * @extends AbstractType<ShareCartData>
19+ */
1720final class ShareCartType extends AbstractType
1821{
1922 public function buildForm (FormBuilderInterface $ builder , array $ options ): void
You can’t perform that action at this time.
0 commit comments