Установить модуль из Marketplace

@param string $plugin название модуля
@param Callable $status метод или функция для приема сообщений
@param Zend_Translate $translator класс-переводчик
8006
public static function install($plugin, $status = null, $translator = null)
    {
		
        if (!$translator) $translator = Application::getInstance()->getTranslator();
		    
		$pluginPath = WWWROOT . PLUGIN_DIR . '/' . $plugin;
		$archiveFile = WWWROOT . PLUGIN_DIR . '/' . $plugin . '.zip';	

		if ($status) $status($translator->_('Загрузка плагина'), true);

        if (!file_exists(WWWROOT . PLUGIN_DIR))
            mkdir(WWWROOT . PLUGIN_DIR);

        if (!is_writable(WWWROOT . PLUGIN_DIR))
            throw new \Exception($translator->_('Каталог') . ' ' . DOCROOT . PLUGIN_DIR . ' ' . $translator->_('недоступен для записи'));

		$d = false;   
        try
		{			
            $client = new \GuzzleHttp\Client();
			$res = $client->request('GET', PLUGINS_INFO . '?download=' . $plugin, ['verify'=>false]);
            $d = $res->getBody();

            if (!$d) throw new \Exception($translator->_('Не удалось скачать плагин'));
        } 
		catch (\Exception $e)
		{
			if ($status)
			{
				$status($translator->_('Не удалось скачать плагин.'), false);  
				$status($translator->_('Переустановка ранее загруженного плагина'), true, true); 				
			}
        }

        if ($d)
		{
            file_put_contents($archiveFile, $d);

            if ($status) $status('OK', false);  

            if (file_exists($pluginPath))
			{
				if ($status) $status($translator->_('Удаление предыдущей версии'), true);
                Util::delTree($pluginPath);
                if ($status) $status('OK', false);  
            }

			if ($status) $status($translator->_('Распаковка архива'), true);

            $zip = new \ZipArchive;
            if ($zip->open($archiveFile) === TRUE)
			{
                if (!$zip->extractTo(WWWROOT . PLUGIN_DIR)) throw new Exception($translator->_('Не удалось распаковать архив'). ' ' . $archiveFile);
                $zip->close();
                unlink($archiveFile);

            } 
			else throw new \Exception($translator->_('Не удалось открыть архив'). ' ' . $archiveFile);

            if ($status) $status('OK', false);  
        }
		
		if ($status) $status($translator->_('Модификация БД'), true);
        $schema = new Schema(); 
        $schema->fixSchema('plugin_' . $plugin);
		$schema->readDump('plugin_' . $plugin);
        if ($status) $status('OK', false);  

        if (file_exists($pluginPath . '/' . PLUGIN_INSTALL))
            include $pluginPath . '/' . PLUGIN_INSTALL;
		
		$p = new self($plugin);
		self::installRequirements($p->requires, $status, $translator);
		
	}
544934
abstract public function __construct(Request $request, Translator $translator, View $view, GridContract $grid);

    /**
     * Extend decoration.
     *
     * @param  callable  $callback
     *
     * @return $this
     */
    public function extend(callable $callback = null)
    {
        // Run the table designer.
        if (! \is_null($callback)) {
            \call_user_func($callback, $this->grid, $this->request, $this->translator);
        }

        return $this;
    }
171413
function (plugin) {
    var that = this;

    /**
     * DOM element used for updating the status of requests and list counts.
     * @type {jQuery}
     */
    this.$status = $(plugin.options.templates.status).hide().appendTo(plugin.selectpicker.$menu);
    var statusInitialized = plugin.t('statusInitialized');
    if (statusInitialized && statusInitialized.length) {
        this.setStatus(statusInitialized);
    }

    /**
     * Container for cached data.
     * @type {Object}
     */
    this.cache = {};

    /**
     * Reference the plugin for internal use.
     * @type {AjaxBootstrapSelect}
     */
    this.plugin = plugin;

    /**
     * Container for current selections.
     * @type {Array}
     */
    this.selected = [];

    /**
     * Containers for previous titles.
     */
    this.title = null;
    this.selectedTextFormat = plugin.selectpicker.options.selectedTextFormat;

    // Save initial options
    var initial_options = [];
    plugin.$element.find('option').each(function() {
        var $option = $(this);
        var value = $option.attr('value');
        initial_options.push({
            value: value,
            text: $option.text(),
            'class': $option.attr('class') || '',
            data: $option.data() || {},
            preserved: plugin.options.preserveSelected,
            selected: !!$option.attr('selected')
        });
    });
    this.cacheSet(/*query=*/'', initial_options);

    // Preserve selected options.
    if (plugin.options.preserveSelected) {
        that.selected = initial_options;
        plugin.$element.on('change.abs.preserveSelected', function (e) {
            var $selected = plugin.$element.find(':selected');
            that.selected = [];
            // If select does not have multiple selection, ensure that only the
            // last selected option is preserved.
            if (!plugin.selectpicker.multiple) {
                $selected = $selected.last();
            }
            $selected.each(function () {
                var $option = $(this);
                var value = $option.attr('value');
                that.selected.push({
                    value: value,
                    text: $option.text(),
                    'class': $option.attr('class') || '',
                    data: $option.data() || {},
                    preserved: true,
                    selected: true
                });
            });
            that.replaceOptions(that.cacheGet(that.plugin.query));
        });
    }
}
951346
public function injectTranslator($helper)
    {
        if (!$helper instanceof TranslatorAwareInterface) {
            return;
        }

        $locator = $this->getServiceLocator();

        if (!$locator) {
            return;
        }

        if ($locator->has('MvcTranslator')) {
            $helper->setTranslator($locator->get('MvcTranslator'));
            return;
        }

        if ($locator->has(TranslatorInterface::class)) {
            $helper->setTranslator($locator->get(TranslatorInterface::class));
            return;
        }

        if ($locator->has('Translator')) {
            $helper->setTranslator($locator->get('Translator'));
            return;
        }
    }
68051
protected function _camelizePlugin($plugin) {
		if (strpos($plugin, '/') === false) {
			return Inflector::camelize($plugin);
		}
		list($vendor, $plugin) = explode('/', $plugin, 2);
		return Inflector::camelize($vendor) . '/' . Inflector::camelize($plugin);
	}
98291
def translate_type(type_info, options)
    if type_info
      klass = plugin_class(type_info[:namespace], type_info[:type])
      logger.debug("Executing option translation for: #{klass.inspect}")

      options = klass.send(:translate, options) if klass.respond_to?(:translate)
    end
    options
  end
1325024
public static function setDefaultTranslator($translator = null)
    {
        if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
            self::$_defaultTranslator = $translator;
        } elseif ($translator instanceof Zend_Translate) {
            self::$_defaultTranslator = $translator->getAdapter();
        } else {
            require_once 'Zend/Validate/Exception.php';
            throw new Zend_Validate_Exception('Invalid translator specified');
        }
    }
1326289
protected function getView(TranslatorInterface $translator, $translationDomain)
    {
        /** @var View $view */
        $view = $this->container->get('symfonyid.admin.view.view');
        $view->setParam('page_title', $translator->trans('page.change_password.title', array(), $translationDomain));
        $view->setParam('page_description', $translator->trans('page.change_password.description', array(), $translationDomain));
        $view->setParam('menu', $this->container->getParameter('symfonyid.admin.menu.menu_name'));

        return $view;
    }
840205
public function addTranslation($translator)
	{
		if (!file_exists( $this->getPath().'/'.TRANSLATIONS )) return;
		$translator->addTranslation( $this->getPath().'/'.TRANSLATIONS );
	}
1177433
protected function _setTranslator($translator)
    {
        if (!(is_null($translator) || $translator instanceof StringTranslatorInterface)) {
            throw new InvalidArgumentException('Invalid translator');
        }

        $this->translator = $translator;

        return $this;
    }
1064924
private function registerPlugin(Plugin $plugin): void
    {
        if ($this->hasPlugin($plugin->getName())) {
            return;
        }

        $this->plugins[$plugin->getName()] = $plugin;
    }
6994
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);
        $context = Context::createDefaultContext();
        $plugins = $this->prepareExecution(self::LIFECYCLE_METHOD, $io, $input, $context);

        $deactivatedPluginCount = 0;
        /** @var PluginEntity $plugin */
        foreach ($plugins as $plugin) {
            if ($plugin->getInstalledAt() === null) {
                $io->note(sprintf('Plugin "%s" must be installed. Skipping.', $plugin->getName()));

                continue;
            }

            if ($plugin->getActive() === false) {
                $io->note(sprintf('Plugin "%s" must be activated. Skipping.', $plugin->getName()));

                continue;
            }

            $this->pluginLifecycleService->deactivatePlugin($plugin, $context);
            ++$deactivatedPluginCount;

            $io->text(sprintf('Plugin "%s" has been deactivated successfully.', $plugin->getName()));
        }

        if ($deactivatedPluginCount !== 0) {
            $io->success(sprintf('Deactivated %d plugin(s).', $deactivatedPluginCount));
        }
    }
675843
public function translate($id, $params = null, $domain = null, $locale = null) {
		if ($domain === null) {
			$domain = $this->handleDomain($id);
		}
		
		if ($locale === null) {
			$locale = $this->getLocale();
		} else {
			$locale = $this->normalizeLocale($locale);
		}
		
		$translation = $this->getTranslation($id, $domain, $locale, $this->fallbackLocales);
		
		if ($translation === null) {
			return $this->handleFailure($id);
		}
		
		if (! empty($this->plugins)) {
			$translation = $this->handlePlugins($locale, $translation, $params);
		}
		
		if ($params === null) {
			return $translation;
		}
		
		return strtr($translation, $this->normalizeParams($params));
	}
564314
public function autoupgradePlugin(Plugin $plugin)
    {

        if(empty($plugin) || !$plugin->isInstalled() || !$plugin->isEnabled())
            return;

        $xml = $this->loadXML($plugin->Path);

        if(empty($xml))
            return;

        if($plugin->Version != ($newversion = strval($xml->info->version))) {
            $plugin->NewVersion = $newversion;
            return;
        }

        if(!$this->TransactionManager->isTransactionInProgress())
            $this->TransactionManager->begin();

        $xmlFile = $plugin->Path.'/plugin.xml';
        $ts = $this->DateFactory->newLocalDate(filemtime($xmlFile));
        $md5 = md5_file($xmlFile);

        $changed = $this->processAspects($plugin, $log);

        if($plugin->Md5 !== $md5)
        {
            $plugin->Md5 = $md5;
            $this->processCMSNavItems($plugin, $log, $xml);
            $this->processElements($plugin, $log, $xml);

            $changed = true;
        }

        // rerun element schemas
        if($changed) {

            $plugin->AutoUpgraded = true;

            if(!$this->TransactionManager->isTransactionInProgress())
                $this->TransactionManager->begin();

//            foreach($this->ElementService->findAll()->getResults() as $element)
//                $this->NodeService->createDBSchema($element);

            $plugin = $this->PluginService->edit($plugin);
        }

    }
276557
public static function translate($string, Translation $translation = null) {
		if ($translation !== null) {
			$translation = self::get($translation->language, $translation->application_name);
		} else {
			$translation = self::get(\Application::get()->language, \Application::get()->name);
		}

		return $translation->translate_string($string);
	}
1113872
public function setTranslator(\Symfony\Component\Translation\TranslatorInterface $translator)
    {
        $this->translator = $translator;

        return $this;
    }
1066659
public function setTranslator($translator)
    {
        ObjectHelper::isInstanceOf($translator, [Organization::class, PersonInterface::class]);
        
        $this->_translator = $translator;
        return $this;
    }