Skip to content

Commit

Permalink
Using Parkour
Browse files Browse the repository at this point in the history
  • Loading branch information
felixgirault committed Aug 9, 2015
1 parent ecf4a98 commit b87817e
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 209 deletions.
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -19,10 +19,10 @@
"homepage": "http://github.com/essence/essence",
"minimum-stability": "dev",
"require": {
"php": ">=5.5.0",
"essence/dom": "dev-master",
"essence/http": "dev-master",
"fg/cascade": "1.0.0"
"php": ">=5.6.0",

This comment has been minimized.

Copy link
@mariuswilms

mariuswilms Aug 12, 2015

May I ask why this is now >= 5.6.0 instead of the previous >=5.5.0? I know it's recommended to use 5.6, but are there any technical requirements certain 5.6 features that are being used?

This comment has been minimized.

Copy link
@felixgirault

felixgirault Aug 12, 2015

Author Member

It is induced by fg/parkour, wich requires some of the features from 5.6.
I hesitated to make this move but I thought it would be ok to start fresh for a new version.
Are you running a 5.5 environment ?

This comment has been minimized.

Copy link
@felixgirault

felixgirault Aug 12, 2015

Author Member

In fact, I think you can still use version 3.0 on PHP 5.5, as it doesn't use methods requiring PHP 5.6 from Parkour.

This comment has been minimized.

Copy link
@mariuswilms

mariuswilms Aug 13, 2015

Thanks for the quick answers Felix.

I totally understand your motivation. And yes I/we are running on PHP 5.5 and have a couple of clients on that version requirement - we can change that for the next year or so.

If Parkours does not require 5.6 (it states 5.5 in its composer.json) I'd be happy if the version requirement for Essence also drops to 5.5. In my opinion the req can also be raised in minor version changes. Semver does not state that changes in language version requirements require a major version bump.

This comment has been minimized.

Copy link
@felixgirault

felixgirault Aug 13, 2015

Author Member

Oops, I forgot to update the composer.json of Parkour... It should be 5.6.
About semver, don't you think it's kind of a breaking API change ?

Sorry to hear that you're stuck with 5.5, but again, I didn't try recently but you should be able to use Essence 3.0 with it :)

This comment has been minimized.

Copy link
@mariuswilms

mariuswilms Aug 13, 2015

The semver spec isn't clear in that regard, thus you hear different opinions about that. My opinion is that it isn't a BC break as long as you just change the minor version (PHP 5.5 -> 5.6).

I'll probably downgrade to Essence 2.x as we can't run speculatively on 5.5.

"fg/parkour": "1.0.0"
},
"suggest": {
"ext-curl": "*"
Expand Down
4 changes: 2 additions & 2 deletions lib/Essence/Di/Container.php
Expand Up @@ -6,7 +6,7 @@
*/
namespace Essence\Di;

use Essence\Utility\Hash;
use Parkour\Transform;
use Closure;


Expand Down Expand Up @@ -73,7 +73,7 @@ public function set($property, $value) {
* @param array $properties Properties to merge.
*/
public function configure(array $properties) {
$this->_properties = Hash::merge(
$this->_properties = Transform::merge(
$this->_properties,
$properties
);
Expand Down
4 changes: 2 additions & 2 deletions lib/Essence/Extractor.php
Expand Up @@ -7,7 +7,7 @@
namespace Essence;

use Essence\Provider\Collection;
use Essence\Utility\Hash;
use Parkour\Transform;
use Exception;


Expand Down Expand Up @@ -69,7 +69,7 @@ public function extract($url, array $options = []) {
* @return array An array of informations, indexed by URL.
*/
public function extractAll(array $urls, array $options = []) {
return Hash::combine($urls, function($url) use ($options) {
return Transform::combine($urls, function($url) use ($options) {
yield $url => $this->extract($url, $options);
});
}
Expand Down
48 changes: 26 additions & 22 deletions lib/Essence/Provider.php
Expand Up @@ -7,7 +7,8 @@
namespace Essence;

use Essence\Media;
use Cascade\Cascade;
use Parkour\Traverse;
use Parkour\Functor\Execute;



Expand All @@ -19,18 +20,18 @@ abstract class Provider {
/**
* Preparators.
*
* @var Cascade
* @var array
*/
protected $_Preparators = null;
protected $_preparators = [];



/**
* Presenters.
*
* @var Cascade
* @var array
*/
protected $_Presenters = null;
protected $_presenters = [];



Expand All @@ -44,33 +45,23 @@ abstract class Provider {


/**
* Constructor.
*/
public function __construct() {
$this->_Preparators = new Cascade();
$this->_Presenters = new Cascade();
}



/**
*
* Sets preparators.
*
* @param array $preparators Preparators.
*/
public function setPreparators(array $preparators) {
$this->_Preparators->setFilters($preparators);
$this->_preparators = $preparators;
}



/**
*
* Sets presenters.
*
* @param array $presenters Presenters.
*/
public function setPresenters(array $presenters) {
$this->_Presenters->setFilters($presenters);
$this->_presenters = $presenters;
}


Expand All @@ -82,13 +73,26 @@ public function setPresenters(array $presenters) {
* @param array $options Custom options to be interpreted by the provider.
* @return Media Embed informations.
*/
public final function extract($url, array $options = []) {
$url = $this->_Preparators->filter($url);
final public function extract($url, array $options = []) {
$url = $this->filter($url, $this->_preparators);

$Media = $this->_extract($url, $options);
$Media->setDefault('url', $url);

return $this->_Presenters->filter($Media);
return $this->filter($Media, $this->_presenters);
}



/**
* Filters a value through a set of functions.
*
* @param mixed $value Value.
* @param array $filters Filters.
* @return mixed Filtered value.
*/
private function filter($value, array $filters) {
return Traverse::reduce($filters, new Execute(), $value);
}


Expand Down
6 changes: 2 additions & 4 deletions lib/Essence/Provider/MetaTags.php
Expand Up @@ -11,7 +11,7 @@
use Essence\Provider;
use Essence\Dom\Document\Factory\Native as Dom;
use Essence\Http\Client as Http;
use Essence\Utility\Hash;
use Parkour\Transform;
use Exception;


Expand Down Expand Up @@ -55,8 +55,6 @@ class MetaTags extends Provider {
* @param Dom $Dom DOM parser.
*/
public function __construct(Http $Http, Dom $Dom) {
parent::__construct();

$this->_Http = $Http;
$this->_Dom = $Dom;
}
Expand Down Expand Up @@ -115,7 +113,7 @@ protected function _extractMetas($html) {
* @return Media Media.
*/
protected function _media(array $metas) {
$metas = Hash::combine($metas, function($Meta) {
$metas = Transform::combine($metas, function($Meta) {
yield $Meta->get('property') => $Meta->get('content');
});

Expand Down
2 changes: 0 additions & 2 deletions lib/Essence/Provider/OEmbed.php
Expand Up @@ -68,8 +68,6 @@ class OEmbed extends Provider {
* @param Dom $Dom DOM parser.
*/
public function __construct(Http $Http, Dom $Dom) {
parent::__construct();

$this->_Http = $Http;
$this->_Dom = $Dom;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Essence/Provider/Presenter/Reindexer.php
Expand Up @@ -8,7 +8,7 @@

use Essence\Provider\Presenter;
use Essence\Media;
use Essence\Utility\Hash;
use Parkour\Transform;



Expand Down Expand Up @@ -42,7 +42,7 @@ public function __construct(array $mapping) {
*/
public function present(Media $Media) {
return $Media->setProperties(
Hash::reindex(
Transform::reindex(
$Media->properties(),
$this->_mapping
)
Expand Down
82 changes: 0 additions & 82 deletions lib/Essence/Utility/Hash.php

This file was deleted.

90 changes: 0 additions & 90 deletions tests/Essence/Utility/HashTest.php

This file was deleted.

0 comments on commit b87817e

Please sign in to comment.