-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9a9dee7
Showing
601 changed files
with
76,662 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor/ | ||
composer.lock | ||
phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Storefront\Api\Entity\Dbal; | ||
|
||
use Shopware\Api\Entity\Dbal\EntityDefinitionQueryHelper; | ||
use Shopware\Api\Entity\Dbal\FieldResolver\FieldResolverInterface; | ||
use Shopware\Api\Entity\Dbal\QueryBuilder; | ||
use Shopware\Api\Entity\Field\Field; | ||
use Shopware\Context\Struct\ApplicationContext; | ||
use Shopware\Framework\Struct\Uuid; | ||
use Shopware\Storefront\Api\Entity\Field\CanonicalUrlAssociationField; | ||
use Shopware\Storefront\Api\Seo\Definition\SeoUrlDefinition; | ||
|
||
class CanonicalUrlAssociationFieldResolver implements FieldResolverInterface | ||
{ | ||
public function resolve( | ||
string $definition, | ||
string $root, | ||
Field $field, | ||
QueryBuilder $query, | ||
ApplicationContext $context, | ||
EntityDefinitionQueryHelper $queryHelper, | ||
bool $raw | ||
): void { | ||
if (!$field instanceof CanonicalUrlAssociationField) { | ||
return; | ||
} | ||
|
||
$table = SeoUrlDefinition::getEntityName(); | ||
$alias = $root . '.' . $field->getPropertyName(); | ||
|
||
if ($query->hasState($alias)) { | ||
return; | ||
} | ||
|
||
$query->addState($alias); | ||
|
||
$key = 'route' . $field->getRouteName(); | ||
|
||
$parameters = [ | ||
'#root#' => EntityDefinitionQueryHelper::escape($root), | ||
'#source_column#' => EntityDefinitionQueryHelper::escape($field->getStorageName()), | ||
'#alias#' => EntityDefinitionQueryHelper::escape($alias), | ||
'#reference_column#' => EntityDefinitionQueryHelper::escape($field->getReferenceField()), | ||
]; | ||
$query->leftJoin( | ||
EntityDefinitionQueryHelper::escape($root), | ||
EntityDefinitionQueryHelper::escape($table), | ||
EntityDefinitionQueryHelper::escape($alias), | ||
str_replace( | ||
array_keys($parameters), | ||
array_values($parameters), | ||
'#alias#.application_id = :applicationId | ||
AND #root#.#source_column# = #alias#.#reference_column# | ||
AND #alias#.name = :' . $key . ' | ||
AND #alias#.is_canonical = 1' | ||
) | ||
); | ||
$query->setParameter($key, $field->getRouteName()); | ||
$query->setParameter('applicationId', Uuid::fromStringToBytes($context->getApplicationId())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Storefront\Api\Entity\Field; | ||
|
||
use Shopware\Api\Entity\Field\ManyToOneAssociationField; | ||
use Shopware\Api\Entity\Write\Flag\Extension; | ||
use Shopware\Api\Entity\Write\Flag\ReadOnly; | ||
use Shopware\Storefront\Api\Seo\Definition\SeoUrlDefinition; | ||
|
||
class CanonicalUrlAssociationField extends ManyToOneAssociationField | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $routeName; | ||
|
||
public function __construct( | ||
string $propertyName, | ||
string $storageName, | ||
bool $loadInBasic, | ||
string $routeName | ||
) { | ||
parent::__construct($propertyName, $storageName, SeoUrlDefinition::class, $loadInBasic, 'foreign_key'); | ||
$this->setFlags(new ReadOnly(), new Extension()); | ||
$this->routeName = $routeName; | ||
} | ||
|
||
public function getRouteName(): string | ||
{ | ||
return $this->routeName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Storefront\Api\Seo\Collection; | ||
|
||
use Shopware\Api\Entity\EntityCollection; | ||
use Shopware\Storefront\Api\Seo\Struct\SeoUrlBasicStruct; | ||
|
||
class SeoUrlBasicCollection extends EntityCollection | ||
{ | ||
/** | ||
* @var SeoUrlBasicStruct[] | ||
*/ | ||
protected $elements = []; | ||
|
||
public function get(string $id): ? SeoUrlBasicStruct | ||
{ | ||
return parent::get($id); | ||
} | ||
|
||
public function current(): SeoUrlBasicStruct | ||
{ | ||
return parent::current(); | ||
} | ||
|
||
public function getShopIds(): array | ||
{ | ||
return $this->fmap(function (SeoUrlBasicStruct $seoUrl) { | ||
return $seoUrl->getApplicationId(); | ||
}); | ||
} | ||
|
||
public function filterByShopId(string $id): SeoUrlBasicCollection | ||
{ | ||
return $this->filter(function (SeoUrlBasicStruct $seoUrl) use ($id) { | ||
return $seoUrl->getApplicationId() === $id; | ||
}); | ||
} | ||
|
||
public function getByPathInfo(string $pathInfo): ?SeoUrlBasicStruct | ||
{ | ||
foreach ($this->elements as $element) { | ||
if ($element->getPathInfo() === $pathInfo) { | ||
return $element; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function getBySeoPathInfo(string $seoPathInfo): ?SeoUrlBasicStruct | ||
{ | ||
foreach ($this->elements as $element) { | ||
if ($element->getSeoPathInfo() === $seoPathInfo) { | ||
return $element; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function getForeignKeys() | ||
{ | ||
return $this->fmap(function (SeoUrlBasicStruct $seoUrl) { | ||
return $seoUrl->getForeignKey(); | ||
}); | ||
} | ||
|
||
public function hasForeignKey(string $name, string $foreignKey): bool | ||
{ | ||
foreach ($this->elements as $element) { | ||
if ($element->getForeignKey() === $foreignKey && $element->getName() === $name) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function hasPathInfo(string $pathInfo): bool | ||
{ | ||
foreach ($this->elements as $element) { | ||
if ($element->getPathInfo() === $pathInfo) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
protected function getExpectedClass(): string | ||
{ | ||
return SeoUrlBasicStruct::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Storefront\Api\Seo\Collection; | ||
|
||
use Shopware\Api\Shop\Collection\ShopBasicCollection; | ||
use Shopware\Storefront\Api\Seo\Struct\SeoUrlDetailStruct; | ||
|
||
class SeoUrlDetailCollection extends SeoUrlBasicCollection | ||
{ | ||
/** | ||
* @var SeoUrlDetailStruct[] | ||
*/ | ||
protected $elements = []; | ||
|
||
public function getShops(): ShopBasicCollection | ||
{ | ||
return new ShopBasicCollection( | ||
$this->fmap(function (SeoUrlDetailStruct $seoUrl) { | ||
return $seoUrl->getApplication(); | ||
}) | ||
); | ||
} | ||
|
||
protected function getExpectedClass(): string | ||
{ | ||
return SeoUrlDetailStruct::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Shopware\Storefront\Api\Seo\Definition; | ||
|
||
use Shopware\Api\Application\Definition\ApplicationDefinition; | ||
use Shopware\Api\Entity\EntityDefinition; | ||
use Shopware\Api\Entity\EntityExtensionInterface; | ||
use Shopware\Api\Entity\Field\BoolField; | ||
use Shopware\Api\Entity\Field\DateField; | ||
use Shopware\Api\Entity\Field\FkField; | ||
use Shopware\Api\Entity\Field\IdField; | ||
use Shopware\Api\Entity\Field\ManyToOneAssociationField; | ||
use Shopware\Api\Entity\Field\StringField; | ||
use Shopware\Api\Entity\Field\TenantIdField; | ||
use Shopware\Api\Entity\FieldCollection; | ||
use Shopware\Api\Entity\Write\Flag\PrimaryKey; | ||
use Shopware\Api\Entity\Write\Flag\Required; | ||
use Shopware\Storefront\Api\Seo\Collection\SeoUrlBasicCollection; | ||
use Shopware\Storefront\Api\Seo\Collection\SeoUrlDetailCollection; | ||
use Shopware\Storefront\Api\Seo\Event\SeoUrl\SeoUrlDeletedEvent; | ||
use Shopware\Storefront\Api\Seo\Event\SeoUrl\SeoUrlWrittenEvent; | ||
use Shopware\Storefront\Api\Seo\Repository\SeoUrlRepository; | ||
use Shopware\Storefront\Api\Seo\Struct\SeoUrlBasicStruct; | ||
use Shopware\Storefront\Api\Seo\Struct\SeoUrlDetailStruct; | ||
|
||
class SeoUrlDefinition extends EntityDefinition | ||
{ | ||
/** | ||
* @var FieldCollection | ||
*/ | ||
protected static $primaryKeys; | ||
|
||
/** | ||
* @var FieldCollection | ||
*/ | ||
protected static $fields; | ||
|
||
/** | ||
* @var EntityExtensionInterface[] | ||
*/ | ||
protected static $extensions = []; | ||
|
||
public static function getEntityName(): string | ||
{ | ||
return 'seo_url'; | ||
} | ||
|
||
public static function getFields(): FieldCollection | ||
{ | ||
if (self::$fields) { | ||
return self::$fields; | ||
} | ||
|
||
self::$fields = new FieldCollection([ | ||
new TenantIdField(), | ||
(new IdField('id', 'id'))->setFlags(new PrimaryKey(), new Required()), | ||
(new IdField('version_id', 'versionId'))->setFlags(new PrimaryKey(), new Required()), | ||
(new FkField('application_id', 'applicationId', ApplicationDefinition::class))->setFlags(new Required()), | ||
(new StringField('name', 'name'))->setFlags(new Required()), | ||
(new IdField('foreign_key', 'foreignKey'))->setFlags(new Required()), | ||
(new IdField('foreign_key_version_id', 'foreignKeyVersionId'))->setFlags(new Required()), | ||
(new StringField('path_info', 'pathInfo'))->setFlags(new Required()), | ||
(new StringField('seo_path_info', 'seoPathInfo'))->setFlags(new Required()), | ||
new BoolField('is_canonical', 'isCanonical'), | ||
new BoolField('is_modified', 'isModified'), | ||
new DateField('created_at', 'createdAt'), | ||
new DateField('updated_at', 'updatedAt'), | ||
new ManyToOneAssociationField('application', 'application_id', ApplicationDefinition::class, false), | ||
]); | ||
|
||
foreach (self::$extensions as $extension) { | ||
$extension->extendFields(self::$fields); | ||
} | ||
|
||
return self::$fields; | ||
} | ||
|
||
public static function getRepositoryClass(): string | ||
{ | ||
return SeoUrlRepository::class; | ||
} | ||
|
||
public static function getBasicCollectionClass(): string | ||
{ | ||
return SeoUrlBasicCollection::class; | ||
} | ||
|
||
public static function getDeletedEventClass(): string | ||
{ | ||
return SeoUrlDeletedEvent::class; | ||
} | ||
|
||
public static function getWrittenEventClass(): string | ||
{ | ||
return SeoUrlWrittenEvent::class; | ||
} | ||
|
||
public static function getBasicStructClass(): string | ||
{ | ||
return SeoUrlBasicStruct::class; | ||
} | ||
|
||
public static function getTranslationDefinitionClass(): ?string | ||
{ | ||
return null; | ||
} | ||
|
||
public static function getDetailStructClass(): string | ||
{ | ||
return SeoUrlDetailStruct::class; | ||
} | ||
|
||
public static function getDetailCollectionClass(): string | ||
{ | ||
return SeoUrlDetailCollection::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service class="Shopware\Storefront\Api\Seo\Definition\SeoUrlDefinition" id="shopware.seo.seo_url_definition" > | ||
<tag name="shopware.entity.definition" entity="seo_url" /> | ||
</service> | ||
<service class="Shopware\Storefront\Api\Seo\Repository\SeoUrlRepository" id="Shopware\Storefront\Api\Seo\Repository\SeoUrlRepository" public="true"> | ||
<argument id="Shopware\Api\Entity\Dbal\EntityReader" type="service"/> | ||
<argument id="Shopware\Version\VersionManager" type="service"/> | ||
<argument id="Shopware\Api\Entity\Dbal\EntitySearcher" type="service"/> | ||
<argument id="Shopware\Api\Entity\Dbal\EntityAggregator" type="service"/> | ||
<argument id="event_dispatcher" type="service"/> | ||
</service> | ||
</services> | ||
</container> | ||
|
Oops, something went wrong.