Skip to content

Commit

Permalink
Move out of article namespaces (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz authored Jun 17, 2021
1 parent 6987fe6 commit 8857c9f
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 69 deletions.
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
.gitattributes export-ignore
.gitignore export-ignore
.php_cs.dist export-ignore
.phpstan.neon export-ignore
.phpunit.xml.dist export-ignore
phpstan.neon export-ignore
phpunit.xml.dist export-ignore
33 changes: 14 additions & 19 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace Sulu\Bundle\ArticleBundle\DependencyInjection;

use Sulu\Bundle\ArticleBundle\Article\Domain\Model\Article;
use Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleDimensionContent;
use Sulu\Bundle\ArticleBundle\Document\ArticlePageViewObject;
use Sulu\Bundle\ArticleBundle\Document\ArticleViewDocument;
use Sulu\Bundle\ArticleBundle\Domain\Model\Article;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleDimensionContent;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

Expand All @@ -36,28 +36,23 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->arrayNode('article')
->enumNode('storage')
->values([self::ARTICLE_STORAGE_PHPCR, self::ARTICLE_STORAGE_EXPERIMENTAL])
->defaultValue(self::ARTICLE_STORAGE_PHPCR)
->end()
->arrayNode('objects')
->addDefaultsIfNotSet()
->children()
->enumNode('storage')
->values([self::ARTICLE_STORAGE_PHPCR, self::ARTICLE_STORAGE_EXPERIMENTAL])
->defaultValue(self::ARTICLE_STORAGE_PHPCR)
->arrayNode('article')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(Article::class)->end()
->end()
->end()
->arrayNode('objects')
->arrayNode('article_content')
->addDefaultsIfNotSet()
->children()
->arrayNode('article')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(Article::class)->end()
->end()
->end()
->arrayNode('article_content')
->addDefaultsIfNotSet()
->children()
->scalarNode('model')->defaultValue(ArticleDimensionContent::class)->end()
->end()
->end()
->scalarNode('model')->defaultValue(ArticleDimensionContent::class)->end()
->end()
->end()
->end()
Expand Down
10 changes: 5 additions & 5 deletions DependencyInjection/SuluArticleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

namespace Sulu\Bundle\ArticleBundle\DependencyInjection;

use Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleInterface;
use Sulu\Bundle\ArticleBundle\Document\ArticleDocument;
use Sulu\Bundle\ArticleBundle\Document\ArticlePageDocument;
use Sulu\Bundle\ArticleBundle\Document\Form\ArticleDocumentType;
use Sulu\Bundle\ArticleBundle\Document\Form\ArticlePageDocumentType;
use Sulu\Bundle\ArticleBundle\Document\Structure\ArticleBridge;
use Sulu\Bundle\ArticleBundle\Document\Structure\ArticlePageBridge;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;
use Sulu\Bundle\ArticleBundle\Exception\ArticlePageNotFoundException;
use Sulu\Bundle\ArticleBundle\Exception\ParameterNotAllowedException;
use Sulu\Bundle\PersistenceBundle\DependencyInjection\PersistenceExtensionTrait;
Expand Down Expand Up @@ -46,7 +46,7 @@ public function prepend(ContainerBuilder $container)
$configs = $resolvingBag->resolveValue($configs);
$config = $this->processConfiguration(new Configuration(), $configs);

$storage = $config['article']['storage'];
$storage = $config['storage'];

if ($container->hasExtension('jms_serializer')) {
$container->prependExtensionConfig(
Expand Down Expand Up @@ -325,7 +325,7 @@ private function prependExperimentalStorage(ContainerBuilder $container): void
'mappings' => [
'SuluBundleArticle' => [
'type' => 'xml',
'prefix' => 'Sulu\Bundle\ArticleBundle\Article\Domain\Model',
'prefix' => 'Sulu\Bundle\ArticleBundle\Domain\Model',
'dir' => \dirname(__DIR__) . '/Resources/config/doctrine/Article',
'alias' => 'SuluArticleBundle',
'is_bundle' => false,
Expand Down Expand Up @@ -405,7 +405,7 @@ public function load(array $configs, ContainerBuilder $container)

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));

$storage = $config['article']['storage'];
$storage = $config['storage'];
$container->setParameter('sulu_article.article_storage', $storage);

if (Configuration::ARTICLE_STORAGE_PHPCR === $storage) {
Expand All @@ -417,7 +417,7 @@ public function load(array $configs, ContainerBuilder $container)

private function loadExperimentalStorage(array $config, ContainerBuilder $container, Loader\XmlFileLoader $loader): void
{
$this->configurePersistence($config['article']['objects'], $container);
$this->configurePersistence($config['objects'], $container);

$loader->load('experimental.xml');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Article\Domain\Model;
namespace Sulu\Bundle\ArticleBundle\Domain\Model;

use Ramsey\Uuid\Uuid;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Article\Domain\Model;
namespace Sulu\Bundle\ArticleBundle\Domain\Model;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentTrait;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Article\Domain\Model;
namespace Sulu\Bundle\ArticleBundle\Domain\Model;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\DimensionContentInterface;
use Sulu\Bundle\ContentBundle\Content\Domain\Model\ExcerptInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Article\Domain\Model;
namespace Sulu\Bundle\ArticleBundle\Domain\Model;

use Sulu\Bundle\ContentBundle\Content\Domain\Model\ContentRichEntityInterface;
use Sulu\Component\Persistence\Model\AuditableInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Article\Infrastructure\Sulu\Admin;
namespace Sulu\Bundle\ArticleBundle\Infrastructure\Sulu\Admin;

use Sulu\Bundle\AdminBundle\Admin\Admin;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItem;
use Sulu\Bundle\AdminBundle\Admin\Navigation\NavigationItemCollection;
use Sulu\Bundle\AdminBundle\Admin\View\ToolbarAction;
use Sulu\Bundle\AdminBundle\Admin\View\ViewBuilderFactoryInterface;
use Sulu\Bundle\AdminBundle\Admin\View\ViewCollection;
use Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleInterface;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;
use Sulu\Bundle\ContentBundle\Content\Infrastructure\Sulu\Admin\ContentViewBuilderFactoryInterface;
use Sulu\Component\Localization\Manager\LocalizationManagerInterface;
use Sulu\Component\Security\Authorization\PermissionTypes;
Expand Down
4 changes: 2 additions & 2 deletions Resources/config/doctrine/Article/Article.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<mapped-superclass
name="Sulu\Bundle\ArticleBundle\Article\Domain\Model\Article"
name="Sulu\Bundle\ArticleBundle\Domain\Model\Article"
table="ar_articles"
repository-class="Sulu\Component\Persistence\Repository\ORM\EntityRepository"
>
<id name="id" type="string" column="id">
<generator strategy="NONE"/>
</id>

<one-to-many field="dimensionContents" target-entity="Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleDimensionContentInterface" mapped-by="article">
<one-to-many field="dimensionContents" target-entity="Sulu\Bundle\ArticleBundle\Domain\Model\ArticleDimensionContentInterface" mapped-by="article">
<cascade>
<cascade-persist/>
</cascade>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleDimensionContent"
<entity name="Sulu\Bundle\ArticleBundle\Domain\Model\ArticleDimensionContent"
table="ar_articles_dimension_contents">
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>

<field name="title" type="string" column="title" length="64" nullable="true"/>

<many-to-one field="article" target-entity="Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleInterface" inversed-by="dimensionContents">
<many-to-one field="article" target-entity="Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface" inversed-by="dimensionContents">
<join-columns>
<join-column name="articleId" referenced-column-name="id" on-delete="CASCADE" nullable="false"/>
</join-columns>
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/experimental.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-->

<services>
<service id="sulu_article.article_admin" class="Sulu\Bundle\ArticleBundle\Article\Infrastructure\Sulu\Admin\ArticleAdmin">
<service id="sulu_article.article_admin" class="Sulu\Bundle\ArticleBundle\Infrastructure\Sulu\Admin\ArticleAdmin">
<!-- @internal this service is internal and should not be used by your project -->

<argument type="service" id="sulu_admin.view_builder_factory" />
Expand Down
74 changes: 62 additions & 12 deletions Resources/doc/experimental-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

For the **experimental** storage the articles are stored using the [SuluContentBundle](https://github.com/sulu/sulucontentbundle).

## Table of content

- [Installation](#installation)
- [Routes](#routes)
- [Configuration](#configuration)
- [Override Entities](#override-entities)
- [Override Article Entity](#override-article-entity)
- [Override Article Content Entity](#override-article-entity)

## Installation

To use the experimental storage you need to have the [SuluContentBundle](https://github.com/sulu/sulucontentbundle) installed.
Expand All @@ -18,19 +27,28 @@ sulu_article:
storage: experimental
```
## Routes
```yaml
# config/routes/sulu_article_admin.yaml

## coming soon ...
```

## Configuration

The following is showing the full configuration of the **experimental** article module:

```yaml
sulu_product:
article:
storage: experimental

# optional
objects:
article:
model: 'Sulu\Bundle\ArticleBundle\Article\Domain\Model\Article'
storage: experimental

# optional
objects:
article:
model: 'Sulu\Bundle\ArticleBundle\Domain\Model\Article'
article_content:
model: 'Sulu\Bundle\ArticleBundle\Domain\Model\ArticleDimensionContent'
```
## Override Entities
Expand All @@ -44,7 +62,7 @@ sulu_product:
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Sulu\Bundle\ArticleBundle\Product\Domain\Model\Article as SuluArticle;
use Sulu\Bundle\ArticleBundle\Domain\Model\Article as SuluArticle;

/**
* @ORM\Table(name="ar_articles")
Expand All @@ -61,10 +79,42 @@ Configure your new model class:
# config/packages/sulu_article.yaml

sulu_article:
article:
objects:
article:
model: 'App\Entity\Article'
objects:
article:
model: 'App\Entity\Article'
```
To add new fields to your entity have a look at the [Doctrine Mapping Documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/basic-mapping.html);
### Override Article Content Entity
```php
<?php
// src/Entity/Article.php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleDimensionContent as SuluArticleDimensionContent;

/**
* @ORM\Table(name="ar_articles_dimension_contents")
* @ORM\Entity
*/
class ArticleDimensionContent extends SuluArticleDimensionContent
{
}
```

Configure your new model class:

```yaml
# config/packages/sulu_article.yaml

sulu_article:
objects:
article_content:
model: 'App\Entity\ArticleDimensionContent'
```
To add new fields to your entity have a look at the [Doctrine Mapping Documentation](https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/basic-mapping.html);
4 changes: 2 additions & 2 deletions SuluArticleBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

namespace Sulu\Bundle\ArticleBundle;

use Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleDimensionContentInterface;
use Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleInterface;
use Sulu\Bundle\ArticleBundle\DependencyInjection\Configuration;
use Sulu\Bundle\ArticleBundle\DependencyInjection\ConverterCompilerPass;
use Sulu\Bundle\ArticleBundle\DependencyInjection\RouteEnhancerCompilerPass;
use Sulu\Bundle\ArticleBundle\DependencyInjection\StructureValidatorCompilerPass;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleDimensionContentInterface;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;
use Sulu\Bundle\PersistenceBundle\DependencyInjection\Compiler\ResolveTargetEntitiesPass;
use Sulu\Bundle\PersistenceBundle\PersistenceBundleTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand Down
3 changes: 1 addition & 2 deletions Tests/Application/config/config_experimental_storage.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
sulu_article:
article:
storage: 'experimental'
storage: 'experimental'
3 changes: 1 addition & 2 deletions Tests/Application/config/config_phpcr_storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ sulu_route:
parent: "{object.getParent().getRoutePath()}"

sulu_article:
article:
storage: 'phpcr'
storage: 'phpcr'
index_name: "su_articles_tests"
hosts: ["%env(ELASTICSEARCH_HOST)%"]
default_main_webspace: 'sulu_io'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Tests\Unit\Article\Domain\Model;
namespace Sulu\Bundle\ArticleBundle\Tests\Unit\Domain\Model;

use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleDimensionContent;
use Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleDimensionContentInterface;
use Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleInterface;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleDimensionContent;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleDimensionContentInterface;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;

class ArticleDimensionContentTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
* with this source code in the file LICENSE.
*/

namespace Sulu\Bundle\ArticleBundle\Tests\Unit\Article\Domain\Model;
namespace Sulu\Bundle\ArticleBundle\Tests\Unit\Domain\Model;

use PHPUnit\Framework\TestCase;
use Sulu\Bundle\ArticleBundle\Article\Domain\Model\Article;
use Sulu\Bundle\ArticleBundle\Article\Domain\Model\ArticleInterface;
use Sulu\Bundle\ArticleBundle\Domain\Model\Article;
use Sulu\Bundle\ArticleBundle\Domain\Model\ArticleInterface;

class ArticleTest extends TestCase
{
Expand Down
Loading

0 comments on commit 8857c9f

Please sign in to comment.