Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/node_modules/
/composer.lock

/.idea/

/etc/build/*
!/etc/build/.gitignore

Expand Down
15 changes: 12 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@
],
"license": "MIT",
"require": {
"php": "^7.4 || ^8.1",
"sherlockode/advanced-content-bundle": "^0.9.8",
"sylius/sylius": "^1.10"
"php": "^8.2",
"sherlockode/advanced-content-bundle": "^0.10",
"sylius/sylius": "^2.0",
"symfony/framework-bundle": "^7.4",
"symfony/form": "^7.4",
"symfony/twig-bundle": "^7.4",
"twig/twig": "^3.0"
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-sylius-2": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Sherlockode\\SyliusAdvancedContentPlugin\\": "src/"
Expand Down
66 changes: 14 additions & 52 deletions src/Command/ScopeInitCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\Command;

use Sherlockode\AdvancedContentBundle\Manager\ConfigurationManager;
Expand All @@ -12,87 +14,47 @@

class ScopeInitCommand extends Command
{
/**
* @var ConfigurationManager
*/
private $configurationManager;

/**
* @var TranslatorInterface
*/
private $translator;

/**
* @var ScopeInitializer
*/
private $scopeInitializer;

/**
* @param ConfigurationManager $configurationManager
* @param TranslatorInterface $translator
* @param ScopeInitializer $scopeInitializer
* @param $name
*/
public function __construct(
ConfigurationManager $configurationManager,
TranslatorInterface $translator,
ScopeInitializer $scopeInitializer,
$name = null
private readonly ConfigurationManager $configurationManager,
private readonly TranslatorInterface $translator,
private readonly ScopeInitializer $scopeInitializer,
) {
parent::__construct($name);
$this->configurationManager = $configurationManager;
$this->translator = $translator;
$this->scopeInitializer = $scopeInitializer;
parent::__construct();
}

protected function configure()
protected function configure(): void
{
$this
->setName('sherlockode:sylius-acb:init-scope')
->setDescription('Initialize sylius scopes for ACB')
;
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int|void
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);

if (!$this->configurationManager->isScopesEnabled()) {
$io->info($this->translator->trans('sherlockode_sylius_acb.scopes.disabled'));

if (defined(sprintf('%s::SUCCESS', get_class($this)))) {
return self::SUCCESS;
}
return;
return self::SUCCESS;
}

if (!$this->scopeInitializer->hasMissingScopes()) {
$io->info($this->translator->trans('sherlockode_sylius_acb.scopes.up_to_date'));

if (defined(sprintf('%s::SUCCESS', get_class($this)))) {
return self::SUCCESS;
}
return;
return self::SUCCESS;
}

try {
$this->scopeInitializer->init();
$io->success($this->translator->trans('sherlockode_sylius_acb.scopes.init_success'));
if (defined(sprintf('%s::SUCCESS', get_class($this)))) {
return self::SUCCESS;
}
return;

return self::SUCCESS;
} catch (\Exception $e) {
$io->error($e->getMessage());

if (defined(sprintf('%s::FAILURE', get_class($this)))) {
return self::FAILURE;
}
return self::FAILURE;
}
}
}
53 changes: 11 additions & 42 deletions src/Controller/PreviewController.php
Original file line number Diff line number Diff line change
@@ -1,60 +1,29 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\Controller;

use Sherlockode\AdvancedContentBundle\Scope\ScopeHandlerInterface;
use Sherlockode\SyliusAdvancedContentPlugin\Preview\ViewHandlerInterface;
use Sherlockode\SyliusAdvancedContentPlugin\Scope\ChannelLocaleScopeHandler;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Resource\Doctrine\Persistence\RepositoryInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class PreviewController extends AbstractController
{
/**
* @var ChannelLocaleScopeHandler
*/
private $channelLocaleScopeHandler;

/**
* @var RepositoryInterface
*/
private $pageRepository;

/**
* @var ViewHandlerInterface
*/
private $viewHandler;

/**
* @param ScopeHandlerInterface $channelLocaleScopeHandler
* @param RepositoryInterface $pageRepository
* @param ViewHandlerInterface $viewHandler
*/
public function __construct(
ScopeHandlerInterface $channelLocaleScopeHandler,
RepositoryInterface $pageRepository,
ViewHandlerInterface $viewHandler
private readonly ScopeHandlerInterface $channelLocaleScopeHandler,
private readonly RepositoryInterface $pageRepository,
private readonly ViewHandlerInterface $viewHandler,
) {
$this->channelLocaleScopeHandler = $channelLocaleScopeHandler;
$this->pageRepository = $pageRepository;
$this->viewHandler = $viewHandler;
}

/**
* @param Request $request
* @param string $pageIdentifier
*
* @return Response
*
* @throws \Exception
*/
public function previewAction(
Request $request,
string $pageIdentifier
): Response {
public function previewAction(Request $request, string $pageIdentifier): Response
{
$channelCode = $request->query->get('_channel_code');
$localeCode = $request->query->get('_locale');

Expand All @@ -67,7 +36,7 @@ public function previewAction(
throw new NotFoundHttpException(sprintf(
'Scope for channel "%s" and locale "%s" does not exists',
$channelCode,
$localeCode
$localeCode,
));
}

Expand All @@ -77,7 +46,7 @@ public function previewAction(
throw new NotFoundHttpException(sprintf(
'Page with scope for channel "%s" and locale "%s" does not exists',
$channelCode,
$localeCode
$localeCode,
));
}

Expand All @@ -86,7 +55,7 @@ public function previewAction(
if (!$template) {
throw new \Exception(sprintf(
'Cannot find any template for the page "%s" preview',
$page->getPageIdentifier()
$page->getPageIdentifier(),
));
}

Expand Down
37 changes: 6 additions & 31 deletions src/Controller/ScopeController.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,25 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\Controller;

use Sherlockode\AdvancedContentBundle\Manager\ConfigurationManager;
use Sherlockode\SyliusAdvancedContentPlugin\Scope\ScopeInitializer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;

class ScopeController extends AbstractController
{
/**
* @var ConfigurationManager
*/
private $configurationManager;

/**
* @var ScopeInitializer
*/
private $scopeInitializer;

/**
* @var TranslatorInterface
*/
private $translator;

/**
* @param ConfigurationManager $configurationManager
* @param ScopeInitializer $scopeInitializer
* @param TranslatorInterface $translator
*/
public function __construct(
ConfigurationManager $configurationManager,
ScopeInitializer $scopeInitializer,
TranslatorInterface $translator
private readonly ConfigurationManager $configurationManager,
private readonly ScopeInitializer $scopeInitializer,
private readonly TranslatorInterface $translator,
) {
$this->configurationManager = $configurationManager;
$this->scopeInitializer = $scopeInitializer;
$this->translator = $translator;
}

/**
* @return Response
*/
public function updateScopesAction()
public function updateScopesAction(): Response
{
if (!$this->configurationManager->isScopesEnabled()) {
$this->addFlash('error', $this->translator->trans('sherlockode_sylius_acb.scopes.disabled'));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down
2 changes: 2 additions & 0 deletions src/Entity/Content.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\Entity;

use Doctrine\Common\Collections\Collection;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/ContentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sherlockode\SyliusAdvancedContentPlugin\Entity;

use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Resource\Model\ResourceInterface;

interface ContentInterface extends ResourceInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Entity/ContentVersion.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\Entity;

use Sherlockode\AdvancedContentBundle\Model\ContentVersion as BaseContentVersion;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/ContentVersionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sherlockode\SyliusAdvancedContentPlugin\Entity;

use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Resource\Model\ResourceInterface;

interface ContentVersionInterface extends ResourceInterface
{
Expand Down
4 changes: 3 additions & 1 deletion src/Entity/Page.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\Entity;

use Doctrine\Common\Collections\Collection;
Expand All @@ -8,7 +10,7 @@
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Sherlockode\AdvancedContentBundle\Model\Page as BasePage;
use Sherlockode\AdvancedContentBundle\Model\PageVersionInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Resource\Model\ResourceInterface;

class Page extends BasePage implements PageInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/PageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sherlockode\SyliusAdvancedContentPlugin\Entity;

use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Resource\Model\ResourceInterface;

interface PageInterface extends ResourceInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Entity/PageMeta.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\Entity;

use Doctrine\Common\Collections\Collection;
Expand Down
2 changes: 1 addition & 1 deletion src/Entity/PageMetaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Sherlockode\SyliusAdvancedContentPlugin\Entity;

use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Resource\Model\ResourceInterface;

interface PageMetaInterface extends ResourceInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Entity/PageMetaVersion.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Sherlockode\SyliusAdvancedContentPlugin\Entity;

use Sherlockode\AdvancedContentBundle\Model\PageMetaVersion as BasePageMetaVersion;
Expand Down
Loading