8000 Add symfony/contracts: a set of abstractions extracted out of the Symfony components by nicolas-grekas · Pull Request #27093 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add symfony/contracts: a set of abstractions extracted out of the Symfony components #27093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2018
Merged
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: 1 addition & 1 deletion .github/build-packages.php 8000
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

$packages[$package->name][$package->version] = $package;

$versions = file_get_contents('https://packagist.org/p/'.$package->name.'.json');
$versions = @file_get_contents('https://packagist.org/p/'.$package->name.'.json') ?: sprintf('{"packages":{"%s":{"dev-master":%s}}}', $package->name, file_get_contents($dir.'/composer.json'));
$versions = json_decode($versions)->packages->{$package->name};

if ($package->version === str_replace('-dev', '.x-dev', $versions->{'dev-master'}->extra->{'branch-alias'}->{'dev-master'})) {
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ before_install:
deps=skip
skip=1
else
COMPONENTS=$(find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist -printf '%h\n')
COMPONENTS=$(find src/Symfony -mindepth 2 -type f -name phpunit.xml.dist -printf '%h\n')
fi

- |
Expand Down Expand Up @@ -181,7 +181,7 @@ install:
SYMFONY_VERSION=$(git ls-remote --heads | grep -o '/[1-9].*' | tail -n 1 | sed s/.//) &&
git fetch origin $SYMFONY_VERSION &&
git checkout -m FETCH_HEAD &&
COMPONENTS=$(find src/Symfony -mindepth 3 -type f -name phpunit.xml.dist -printf '%h\n')
COMPONENTS=$(find src/Symfony -mindepth 2 -type f -name phpunit.xml.dist -printf '%h\n')
elif [[ ! $skip ]]; then
SYMFONY_VERSION=$(cat composer.json | grep '^ *"dev-master". *"[1-9]' | grep -o '[0-9.]*')
fi
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"symfony/cache": "self.version",
"symfony/config": "self.version",
"symfony/console": "self.version",
"symfony/contracts": "1.0.0",
"symfony/css-selector": "self.version",
"symfony/dependency-injection": "self.version",
"symfony/debug": "self.version",
Expand Down Expand Up @@ -118,7 +119,8 @@
"Symfony\\Bridge\\ProxyManager\\": "src/Symfony/Bridge/ProxyManager/",
"Symfony\\Bridge\\Twig\\": "src/Symfony/Bridge/Twig/",
"Symfony\\Bundle\\": "src/Symfony/Bundle/",
"Symfony\\Component\\": "src/Symfony/Component/"
"Symfony\\Component\\": "src/Symfony/Component/",
"Symfony\\Contract\\": "src/Symfony/Contract/"
},
"classmap": [
"src/Symfony/Component/Intl/Resources/stubs"
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<directory>./src/Symfony/Bridge/*/Tests/</directory>
<directory>./src/Symfony/Component/*/Tests/</directory>
<directory>./src/Symfony/Component/*/*/Tests/</directory>
<directory>./src/Symfony/Contract/*/Tests/</directory>
<directory>./src/Symfony/Bundle/*/Tests/</directory>
</testsuite>
</testsuites>
Expand All @@ -44,6 +45,7 @@
<directory>./src/Symfony/Bridge/*/Tests</directory>
<directory>./src/Symfony/Component/*/Tests</directory>
<directory>./src/Symfony/Component/*/*/Tests</directory>
<directory>./src/Symfony/Contract/*/Tests</directory>
<directory>./src/Symfony/Bundle/*/Tests</directory>
<directory>./src/Symfony/Bundle/*/Resources</directory>
<directory>./src/Symfony/Component/*/Resources</directory>
Expand All @@ -52,6 +54,7 @@
<directory>./src/Symfony/Bundle/*/vendor</directory>
<directory>./src/Symfony/Component/*/vendor</directory>
<directory>./src/Symfony/Component/*/*/vendor</directory>
<directory>./src/Symfony/Contract/*/vendor</directory>
</exclude>
</whitelist>
</filter>
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contract\Service\ResetInterface;

abstract class DoctrineType extends AbstractType
abstract class DoctrineType extends AbstractType implements ResetInterface
{
/**
* @var ManagerRegistry
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Doctrine/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"require": {
"php": "^7.1.3",
"doctrine/common": "~2.4@stable",
"symfony/contracts": "^1.0",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.0"
},
Expand Down
11 changes: 10 additions & 1 deletion src/Symfony/Bridge/Monolog/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
use Monolog\Logger as BaseLogger;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Contract\Service\ResetInterface;

/**
* Logger.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Logger extends BaseLogger implements DebugLoggerInterface
class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -56,6 +57,14 @@ public function clear()
}
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->clear();
}

/**
* Returns a DebugLoggerInterface instance if one is registered with this logger.
*
Expand Down
11 changes: 10 additions & 1 deletion src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Contract\Service\ResetInterface;

class DebugProcessor implements DebugLoggerInterface
class DebugProcessor implements DebugLoggerInterface, ResetInterface
{
private $records = array();
private $errorCount = array();
Expand Down Expand Up @@ -91,4 +92,12 @@ public function clear()
$this->records = array();
$this->errorCount = array();
}

/**
* {@inheritdoc}
*/
public function reset()
{
$this->clear();
}
}
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Monolog/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"require": {
"php": "^7.1.3",
"monolog/monolog": "~1.19",
"symfony/contracts": "^1.0",
"symfony/http-kernel": "~3.4|~4.0"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\Marshaller\DefaultMarshaller;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\DirectoryResource;
Expand Down Expand Up @@ -95,6 +94,7 @@
use Symfony\Component\Workflow;
use Symfony\Component\Yaml\Command\LintCommand as BaseYamlLintCommand;
use Symfony\Component\Yaml\Yaml;
use Symfony\Contract\Service\ResetInterface;

/**
* FrameworkExtension.
Expand Down Expand Up @@ -324,7 +324,7 @@ public function load(array $configs, ContainerBuilder $container)
->addTag('kernel.cache_warmer');
$container->registerForAutoconfiguration(EventSubscriberInterface::class)
->addTag('kernel.event_subscriber');
$container->registerForAutoconfiguration(ResettableInterface::class)
$container->registerForAutoconfiguration(ResetInterface::class)
->addTag('kernel.reset', array('method' => 'reset'));
$container->registerForAutoconfiguration(ProcessorInterface::class)
->addTag('monolog.processor');
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Cache/Adapter/ChainAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Component\Cache\Traits\GetTrait;
use Symfony\Contract\Service\ResetInterface;

/**
* Chains several adapters together.
Expand Down Expand Up @@ -301,7 +302,7 @@ public function prune()
public function reset()
{
foreach ($this->adapters as $adapter) {
if ($adapter instanceof ResettableInterface) {
if ($adapter instanceof ResetInterface) {
$adapter->reset();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Cache/Adapter/TraceableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Contract\Service\ResetInterface;

/**
* An adapter that collects data about all cache calls.
Expand Down Expand Up @@ -225,7 +226,7 @@ public function prune()
*/
public function reset()
{
if (!$this->pool instanceof ResettableInterface) {
if (!$this->pool instanceof ResetInterface) {
return;
}
$event = $this->start(__FUNCTION__);
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Cache/DoctrineProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\Common\Cache\CacheProvider;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Contract\Service\ResetInterface;

/**
* @author Nicolas Grekas <p@tchwork.com>
Expand All @@ -39,7 +40,7 @@ public function prune()
*/
public function reset()
{
if ($this->pool instanceof ResettableInterface) {
if ($this->pool instanceof ResetInterface) {
$this->pool->reset();
}
$this->setNamespace($this->getNamespace());
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Component/Cache/ResettableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

namespace Symfony\Component\Cache;

use Symfony\Contract\Service\ResetInterface;

/**
* Resets a pool's local state.
*/
interface ResettableInterface
interface ResettableInterface extends ResetInterface
{
public function reset();
}
3 changes: 2 additions & 1 deletion src/Symfony/Component/Cache/Simple/ChainCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Contract\Service\ResetInterface;

/**
* Chains several caches together.
Expand Down Expand Up @@ -244,7 +245,7 @@ public function prune()
public function reset()
{
foreach ($this->caches as $cache) {
if ($cache instanceof ResettableInterface) {
if ($cache instanceof ResetInterface) {
$cache->reset();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Cache/Simple/TraceableCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Contract\Service\ResetInterface;

/**
* An adapter that collects data about all cache calls.
Expand Down Expand Up @@ -200,7 +201,7 @@ public function prune()
*/
public function reset()
{
if (!$this->pool instanceof ResettableInterface) {
if (!$this->pool instanceof ResetInterface) {
return;
}
$event = $this->start(__FUNCTION__);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Traits/ProxyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Symfony\Component\Cache\Traits;

use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\ResettableInterface;
use Symfony\Contract\Service\ResetInterface;

/**
* @author Nicolas Grekas <p@tchwork.com>
Expand All @@ -36,7 +36,7 @@ public function prune()
*/
public function reset()
{
if ($this->pool instanceof ResettableInterface) {
if ($this->pool instanceof ResetInterface) {
$this->pool->reset();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Cache/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"php": "^7.1.3",
"psr/cache": "~1.0",
"psr/log": "~1.0",
"psr/simple-cache": "^1.0"
"psr/simple-cache": "^1.0",
"symfony/contracts": "^1.0"
},
"require-dev": {
"cache/integration-tests": "dev-master",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
namespace Symfony\Component\Console\Formatter;

use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Contract\Service\ResetInterface;

/**
* @author Jean-François Simon <contact@jfsimon.fr>
*/
class OutputFormatterStyleStack
class OutputFormatterStyleStack implements ResetInterface
{
/**
* @var OutputFormatterStyleInterface[]
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Console/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": "^7.1.3",
"symfony/contracts": "^1.0",
"symfony/polyfill-mbstring": "~1.0"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@

namespace Symfony\Component\DependencyInjection;

use Symfony\Contract\Service\ResetInterface;

/**
* ResettableContainerInterface defines additional resetting functionality
* for containers, allowing to release shared services when the container is
* not needed anymore.
*
* @author Christophe Coevoet <stof@notk.org>
*/
interface ResettableContainerInterface extends ContainerInterface
interface ResettableContainerInterface extends ContainerInterface, ResetInterface
{
/**
* Resets shared services from the container.
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/DependencyInjection/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"require": {
"php": "^7.1.3",
"psr/container": "^1.0"
"psr/container": "^1.0",
"symfony/contracts": "^1.0"
},
"require-dev": {
"symfony/yaml": "~3.4|~4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
namespace Symfony\Component\EventDispatcher\Debug;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Contract\Service\ResetInterface;

/**
* @deprecated since Symfony 4.1
*
* @author Fabien Potencier <fabien@symfony.com>
*/
interface TraceableEventDispatcherInterface extends EventDispatcherInterface
interface TraceableEventDispatcherInterface extends EventDispatcherInterface, ResetInterface
{
/**
* Gets the called listeners.
Expand All @@ -33,9 +34,4 @@ public function getCalledListeners();
* @return array An array of not called listeners
*/
public function getNotCalledListeners();

/**
* Resets the trace.
*/
public function reset();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we should change the reset() method in EventDataCollector to read $this->dispatcher instanceof ResettableInterface instead of $this->dispatcher instanceof TraceableEventDispatcherInterface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, is this reset() method really tied with dependency injection? I think Symfony\Contract\DependencyInjection\ResettableInterface should be Symfony\Contract\HttpKernel\ResettableInterface instead, no?

This comment was marked as resolved.

Copy link
Contributor
@unkind unkind Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TraceableEventDispatcherInterface::reset() means "Resets the trace" like description in phpdoc says.
But what does mean TraceableEventDispatcher extends ResettableInterface or just EventDispatcher implements ResettableInterface ?
"Resets event dispatcher" (remove all subscribers?)?
"Resets trace"?
When reset() method is attached to specific concept/model, you have description of the method, it makes whole model more cohesive.
From my PoV, such approach ruins cohesion and it messes up semantics of reset() method for each context.

Just imagine one would notice length() method on Line and Movie classes. Line::length() returns meters (integer) and Movie::length() returns seconds (integer as well). Does it look like a good idea to make

interface HasLength
{
    public function length(): int;
}

? I don't think so. Yes, technically, they have the same signature, but they are different.

}
3 changes: 2 additions & 1 deletion src/Symfony/Component/EventDispatcher/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
}
],
"require": {
"php": "^7.1.3"
"php": "^7.1.3",
"symfony/contracts": "^1.0"
},
"require-dev": {
"symfony/dependency-injection": "~3.4|~4.0",
Expand Down
Loading
0