Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

[WIP] [2.0] Introduced the concept of loaders #294

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ cache:

env:
matrix:
- SYMFONY_VERSION=2.8.*
- SYMFONY_VERSION=2.8.*
global:
- SYMFONY_DEPRECATIONS_HELPER=weak

matrix:
include:
- php: 5.6
- php: 7.0
Copy link
Member

Choose a reason for hiding this comment

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

is LTS for 5.6 over now?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, 5.6 is still tested (see the PHP version list). However, when testing all different supported Symfony versions, we should use the latest version around (as it's the quickest).

env: DEPS=dev SYMFONY_VERSION=3.1.*
- php: 5.5
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 5.6
- php: 7.0
env: DEPS=dev COMPOSER_FLAGS="--prefer-stable" SYMFONY_VERSION=3.0.*
fast_finish: true

Expand Down
24 changes: 16 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ Changelog
=========

* **2016-06-18**: [BC BREAK] Removed all `*.class` parameters.
* **2016-05-08**: [BC BREAK] Removed `showAtion` in favor of `listAction` in the `SuggestionProviderController`.
* **2016-05-02**: [BC BREAK] Dropped PHP <5.5 support.
* **2016-05-02**: [BC BREAK] Dropped Symfony <2.8 support.
* **2016-05-31**: [BC BREAK] Removed `CacheInterface` and `FileCache`, use
Copy link
Member

Choose a reason for hiding this comment

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

showAction

PSR-6 cache instead.
* **2016-05-27**: [BC BREAK] Removed `SeoPresentation::addExtractor()`, use
`ExtractorLoader::addExtractor()` instead.
* **2016-05-27**: [BC BREAK] Changed the fourth argument of the constructor of
`SeoPresentation` from `CacheInterface` to `LoaderInterface`.
* **2016-05-27**: Added loaders.
* **2016-05-08**: [BC BREAK] Removed `showAtion` in favor of `listAction` in
the `SuggestionProviderController`
* **2016-05-02**: [BC BREAK] Dropped PHP <5.5 support
* **2016-05-02**: [BC BREAK] Dropped Symfony <2.8 support

1.3.0
-----
Expand All @@ -22,15 +30,15 @@ Changelog
* **2015-08-20**: Added templates configuration and `exclusion_rules` (based on the request matcher) to
the error handling configuration
* **2015-08-12**: Added configuration for the default data class of the `seo_metadata` form type.
* **2015-07-20**: Cleaned up the sitemap generation. If you used the unreleased
* **2015-07-20**: Cleaned up the sitemap generation. If you used the unreleased
version of sitemaps, you will need to adjust your code. See https://github.com/symfony-cmf/SeoBundle/pull/225
Options are available to keep all or no voters|guessers|loaders enabled or
Options are available to keep all or no voters|guessers|loaders enabled or
enable them one by one by their service id.
* **2015-02-24**: Configuration for `content_key` moved to the `content_listener`
section, and its now possible to disable the content listener by setting
* **2015-02-24**: Configuration for `content_key` moved to the `content_listener`
section, and its now possible to disable the content listener by setting
`cmf_seo.content_listener.enabled: false`
* **2015-02-14**: Added sitemap generation
* **2015-02-14**: [BC BREAK] Changed method visibility of
* **2015-02-14**: [BC BREAK] Changed method visibility of
`SeoPresentation#getSeoMetadata()` from private to public.
* **2014-10-04**: Custom exception controller for error handling.

Expand Down
38 changes: 0 additions & 38 deletions Cache/CacheInterface.php

This file was deleted.

52 changes: 41 additions & 11 deletions Cache/ExtractorCollection.php → Cache/CachedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
namespace Symfony\Cmf\Bundle\SeoBundle\Cache;

/**
* Contains the extractors for one particular content object.
* Contains the cached data for one particular content object.
*
* @author Wouter J <[email protected]>
*/
class ExtractorCollection implements \IteratorAggregate, \Serializable
class CachedCollection implements \IteratorAggregate, \Serializable
{
/**
* @var array
*/
private $extractors;
private $data;

/**
* @var null|string
Expand All @@ -34,23 +34,53 @@ class ExtractorCollection implements \IteratorAggregate, \Serializable
private $createdAt;

/**
* @param array $extractors
* @param null|string $resource The path to the file of the content object, this is
* used to determine if the cache needs to be updated
* @param array $data
* @param null|string $resource The path to the file of the content object, this is
* used to determine if the cache needs to be updated
*/
public function __construct(array $extractors, $resource = null)
public function __construct(array $data, $resource = null)
{
$this->extractors = $extractors;
$this->data = $data;
$this->resource = $resource;
$this->createdAt = time();
}

/**
* Creates a CachedCollection based on the object and data to cache.
*
* @param object|string $objectOrClass Object instance or FQCN
* @param array $data
*
* @return static
*/
public static function createFromObject($objectOrClass, array $data)
{
$class = is_object($objectOrClass) ? get_class($objectOrClass) : $objectOrClass;

static $fileLocations = [];
if (!isset($fileLocations[$class])) {
$fileLocations[$class] = (new \ReflectionClass($objectOrClass))->getFileName();
}

return new static($data, $fileLocations[$class]);
}

public static function generateCacheItemKey($type, $class)
{
return sprintf('cmf_seo.%s.%s', $type, str_replace('\\', '.', $class));
}

/**
* {@inheritdoc}
*/
public function getIterator()
{
return new \ArrayIterator($this->extractors);
return new \ArrayIterator($this->data);
}

public function getData()
{
return $this->data;
}

/**
Expand Down Expand Up @@ -83,7 +113,7 @@ public function isFresh($timestamp = null)
public function serialize()
{
return serialize(array(
$this->extractors,
$this->data,
$this->resource,
$this->createdAt,
));
Expand All @@ -95,7 +125,7 @@ public function serialize()
public function unserialize($data)
{
list(
$this->extractors,
$this->data,
$this->resource,
$this->createdAt
) = unserialize($data);
Expand Down
131 changes: 0 additions & 131 deletions Cache/FileCache.php

This file was deleted.

1 change: 1 addition & 0 deletions DependencyInjection/CmfSeoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function load(array $configs, ContainerBuilder $container)

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
$loader->load('loaders.xml');
$loader->load('extractors.xml');

$this->loadSeoParameters($config, $container);
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Compiler/RegisterExtractorsPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class RegisterExtractorsPass implements CompilerPassInterface
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('cmf_seo.presentation')) {
if (!$container->hasDefinition('cmf_seo.loader.extractor')) {
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't rename the class too?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's still the extractor registerer, so no need to rename the class

return;
}

$strategyDefinition = $container->getDefinition('cmf_seo.presentation');
$strategyDefinition = $container->getDefinition('cmf_seo.loader.extractor');
$taggedServices = $container->findTaggedServiceIds('cmf_seo.extractor');

foreach ($taggedServices as $id => $attributes) {
Expand Down
Loading