Permalink
Browse files

IPlugin interface [#130]

  • Loading branch information...
1 parent affd347 commit 19deb0d76684747d6a2b9a51b024364408460694 @Andrewsville Andrewsville committed Apr 11, 2012
@@ -14,9 +14,11 @@
namespace ApiGen\Config\Extension;
use Nette\Config\CompilerExtension;
+use Nette\InvalidStateException;
use Nette\Loaders\RobotLoader;
use Nette\Utils\PhpGenerator\ClassType;
use Nette\Utils\PhpGenerator\PhpLiteral;
+use ReflectionClass;
/**
* ApiGen plugins DIC extension.
@@ -94,6 +96,11 @@ public function afterCompile(ClassType $class)
// Plugin event listeners
foreach ($this->containerBuilder->parameters['plugins'] as $name => $definition) {
+ $reflection = new ReflectionClass($definition['class']);
+ if (!$reflection->implementsInterface('ApiGen\\IPlugin')) {
+ throw new InvalidStateException(sprintf('Plugin "%s" does not implement interface ApiGen\\IPlugin', $name));
+ }
+
if (!empty($definition['events'])) {
foreach ($definition['events'] as $eventDefinition) {
preg_match(self::EVENT_LISTENER_FORMAT, $eventDefinition, $matches);
View
@@ -0,0 +1,27 @@
+<?php
+
+/**
+ * ApiGen 3.0dev - API documentation generator for PHP 5.3+
+ *
+ * Copyright (c) 2010-2011 David Grudl (http://davidgrudl.com)
+ * Copyright (c) 2011-2012 Jaroslav Hanslík (https://github.com/kukulich)
+ * Copyright (c) 2011-2012 Ondřej Nešpor (https://github.com/Andrewsville)
+ *
+ * For the full copyright and license information, please view
+ * the file LICENSE.md that was distributed with this source code.
+ */
+
+namespace ApiGen;
+
+/**
+ * Basic interface implemented by all user plugins.
+ */
+interface IPlugin
+{
+ /**
+ * Sets plugin options from the configuration.
+ *
+ * @param array $options Plugin options
+ */
+ public function setOptions(array $options);
+}
@@ -1,6 +1,8 @@
# To prevent conflicts between internal services and user plusings, you should
# always prefix your plugin name with "plugin.". Use bare service names only when
# you really want to override an internal service with your own one.
+# No matter if you override an internal service or create a new one, its main class
+# (see below) has to implement the \ApiGen\IPlugin interface.
plugin.name:
# ApiGen will put this path into its plugin autoloading mechanism. Your plugin
@@ -20,7 +22,7 @@ plugin.name:
- methodName@originName::eventName
# Plugin options. This whole part of the config file will be passed to the setOptions()
- # method as an array.
+ # method (defined by the IPlugin interface) as an array.
options:
option1: value1
option2: [value21, value22]
@@ -14,6 +14,7 @@
namespace ApiGen\Contrib;
use ApiGen\ConsoleLogger;
+use ApiGen\IPlugin;
use ApiGen\IProgressBar;
use ApiGen\Object;
@@ -22,7 +23,7 @@
*
* Requires the console logger {@see \ApiGen\ConsoleLogger}.
*/
-class PhpunitProgressBar extends Object implements IProgressBar
+class PhpunitProgressBar extends Object implements IPlugin, IProgressBar
{
/**
* Console logger.
@@ -77,6 +78,22 @@ public function __construct(ConsoleLogger $logger)
}
/**
+ * Sets plugin options from the configuration.
+ *
+ * @param array $options Plugin options
+ */
+ public function setOptions(array $options)
+ {
+ if (isset($options['maxWidth'])) {
+ $this->maxWidth = (int) $options['maxWidth'];
+ }
+
+ if (isset($options['maxSteps'])) {
+ $this->maxSteps = (int) $options['maxSteps'];
+ }
+ }
+
+ /**
* Initializes the progressbar.
*
* @param integer $maximum Maximum value

0 comments on commit 19deb0d

Please sign in to comment.