Skip to content

Commit

Permalink
feature #38 Theme Bundle v2.0 - Symfony 5 support and internal refact…
Browse files Browse the repository at this point in the history
…oring (GSadee, pamil)

This PR was merged into the 2.0-dev branch.

Discussion
----------

Closes #37.

TODO (can be done in subsequent PRs):
 - [x] Upgrade instructions
 - [ ] Trying to install it in Sylius/Sylius

Nice to have:
 - [ ] Legacy templates adapters
 - [ ] Legacy translations adapters
 - [ ] Legacy assets adapters

Commits
-------

84f9188 Support for Symfony 5
d5759f5 Add typehints to the FilesystemInterface
be9e5ac Change parameter type of collect method from ThemeCollector
9cb1aa9 Use Command class instead of removed ContainerAwareCommand
55e835c Fix some problems with adding support for Symfony 5
819d8be Rework themes for templates
ce10551 Rework themes for assets
23d78d6 Rework themes for translations
13a9c03 Remove and ignore .phpunit.result.cache
63ae7a5 Fix coding standards + fix static analysis
a908757 Fix specs
fb79acd Fix the build for Symfony 4.4
a765290 Set up coding standard for spec and tests directories
af145b1 Change version to 2.0-dev
ec855e1 Add support for Twig 3.x
8c7d029 Add support for PHP 7.4
ee69780 Remove symfony/templating from Travis CI dependencies
aa9567d Remove inheritdoc comments
5c8c96a Rework Twig integration and template locators logic
3c1bf4a Rename translator-related services
8ba3157 Rename assets-related services + sylius:theme:assets:install command enabled only if assets enabled
c01e630 Use interfaces as services names
fd3fb0f Filesystem defaults: themes top-level directory, scan depth at 1
bf564bb Improve docs
dc302fa Minor docs changes
7be5930 Fix loaders & resource providers for translator
7d71988 Fix the bin/console script
4fc3bbf Add UPGRADE.md for 2.0-dev
0d7856a Fix coding standards
  • Loading branch information
pamil authored Apr 30, 2020
2 parents 0cd4c8a + 0d7856a commit b21b623
Show file tree
Hide file tree
Showing 181 changed files with 1,544 additions and 2,494 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@

/phpspec.yml
/phpunit.xml

/.phpunit.result.cache
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ language: php
php:
- 7.2
- 7.3
- 7.4

env:
- SYMFONY_VERSION=4.4.*
- SYMFONY_VERSION=4.4.* TWIG_VERSION=2.*
- SYMFONY_VERSION=4.4.* TWIG_VERSION=3.*
- SYMFONY_VERSION=5.0.* TWIG_VERSION=2.*
- SYMFONY_VERSION=5.0.* TWIG_VERSION=3.*

cache:
directories:
Expand All @@ -29,14 +33,14 @@ install:
symfony/http-foundation:${SYMFONY_VERSION} \
symfony/http-kernel:${SYMFONY_VERSION} \
symfony/options-resolver:${SYMFONY_VERSION} \
symfony/templating:${SYMFONY_VERSION} \
symfony/translation:${SYMFONY_VERSION} \
--no-update --no-scripts
- |
composer require \
symfony/browser-kit:${SYMFONY_VERSION} \
symfony/security-csrf:${SYMFONY_VERSION} \
symfony/twig-bundle:${SYMFONY_VERSION} \
twig/twig:${TWIG_VERSION} \
--no-update --no-scripts
- composer update --prefer-dist

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011-2019 Paweł Jędrzejewski
Copyright (c) 2011-2020 Paweł Jędrzejewski

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
40 changes: 40 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## UPGRADE FROM `1.x` TO `2.0`

* Renamed the following services:

* `sylius.collector.theme` replaced with `Sylius\Bundle\ThemeBundle\Collector\ThemeCollector`
* `sylius.theme.asset.assets_installer` replaced with `Sylius\Bundle\ThemeBundle\Asset\Installer\AssetsInstaller`
* `sylius.theme.asset.path_resolver` replaced with `Sylius\Bundle\ThemeBundle\Asset\PathResolverInterface`
* `sylius.theme.filesystem` replaced with `Sylius\Bundle\ThemeBundle\Filesystem\FilesystemInterface`
* `sylius.theme.finder_factory` replaced with `Sylius\Bundle\ThemeBundle\Factory\FinderFactoryInterface`
* `sylius.theme.form.type.theme_choice` replaced with `Sylius\Bundle\ThemeBundle\Form\Type\ThemeChoiceType`
* `sylius.theme.form.type.theme_name_choice` replaced with `Sylius\Bundle\ThemeBundle\Form\Type\ThemeNameChoiceType`
* `sylius.theme.locator.application_resource` replaced with `Sylius\Bundle\ThemeBundle\Twig\Locator\ApplicationTemplateLocator`
* `sylius.theme.locator.bundle_resource` replaced with `Sylius\Bundle\ThemeBundle\Twig\Locator\BundleTemplateLocator` and `Sylius\Bundle\ThemeBundle\Twig\Locator\NamespacedTemplateLocator`
* `sylius.theme.locator.resource` replaced with `Sylius\Bundle\ThemeBundle\Twig\Locator\TemplateLocatorInterface`
* `sylius.theme.templating.locator` replaced with `Sylius\Bundle\ThemeBundle\Twig\Locator\TemplateLocatorInterface`
* `sylius.theme.translation.files_finder` replaced with `Sylius\Bundle\ThemeBundle\Translation\Finder\TranslationFilesFinderInterface`
* `sylius.theme.translation.loader_provider` replaced with `Sylius\Bundle\ThemeBundle\Translation\Provider\Loader\TranslatorLoaderProviderInterface`
* `sylius.theme.translation.resource_provider` replaced with `Sylius\Bundle\ThemeBundle\Translation\Provider\Resource\TranslatorResourceProviderInterface`

* Deprecated the following services:

* `sylius.context.theme` superseded by `Sylius\Bundle\ThemeBundle\Context\SettableThemeContext` instead
* `sylius.factory.theme_author` superseded by `Sylius\Bundle\ThemeBundle\Factory\ThemeAuthorFactoryInterface` instead
* `sylius.factory.theme_screenshot` superseded by `Sylius\Bundle\ThemeBundle\Factory\ThemeScreenshotFactoryInterface` instead
* `sylius.factory.theme` superseded by `Sylius\Bundle\ThemeBundle\Factory\ThemeFactoryInterface` instead
* `sylius.repository.theme` superseded by `Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface` instead
* `sylius.theme.circular_dependency_checker` superseded by `Sylius\Bundle\ThemeBundle\Loader\CircularDependencyCheckerInterface` instead
* `sylius.theme.configuration.processor` superseded by `Sylius\Bundle\ThemeBundle\Configuration\ConfigurationProcessorInterface` instead
* `sylius.theme.configuration.provider` superseded by `Sylius\Bundle\ThemeBundle\Configuration\ConfigurationProviderInterface` instead
* `sylius.theme.configuration` superseded by `Sylius\Bundle\ThemeBundle\Configuration\ThemeConfiguration` instead
* `sylius.theme.context.settable` superseded by `Sylius\Bundle\ThemeBundle\Context\SettableThemeContext` instead
* `sylius.theme.hierarchy_provider` superseded by `Sylius\Bundle\ThemeBundle\HierarchyProvider\ThemeHierarchyProviderInterface` instead
* `sylius.theme.loader` superseded by `Sylius\Bundle\ThemeBundle\Loader\ThemeLoaderInterface` instead

* Removed the following services:

* `sylius.theme.hydrator`
* `sylius.theme.templating.cache.clearer`
* `sylius.theme.templating.cache.warmer`
* `sylius.theme.templating.file_locator`
49 changes: 24 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,40 @@
"type": "symfony-bundle",
"description": "Themes management for Symfony projects.",
"keywords": ["themes", "theming"],
"homepage": "http://sylius.com",
"homepage": "https://sylius.com",
"license": "MIT",
"authors": [
{
"name": "Kamil Kokot",
"homepage": "http://kamil.kokot.me"
"homepage": "https://kamilkokot.com"
},
{
"name": "Sylius project",
"homepage": "http://sylius.com"
"homepage": "https://sylius.com"
},
{
"name": "Community contributions",
"homepage": "http://github.com/Sylius/Sylius/contributors"
"homepage": "https://github.com/Sylius/Sylius/contributors"
}
],
"require": {
"php": "^7.2",

"doctrine/common": "^2.5",
"symfony/asset": "^4.4",
"symfony/config": "^4.4",
"symfony/console": "^4.4",
"symfony/dom-crawler": "^4.4",
"symfony/asset": "^4.4|^5.0",
"symfony/config": "^4.4|^5.0",
"symfony/console": "^4.4|^5.0",
"symfony/dom-crawler": "^4.4|^5.0",
"symfony/translation-contracts": "^1.1|^2.0",
"symfony/dependency-injection": "^4.4",
"symfony/filesystem": "^4.4",
"symfony/finder": "^4.4",
"symfony/form": "^4.4",
"symfony/framework-bundle": "^4.4",
"symfony/http-foundation": "^4.4",
"symfony/http-kernel": "^4.4",
"symfony/options-resolver": "^4.4",
"symfony/templating": "^4.4",
"symfony/translation": "^4.4",
"symfony/dependency-injection": "^4.4|^5.0",
"symfony/filesystem": "^4.4|^5.0",
"symfony/finder": "^4.4|^5.0",
"symfony/form": "^4.4|^5.0",
"symfony/framework-bundle": "^4.4|^5.0",
"symfony/http-foundation": "^4.4|^5.0",
"symfony/http-kernel": "^4.4|^5.0",
"symfony/options-resolver": "^4.4|^5.0",
"symfony/translation": "^4.4|^5.0",
"zendframework/zend-hydrator": "^2.2"
},
"require-dev": {
Expand All @@ -50,10 +49,10 @@
"phpstan/phpstan-webmozart-assert": "^0.12",
"phpunit/phpunit": "^8.5",
"sylius-labs/coding-standard": "^3.0",
"symfony/browser-kit": "^4.4",
"symfony/security-csrf": "^4.4",
"symfony/twig-bundle": "^4.4",
"twig/twig": "^2.0",
"symfony/browser-kit": "^4.4|^5.0",
"symfony/security-csrf": "^4.4|^5.0",
"symfony/twig-bundle": "^4.4|^5.0",
"twig/twig": "^2.0|^3.0",
"vimeo/psalm": "^3.5"
},
"autoload": {
Expand All @@ -69,17 +68,17 @@
},
"scripts": {
"analyse": [
"@php vendor/bin/ecs check src",
"@php vendor/bin/ecs check spec src tests",
"@php vendor/bin/phpstan analyse --ansi -c phpstan.neon -l max spec src tests",
"@php vendor/bin/psalm"
],
"fix": [
"@php vendor/bin/ecs check src --fix"
"@php vendor/bin/ecs check spec src tests --fix"
]
},
"extra": {
"branch-alias": {
"dev-master": "1.5-dev"
"dev-master": "2.0-dev"
}
}
}
12 changes: 3 additions & 9 deletions docs/configuration_sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ To discover themes that are defined in the application, ThemeBundle uses configu
**Filesystem** configuration source loads theme definitions from files placed under specified directories.

By default it seeks for `composer.json` files that exists under `%kernel.project_dir%/themes` directory, which
usually is resolved to `themes`.
usually is resolved to `<Project>/themes`.

#### Configuration reference

Expand All @@ -17,15 +17,10 @@ sylius_theme:
filesystem:
enabled: false
filename: composer.json
scan_depth: null
scan_depth: 1
directories:
- "%kernel.project_dir%/themes"
```
Scanning for the configuration file inside themes directories is recursive with unlimited directory depth by default,
which can result in slow performance when a lot of files are placed inside themes (e.g. a `node_modules` folder).
Define the optional `scan_depth` (integer) setting to the configuration to restrict scanning for the theme configuration
file to a specific depth.
### Test configuration source
Expand All @@ -44,8 +39,7 @@ This source does not have any configuration options. To enable it, use the follo
#### Usage
In order to use tests, have a look at `sylius.theme.test_theme_configuration_manager` service
(implementing `TestThemeConfigurationManagerInterface`). You can:
In order to use tests, have a look at `TestThemeConfigurationManager` class. You can:

- add a theme: `add(array $configuration): void`
- remove a theme: `remove(string $themeName): void`
Expand Down
14 changes: 6 additions & 8 deletions docs/important_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ the same as they were.

Changed loading order (priority descending):

- App templates:
- `<Theme>/views` **(NEW!)**
- `app/Resources/views`
- Application templates:
- `<Theme>/templates` **(NEW!)**
- `<Project>/templates`
- Bundle templates:
- `<Theme>/<Bundle name>/views` **(NEW!)**
- `app/Resources/<Bundle name>/views`
- `<Theme>/templates/bundles/<Bundle name>` **(NEW!)**
- `<Project>/templates/bundles/<Bundle name>`
- `<Bundle>/Resources/views`

### Translations

Changed loading order (priority descending):

- `<Theme>/translations` **(NEW!)**
- `<Theme>/<Bundle name>/translations` **(NEW!)**
- `app/Resources/translations`
- `app/Resources/<Bundle name>/translations`
- `<Project>/translations`
- `<Bundle>/Resources/translations`

### Assets
Expand Down
2 changes: 1 addition & 1 deletion docs/theme_configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"name": "Kamil Kokot",
"email": "kamil@kokot.me",
"homepage": "http://kamil.kokot.me",
"homepage": "https://kamilkokot.com",
"role": "Developer"
}
],
Expand Down
25 changes: 11 additions & 14 deletions docs/your_first_theme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,21 @@ When adding or removing a theme, it's necessary to rebuild the container (same a
### Theme structure

Themes can override and add both bundle resources and app resources. When your theme configuration is in `SampleTheme/theme.json`,
app resources should be located at `SampleTheme/views` for templates, `SampleTheme/translations` for translations and `SampleTheme/public` for assets.
Same comes with the bundle resources, eg. for `FOSUserBundle` the paths should be located at `SampleTheme/FOSUserBundle/views`,
`SampleTheme/FOSUserBundle/translations` and `SampleTheme/FOSUserBundle/public` respectively.
app resources should be located at `SampleTheme/templates` for templates, `SampleTheme/translations` for translations and `SampleTheme/public` for assets.
To override a specific bundle's template (eg. `FOSUserBundle`), put it in `SampleTheme/templates/buncles/FOSUserBundle` directory.

```
AcmeTheme
├── AcmeBundle
│   ├── public
│   │   └── asset.jpg
│   ├── translations
│   │   └── messages.en.yml
│   └── views
│   └── template.html.twig
├── composer.json
├── translations
│   └── messages.en.yml
└── views
└── template.html.twig
├── public
│   └── asset.jpg
├── templates
│   ├── bundles
│   │   └── AcmeBundle
│   │   └── bundleTemplate.html.twig
| └── template.html.twig
└── translations
   └── messages.en.yml
```
### Enabling themes
Expand Down
4 changes: 4 additions & 0 deletions easy-coding-standard.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
imports:
- { resource: 'vendor/sylius-labs/coding-standard/easy-coding-standard.yml' }

parameters:
exclude_files:
- '**/var/*'

services:
PhpCsFixer\Fixer\Comment\HeaderCommentFixer:
header: |
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ parameters:

# Symfony caveats
- '/Parameter \#1 \$name of method Symfony\\Component\\Config\\FileLocatorInterface::locate\(\) expects string, Symfony\\Component\\Templating\\TemplateReferenceInterface given/'
- '/Parameter \#1 \$translator of class Symfony\\Component\\Translation\\Formatter\\MessageFormatter constructor expects Symfony\\Contracts\\Translation\\TranslatorInterface|null, Symfony\\Component\\Translation\\MessageSelector given/'

# Symfony passes TemplateReference object instead of a string
- "/Casting to string something that\\'s already string./"
Expand All @@ -30,3 +29,6 @@ parameters:
- '/Method Sylius\\Bundle\\ThemeBundle\\Translation\\ThemeAwareTranslator::__call\(\) has no return typehint specified./'
- '/Method Sylius\\Bundle\\ThemeBundle\\Translation\\ThemeAwareTranslator::trans\(\) has parameter \$[A-Za-z]+ with no typehint specified./'
- '/Method Sylius\\Bundle\\ThemeBundle\\Templating\\Locator\\TemplateFileLocator::unserialize\(\) has parameter \$serialized with no typehint specified./'
- '/Method Sylius\\Bundle\\ThemeBundle\\Asset\\Package\\[A-Za-z]+::getUrl\(\) has parameter \$path with no typehint specified./'
- '/Symfony\\Component\\Translation\\MessageSelector/'
- '/Twig\\Loader\\ExistsLoaderInterface/'
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.0/phpunit.xsd"
colors="true"
processIsolation="false"
>
<php>
<ini name="error_reporting" value="-1" />
Expand Down
Loading

0 comments on commit b21b623

Please sign in to comment.