<?php
namespace Moto\System; use Moto; abstract class PluginConnector { CONST PLUGIN_NAME = null; final public function __construct() { $this->_onConstructPlugin(); } protected function _onConstructPlugin() { } abstract public function compatibleApiVersions(); public function getDetails() { $plugin = PluginManager::findLocalPluginByName($this->getName()); if ($plugin) { return $plugin->toArray(); } return null; } final public function getName() { return (string) static::PLUGIN_NAME; } public function getRequirementsErrors() { return null; } public function bootstrap() { } public function getNamespace() { return ''; } final public function getFolder() { return Moto\System\PluginManager::getPluginFolderByName($this->getName()); } final public function getPath() { return Moto\System\PluginManager::getPluginPathByName($this->getName()); } final public function getAbsolutePath() { return Moto\System::getAbsolutePath($this->getPath()); } final public function getRelativePath() { return Moto\System::getRelativePath($this->getPath()); } final public function getAbsoluteUrl() { return Moto\System::getAbsoluteUrl($this->getPath()); } final public function getRelativeUrl() { return Moto\System::getRelativeUrl($this->getPath()); } public function getNgModuleNames() { return array( 'backend' => str_replace('/', '.', $this->getName()) . '.backend', 'frontend' => str_replace('/', '.', $this->getName()) . '.frontend', ); } public function getWidgets() { return []; } public function getAssets() { return []; } public function install() { } public function activate() { } public function deactivate() { } public function uninstall() { } public function getUpdateSteps() { return null; } final public function processAction($name, $params = null) { $method = 'on' . Moto\Util::toStudlyCase(Moto\Util::toSnakeCase($name)) . 'Action'; if (method_exists($this, $method)) { return $this->{$method}($params); } return null; } public function updateDatabase($params) { return true; } final public function fireEvent($name, $params = null, $silent = false) { $method = 'on' . Moto\Util::toStudlyCase(Moto\Util::toSnakeCase($name)); if (method_exists($this, $method)) { try { return $this->{$method}($params); } catch(\Exception $e) { if (!$silent) { throw $e; } } } } } 