Skip to content

Commit

Permalink
TE-966: Create TwigApplicationPlugin (#5091)
Browse files Browse the repository at this point in the history
* TE-966: Create TwigApplicationPlugin (#5017)

* TE-968 Created TwigExtensionInterface.
* TE-1192 Added EventDispatcherExtension module.
* TE-1191 Adding EventDispatcher module.
* TE-1192 Added Container for EventDispatcherExtensionPlugin.
* TE-1191 Added EventDispatcherExtension as dependency.
* TE-1191 Fixed Symfony version constraints.
* TE-967 Create Twig ApplicationExtension plugin (#4830).
* TE-967 Added shared Twig application plugin.
* TE-967 Moved logic to separate application extensions and twig extension plugins.
* TE-967 Created event subscriber for Zed twig service.
* TE-967 Removed all twig container id's that should not be in the application and moved logic to plugins.
* TE-967: EventDispatcherExtensionPluginInterface -> EventDispatcherPluginInterface
* TE-977 Added UserTwigPlugin.
* TE-976 Added MoneyTwigPlugin.
* TE-975 Added CurrencyTwigPlugin.
* TE-974 Added ZedNavigationTwigPlugin.
* TE-983: Added CmsContentWidgetPlugin (#4930).

* TE-983:
* Deprecated CmsContentWidgetServiceProvider
* Created CmsContentWidgetTwigPlugin as replacement for CmsContentWidgetTwigPlugin
* Updated composer dependencies

* TE-969: Move TwigChartFunctionServiceProvider (#4937)

* TE-969

* Deprecated TwigChartFunctionServiceProvider
* Created ChartTwigPlugin as replacement for TwigChartFunctionServiceProvider
* Updated composer.json

* TE-992

* Created KernelApplicationPlugin as replacement of application functionality of ShopAppliactionServiceProvider
* Created StoreApplicationPlugin as replacement of store functionality of ShopApplicaitonServiceProvider

* Revert "TE-992"

This reverts commit 247ba8e970b6e6aa55af034f1049efc55f9db8bd.

* TE-972: Move DateTimeFormatterServiceProvider (#4935)

* TE-972

* Deprecated DateTimeFormatterServiceProvider
* Created DateTimeFormatterTwigPlugin as replacement for DateTimeFormatterServiceProvider
* Updated composer.json for UtilDateTime

* TE-970: Move TwigGlobalVariablesServiceProvider (#4944)

* TE-970

* Deprecated EnvironmentInformationServiceProvider
* Depracated TwigGlobalVariablesServiceProvider
* Deprecated EnfironmentInfo
* Created ApplicationTwigPlugin
* Updated copmoser.json

* TE-994: Added LocaleExtensionModule (#4973).

* TE-994: Added LocaleExtension module.

* TE-966: Removed adding global variables from TwigApplicationPlugins (#4998)

* TE-994: MoveShopApplicationServiceProvider (#4968)

TE-994
* Created ShopApplicationApplicationPlugin as replacement of application functionality of ShopAppliactionServiceProvider
* Created StoreApplicationPlugin as replacement of store functionality of ShopApplicaitonServiceProvider
* Created LocaleApplicationPlugin as replacement of locale functionality of ShopApplicaitonServiceProvider
* Added getName to zed's AbstractTwigExtensionPlugin
* Added FLAG_USE_LOCALE_LISTENER

* TE-973 Move TranslationServiceProvider (#4953)

* added new translator plugin
* refactored Translator and UserLocale application plugins
* created LocaleApplicationPlugin
* refactored event dispatcher. Added new LocaleListener substitution for Zed
* added locale listener substitution plugin for Yves

* te-966 Fixed Translator performance by moving plugin stack execution inside of Translator to not run on instantiation.

* TE-966:
* Fixed doc block typehints for container. Ignored not found exception
*  LocalePlugin -> LocaleLocalePlugin
* Introduced `Spryker/Yves/CmsBlock/Plugin/Twig/CmsBlockPlaceholderTwigPlugin` instead of `Spryker/Yves/CmsBlock/Twig/Plugin/TwigCmsBlockPlaceholder`.
* Deprecated `Spryker/Yves/CmsBlock/Twig/Plugin/TwigCmsBlockPlaceholder`.
* Deprecated `Spryker/Yves/CmsBlock/Twig/Plugin/TwigCmsBlock`.
* Modified typehints `Spryker/Yves/Kernel/Plugin/Pimple` it is able to take Container as well as Application.
* Introduced `Spryker/Yves/Twig/Plugin/AbstractTwigExtensionPlugin`.
* te-966 Added TwigGlobalVariablesServiceProvider to ApplicationDependencyProvider for BC
* te-966 Added check with instance of which translator is added as service for BC reasons.

* TE-966 Fixed code review findings

* TE-966 Updated composer constraints
  • Loading branch information
stereomon authored Mar 26, 2019
0 parents commit 5812d58
Show file tree
Hide file tree
Showing 12 changed files with 473 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage_clover: tests/_output/coverage.xml
json_path: tests/_output/coveralls-upload.json
service_name: travis-ci
32 changes: 32 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* eol=lf
* text=auto

# Denote all files that are truly binary and should not be modified.
*.png binary
*.jpg binary
*.gif binary
*.jpeg binary
*.zip binary
*.phar binary
*.ttf binary
*.woff binary
*.woff2 binary
*.eot binary
*.ico binary
*.mo binary
*.pdf binary
*.xsd binary
*.ts binary
*.exe binary

# Remove files for archives generated using `git archive`
codeception.yml export-ignore
dependency.json export-ignore
.coveralls.yml export-ignore
.travis.yml export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
phpstan.neon
phpstan.json
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# IDEs
/.idea
/.project
/nbproject
/.buildpath
/.settings
*.sublime-*
*.AppleDouble
*.AppleDB
*.AppleDesktop

# OS
.DS_Store

/vendor
/composer.lock

/tests/_output/*
!/tests/_output/.gitkeep
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: php

php:
- 7.1
- 7.3

cache:
directories:
- vendor
- $HOME/.composer/cache

env:
global:
- APPLICATION_ENV=development
- APPLICATION_STORE=DE

install:
- composer install --no-interaction --prefer-dist

script:
- vendor/bin/phpcs src --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml
- vendor/bin/codecept run --env isolated --coverage-xml

after_success:
- vendor/bin/coveralls -vvv

notifications:
email: false
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Router Changelog

[Release Changelog](https://github.com/spryker/router/releases)
40 changes: 40 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
SPRYKER SYSTEMS GMBH EVALUATION LICENSE AGREEMENT

SPRYKER SYSTEMS GMBH, REGISTERED WITH THE COMMERCIAL REGISTER OF THE LOWER COURT OF HAMBURG UNDER HRB 134310
(“WE” OR ”SPRYKER”)GRANTS YOU (THE “LICENSEE”) THE RIGHT TO USE THE SOFTWARE (AS DEFINED BELOW)
UNDER THE PROVISIONS OF THIS EVALUATION LICENSE AGREEMENT (THE “AGREEMENT”).

The “Software” includes any software owned and distributed by Spryker under this Agreement. The Software
contains elements of open source components, to which different license terms apply respectively.
These open source components are needed to be installed separately.

Spryker grants to Licensee, during the 45-calendar-day period (the “Evaluation Period”) following the download of the Software,
the nontransferable, nonexclusive limited, free of charge license to permit Licensee’s employees to internally use the Software
to test and evaluate the Software in connection with potentially purchasing non-evaluation licenses to the Software.

Licensee shall not (i) use the Software to set up a productive live system, for development purposes or any other purposes apart
from evaluating the Software; (ii) copy any part of the Software except to make one copy for back-up purposes; (iii) distribute,
disclose, market, rent, lease, or transfer the Software or act as a service bureau with respect to the Software; (iv) export the
Software or install it in multiple locations; (v) disclose any confidential information provided by Spryker; (vi) modify or make
derivative works of the Software; or (vii) allow others to make or obtain copies of the Software.

THE SOFTWARE IS PROVIDED “AS-IS” AND WITHOUT WARRANTY OF ANY KIND. SPRYKER DISCLAIMS ALL WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, TITLE, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. SPRYKER WILL NOT
BE LIABLE FOR ANY DAMAGES ASSOCIATED WITH THE SOFTWARE, INCLUDING WITHOUT LIMITATION ORDINARY, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL
DAMAGES OF ANY KIND, INCLUDING BUT NOT LIMITED TO DAMAGES RELATING TO LOST DATA OR LOST PROFITS, EVEN IF SPRYKER HAS BEEN ADVISED OF
THE POSSIBILITY OF SUCH DAMAGES.

Licensee's license to use the Software shall terminate on the earlier of (i) the expiration of the Evaluation Period, or (ii) the date
both parties enter into a definitive agreement for the provision by Spryker to Licensee of a non-evaluation license to the Software.
Upon termination of the license as provided above, Licensee shall promptly destroy the Software and any back-up copy of the Software
made during the Evaluation Period if Spryker and the Licensee have not agreed a non-evaluation license to the Software.

This Agreement shall be governed by the laws of Germany to the exclusion of IPR (International Law) and the United Nations Convention
on Contracts for the International Sale of Goods (CISG). The parties consent to the jurisdiction of the courts in Berlin (Germany).

This Agreement is not assignable or transferable by Licensee and any attempt to do so is null and void.

This Agreement constitutes the entire agreement between the parties concerning Licensee’s use of the Software. This Agreement supersedes
any prior verbal understanding between the parties and any Licensee purchase order or other ordering document, regardless of whether such
document is received by Spryker before or after execution of this Agreement. This Agreement may be amended only in a writing signed by
an authorized officer of Spryker.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Router Module
[![Build Status](https://travis-ci.org/spryker/router.svg)](https://travis-ci.org/spryker/router)
[![Coverage Status](https://coveralls.io/repos/github/spryker/router/badge.svg)](https://coveralls.io/github/spryker/router)

Router module handles application routing.

## Installation

```
composer require spryker/router
```

## Documentation

[Spryker Documentation](https://academy.spryker.com/developing_with_spryker/module_guide/modules.html)
19 changes: 19 additions & 0 deletions codeception.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace: Router
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
suite_class: \PHPUnit\Framework\TestSuite
colors: true
memory_limit: 1024M
log: true
coverage:
enabled: true
whitelist:
include:
- 'src/*.php'
39 changes: 39 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "spryker/router",
"type": "library",
"description": "Router module",
"license": "proprietary",
"require": {
"php": ">=7.1",
"spryker/event-dispatcher-extension": "^1.0.0"
},
"require-dev": {
"spryker/code-sniffer": "*",
"spryker/container": "*",
"spryker/event-dispatcher": "*",
"spryker/kernel": "*",
"spryker/symfony": "*",
"spryker/testify": "*"
},
"suggest": {
"spryker/container": "If you want to use EventDispatcher plugin.",
"spryker/event-dispatcher": "If you want to use EventDispatcher plugin.",
"spryker/kernel": "If you want to use EventDispatcher plugin.",
"spryker/symfony": "If you want to use EventDispatcher plugin."
},
"autoload": {
"psr-4": {
"Spryker\\": "src/Spryker/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"config": {
"sort-packages": true
}
}
3 changes: 3 additions & 0 deletions phpstan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"defaultLevel": 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?php

/**
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
*/

namespace Spryker\Yves\Router\Plugin\EventDispatcher;

use Spryker\Service\Container\ContainerInterface;
use Spryker\Shared\EventDispatcher\EventDispatcherInterface;
use Spryker\Shared\EventDispatcherExtension\Dependency\Plugin\EventDispatcherPluginInterface;
use Spryker\Yves\Kernel\AbstractPlugin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Routing\RequestContextAwareInterface;

class RouterLocaleEventDispatcherPlugin extends AbstractPlugin implements EventDispatcherPluginInterface
{
protected const EVENT_PRIORITY_KERNEL_REQUEST = 16;
protected const EVENT_PRIORITY_KERNEL_FINISH_REQUEST = 0;

protected const SERVICE_URL_MATCHER = 'url_matcher';
protected const SERVICE_REQUEST_STACK = 'request_stack';

/**
* {@inheritdoc}
* - Adds event listener that set the locale to the router context.
*
* @api
*
* @param \Spryker\Shared\EventDispatcher\EventDispatcherInterface $eventDispatcher
* @param \Spryker\Service\Container\ContainerInterface $container
*
* @return \Spryker\Shared\EventDispatcher\EventDispatcherInterface
*/
public function extend(EventDispatcherInterface $eventDispatcher, ContainerInterface $container): EventDispatcherInterface
{
$eventDispatcher = $this->addListeners($eventDispatcher, $container);

return $eventDispatcher;
}

/**
* @param \Spryker\Shared\EventDispatcher\EventDispatcherInterface $eventDispatcher
* @param \Spryker\Service\Container\ContainerInterface $container
*
* @return \Spryker\Shared\EventDispatcher\EventDispatcherInterface
*/
protected function addListeners(EventDispatcherInterface $eventDispatcher, ContainerInterface $container): EventDispatcherInterface
{
$eventDispatcher = $this->addRequestKernelEventListener($eventDispatcher, $container);
$eventDispatcher = $this->addFinishRequestKernelEventListener($eventDispatcher, $container);

return $eventDispatcher;
}

/**
* @param \Spryker\Shared\EventDispatcher\EventDispatcherInterface $eventDispatcher
* @param \Spryker\Service\Container\ContainerInterface $container
*
* @return \Spryker\Shared\EventDispatcher\EventDispatcherInterface
*/
protected function addRequestKernelEventListener(EventDispatcherInterface $eventDispatcher, ContainerInterface $container): EventDispatcherInterface
{
$eventDispatcher->addListener(
KernelEvents::REQUEST,
function (GetResponseEvent $event) use ($container) {
$request = $event->getRequest();
$this->setRouterContext($request, $this->getUrlMatcher($container));
},
static::EVENT_PRIORITY_KERNEL_REQUEST
);

return $eventDispatcher;
}

/**
* @param \Spryker\Shared\EventDispatcher\EventDispatcherInterface $eventDispatcher
* @param \Spryker\Service\Container\ContainerInterface $container
*
* @return \Spryker\Shared\EventDispatcher\EventDispatcherInterface
*/
protected function addFinishRequestKernelEventListener(EventDispatcherInterface $eventDispatcher, ContainerInterface $container): EventDispatcherInterface
{
$eventDispatcher->addListener(
KernelEvents::FINISH_REQUEST,
function (FinishRequestEvent $event) use ($container) {
$requestStack = $this->getRequestStack($container);
$parentRequest = $requestStack->getParentRequest();
if ($parentRequest !== null) {
$this->setRouterContext($parentRequest, $this->getUrlMatcher($container));
}
},
static::EVENT_PRIORITY_KERNEL_FINISH_REQUEST
);

return $eventDispatcher;
}

/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Symfony\Component\Routing\RequestContextAwareInterface $router
*
* @return \Symfony\Component\Routing\RequestContextAwareInterface
*/
protected function setRouterContext(Request $request, RequestContextAwareInterface $router): RequestContextAwareInterface
{
$router->getContext()->setParameter('_locale', $request->getLocale());

return $router;
}

/**
* @param \Spryker\Service\Container\ContainerInterface $container
*
* @return \Symfony\Component\Routing\RequestContextAwareInterface
*/
protected function getUrlMatcher(ContainerInterface $container): RequestContextAwareInterface
{
return $container->get(static::SERVICE_URL_MATCHER);
}

/**
* @param \Spryker\Service\Container\ContainerInterface $container
*
* @return \Symfony\Component\HttpFoundation\RequestStack
*/
protected function getRequestStack(ContainerInterface $container): RequestStack
{
return $container->get(static::SERVICE_REQUEST_STACK);
}
}
Loading

0 comments on commit 5812d58

Please sign in to comment.