zend-framework - 如何使用 Zend Framework 实现模块安装和卸载

标签 zend-framework module installation uninstallation

我有一个使用 Zend Framework 构建的 Web 应用程序,其中包含很多模块。这些模块都是“可选的”,用于使扩展功能可用。其中一些模块编写了自己的日志等。我正在考虑如何为这些模块实现安装和卸载行为。

一开始我的想法是让每个模块都有一个InstallationController , UninstallController等,并让这些处理安装。但后来我开始考虑一种方法,让每个模块包含install.ini。 , uninstall.ini等等。然后核心具有削减和作用于这些的功能。 uninstall.ini 的示例对于模块foo文件可能是

[save_logs]
folder.remove.data.foo
folder.remove.modules.foo
file.remove.configs.foo

[complete : save_logs]
file.remove.logs.foo
db.table.truncate.foo_table1
db.table.truncate.foo_table2

然后将向用户显示 Complete 的选项。或 Save Logs在运行 foo 的卸载时模块。我可以看到这种方法的好处之一是处理所有操作的通用核心机制,并且事实上没有代码实际上是 foo 的一部分。模块将在卸载期间运行。

我以前从未在 web 应用程序上完成过这种类型的安装/卸载/更新支持,所以任何想法和提示都会很好。

最佳答案

在上类的早会之前,我很快就制定了一些初步的想法。你怎么看?是否应该更多地考虑和调查这种方法?
这是一些伪代码讨论格式,它绝不是完整的函数和类集,但我认为主要的 ide 已经足够清楚了。

class Foo_Installer extends Zend_Module_Installer
{
    // The modules bar and exporter are needed by this module
    protected $_dependencies = array('modules' => array('bar', 'exporter'));
        // Maybe this should be expanded to include versions like below. Prehaps even be able to
        // specify a formula of a version like '>2.3 && !2.4 && !2.6' if 2.5 and 2.6 is not compatible
        // for some reason or another.
        protected $_dependencies = array('modules' => array('bar' => '1.0', 'exporter' => '2.3'));

    // Tell the installer what 'script' to use. Should be able to use sources such as xml, ini, yaml, db etc
    // The install script should contain sections for install/uninstall and update process
    protected $_installScript = 'fooInstall.xml';

    // Place to look for files for update
    protected $_repo = 'http://www.foobar.com/repo';
}


class Zend_Module_Installer
{
    protected function _checkDependencies() {
        // Check if modules in $this->_dependencies are already installed
    }

    public function install() {
        $this->_checkDependencies();

        // Parses the given source of the install script and returns installSteps
        $installSteps = $this->_getInstallSteps();

        foreach($installSteps as $installStep) {
            $installStep->perform();
        }
    }

    public function uninstall() {

    }

    public function update() {
        // Connect to repo and check for a newer version of the module.
        // I think that prehaps a standard should be that modules are distributed
        // as zip-archives so only one file needs to be downloaded. On a update server
        // a file named after a standard 'ie packages' could be present that could be
        // read to determine what packages and versions of these exist on the server
        // and if there is a new version avalible to download.
        //
        // If so we download, unzip, check dependencies, check if dependencies we don't
        // already have installet are avalible at the server, download these and itterate
        // until no more downloads are necessery. Then we start runnin the Update()
        // functions of the downloaded modules in the correct order.
    }

    protected function getInstallSteps() {
        // parses the installscript and instanciates Zend_Installer_Step objects
    }
}


// Base class for steps during installation
// This apporach makes it easy to extend the installer to be able to do specific things
// in specific enviroments. Prehaps configure a some external hardware or whatever.
class Zend_Installer_Step
{
    public function perform();
}


// Functions to handle the actual logic of creating and deleting stuff.
// Some could be standard and some could be application specific
class Zend_Installer_Step_Create_File extends Zend_Installer_Step
{
}

class Zend_Installer_Step_Delete_File extends Zend_Installer_Step
{
}

class Zend_Installer_Step_Create_Folder extends Zend_Installer_Step
{
}

class Zend_Installer_Step_Create_Db extends Zend_Installer_Step
{
}

class Zend_Installer_Step_Create_Db_Table extends Zend_Installer_Step
{
}

class Zend_Installer_Step_Create_Db_StoredProcedure extends Zend_Installer_Step
{
}

关于zend-framework - 如何使用 Zend Framework 实现模块安装和卸载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4704999/

相关文章:

java - 如何禁止访问依赖项的依赖项

node.js - 如何处理 Node.js 中的循环依赖

apache - 已安装 Hive 但运行时出错

php - Zend Framework 1.12 - 无法加载模块的模型

php - 在单个 MySQL 或 MariaDB 事务中可以使用多少查询

zend-framework - 如何从 Zend Navigation XML 向 <li> 添加类名

python - ModuleNotFoundError : What does it mean __main__ is not a package?

zend-framework - 如何在所有 Controller init() 函数中运行相同的行?

apache-flex - Adobe AIR 1.5-将AIR安装程序打包为 native Windows可执行文件(.EXE)

installation - 有没有办法进行 IIS Express 8 的无人值守/静默安装?