Skip to content

Commit

Permalink
Updated the plugin component
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateu Aguiló Bosch committed Apr 17, 2015
1 parent 7082fa8 commit ddd3208
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function addConstraint($constraint_name, $options = NULL);
* Returns a validation constraint.
*
* @param string $constraint_name
* The name of the the constraint, i.e. its plugin id.
* The name of the constraint, i.e. its plugin id.
*
* @return array
* A validation constraint definition which can be used for instantiating a
Expand Down
13 changes: 13 additions & 0 deletions lib/Drupal/Component/Plugin/Discovery/CachedDiscoveryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ interface CachedDiscoveryInterface extends DiscoveryInterface {
*/
public function clearCachedDefinitions();

/**
* Disable the use of caches.
*
* Can be used to ensure that uncached plugin definitions are returned,
* without invalidating all cached information.
*
* This will also remove all local/static caches.
*
* @param bool $use_caches
* FALSE to not use any caches.
*/
public function useCaches($use_caches = FALSE);

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getDefinition($plugin_id, $exception_on_invalid = TRUE);
*
* @return mixed[]
* An array of plugin definitions (empty array if no definitions were
* found).
* found). Keys are plugin IDs.
*/
public function getDefinitions();

Expand Down
48 changes: 7 additions & 41 deletions lib/Drupal/Component/Plugin/LazyPluginCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @ingroup plugin_api
*/
abstract class LazyPluginCollection implements \Iterator, \Countable {
abstract class LazyPluginCollection implements \IteratorAggregate, \Countable {

/**
* Stores all instantiated plugins.
Expand Down Expand Up @@ -147,46 +147,12 @@ public function removeInstanceId($instance_id) {
$this->remove($instance_id);
}

/**
* {@inheritdoc}
*/
public function current() {
return $this->get($this->key());
}

/**
* {@inheritdoc}
*/
public function next() {
next($this->instanceIDs);
}

/**
* {@inheritdoc}
*/
public function key() {
return key($this->instanceIDs);
}

/**
* {@inheritdoc}
*/
public function valid() {
$key = key($this->instanceIDs);
// Check the key is valid but also that this key yields a plugin from get().
// There can be situations where configuration contains data for a plugin
// that cannot be instantiated. In this case, this enables us to skip that
// plugin during iteration.
// @todo Look at removing when https://drupal.org/node/2080823 has been
// solved.
return $key !== NULL && $key !== FALSE && $this->get($key);
}

/**
* {@inheritdoc}
*/
public function rewind() {
reset($this->instanceIDs);
public function getIterator() {
$instances = [];
foreach ($this->getInstanceIds() as $instance_id) {
$instances[$instance_id] = $this->get($instance_id);
}
return new \ArrayIterator($instances);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Drupal/Component/Plugin/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"homepage": "https://drupal.org/project/drupal",
"license": "GPL-2.0+",
"require": {
"php": ">=5.4.2"
"php": ">=5.4.2",
},
"autoload": {
"psr-0": {
"Drupal\\Component\\Plugin\\": ""
}
},
}
"suggest": {
"symfony/validator": "Leveraged in the use of context aware plugins."
}
Expand Down

0 comments on commit ddd3208

Please sign in to comment.