/** * * @param array|string $data Data that describes the plugin. * The following indices are required: * * `basename` - The plugin basename, or full path to plugin's main file. See {@see getBasename()}. * Other indices explicitly handled by this class: * * `component_factory` - Instance or name of a component factory class. * * `text_domain` - The text domain used for translation by this plugin. See {@see getTextDomain}. * * `name` - The human-readable name of the plugin. See {@see getName()}. * Any other data will just be added to this instances internal data. * @param ComponentFactoryInterface A factory that will create components for this plugin. * * @throws Exception If required fields are not specified. */ public function __construct($data, ComponentFactoryInterface $factory = null) { if (!is_array($data)) { $data = array('basename' => $data); } // Handling basename if (!isset($data['basename'])) { throw $this->exception('Could not create plugin instance: "basename" must be specified', array(__NAMESPACE__, 'Exception')); } $basename = trim($data['basename']); // Account for full path to main file. if (substr($basename, 0, 1) === '/' || substr_count($basename, '/') >= 2) { $basename = static::getPluginBasename($basename); } $data['basename'] = $basename; // Normalizing and setting component factory if (is_null($factory) && isset($data['component_factory'])) { $factory = $data['component_factory']; } if ($factory) { $this->setFactory($factory); } $this->setBasename($basename); parent::__construct($data); }
/** * * @since 4.8.1 * @param PluginInterface|array $data The instance of the * add-on, of which this is to be a component. Alternatively, an array with data, which must have the 'plugin' * index set to that instance. */ public function __construct($data) { // Allowing specifying parent as the only argument if (!is_array($data)) { $data = array('plugin' => $data); } // Making sure the parent is specified if (!isset($data['plugin']) || !$data['plugin'] instanceof PluginInterface) { throw $this->exception(array('Could not create component: The "%1$s" index must be a plugin instance'), array(__NAMESPACE__, 'Exception')); } $plugin = $data['plugin']; unset($data['plugin']); $this->_plugin = $plugin; parent::__construct($data); }