如何自定义 Zend_Tool 输出?

发布于 2024-08-01 13:12:04 字数 411 浏览 7 评论 0原文

我想在我的项目中使用 Zend_Tool (ZF 1.9),但我希望能够自定义新文件的默认输出。 例如,所有控制器都应该在输出前添加一个特定的标头,其中包含 phpdoc 标记和许可信息,以避免我必须将其添加为额外的步骤。

另外,对于这个特定的项目(但不是所有其他项目),我需要控制器来扩展默认 Zend 控制器以外的其他东西,因为我已经将其扩展为某些特定功能。

该文档暗示了执行这些操作的能力,但并没有说得很清楚。

据我所知,我可以设置一个 ~/.zf 目录(在基于 ***nix 的系统上)并在其中包含自定义提供程序。 然而,这将是整个机器范围内的,而不是仅限于单个项目范围。 另外,虽然这将添加新的提供程序,但它(似乎)不允许我自定义现有提供程序的功能。

任何帮助将不胜感激!

I'd like to use Zend_Tool (ZF 1.9) with my project, but I would like to be able to customize the default output of new files. For example, all Controllers should have a specific header pre-pended to the output with phpdoc markup and licensing information to avoid me having to add this as an extra step.

Also, for this particular project (but not all other projects), I need the controllers to extend something other than the default Zend controller as I have extended that for some specific functionality.

The documentation alludes to the ability to do these things, but it does not make it very clear.

From what I can tell I can set up a ~/.zf directory (on ***nix based systems) and include custom providers there. However, this will be machine-wide as opposed to limited to single project scope. Also, while this will add new providers it does not (seemingly) allow me to customize the functionality of existing providers.

Any help here would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜无邪 2024-08-08 13:12:04

本质上雅各布的意思是:你所说的似乎是简单的类扩展。 这里有一个关于扩展 Zend Framework 的非常简单的幻灯片介绍:

http://www. Slideshare.net/PHPBelgium/extending-zend-framework-presentation

还有许多其他在线资源可用于扩展 Zend Framework。 您可以为不同的项目创建单独的源代码树,并且可以将各种项目通用的功能添加到公共文件夹中的抽象类中。 这样的事情并不常见,但我发现它在这种情况下有效:

class My_Component_HelloProvider extends My_Common_Component_HelloProvider
{
    public function say()
    {
        echo 'Hello from my provider!';
    }

    // public function do() is inherited

}

class My_Common_Component_HelloProvider
    implements Zend_Tool_Framework_Provider_Interface
{
    public function do()
    {
        // do something
    }
}

让我知道这是否与您想要做的不同,但没有理由您不能从中构建多个应用程序扩展ZF 的单个实例。

Essentially what Jacob was getting at: what you're talking seems like simple class extending. There's a really simple slideshow introduction to extending Zend Framework here:

http://www.slideshare.net/PHPBelgium/extending-zend-framework-presentation

There are also lots of other resources available online for extending Zend Framework. You can create separate source trees for your different projects, and functionality common to various projects can be added to abstract classes that are in common folders. Something like this isn't common, but I've found it works in those kinds of situations:

class My_Component_HelloProvider extends My_Common_Component_HelloProvider
{
    public function say()
    {
        echo 'Hello from my provider!';
    }

    // public function do() is inherited

}

class My_Common_Component_HelloProvider
    implements Zend_Tool_Framework_Provider_Interface
{
    public function do()
    {
        // do something
    }
}

Let me know if this is different from what you're trying to do, but there's no reason you can't build multiple applcation extensions from a single instance of ZF.

故人爱我别走 2024-08-08 13:12:04

当你定义具体的类时,你自然可以继续重写。 您可以将它们声明为基于您的类,而不是 ZF 类。

对于特定项目,您可以将类路径修改为 ZF 的自定义版本,或者可能具有自定义覆盖文件夹。 使用自定义文件夹,您的更改将不再是机器范围的,但您的 zend 框架也不是。 在基于 ***nix 的系统上,您可以利用符号链接来保留一份 ZF 副本。

您是否尝试修改源代码以包含许可证标头和 PHPdoc? 如果是这样,我过去所做的就是一个简单的构建步骤,添加您需要的信息。 每种文件类型都可以具有适当的标头信息。 您可以使用漂亮的标签来告诉系统忽略文件,或仅在控制器上运行。

祝你好运,
雅各布

You can naturally continue to override when you define the specific classes. You can declare them to be based on your class, rather than the ZF class.

For specific projects, you can modify your classpath to be a custom version of ZF or possibly have a custom override folder. With a custom folder then your changes are not machine wide, but neither is your zend framework. on ***nix based systems, you can leverage symbolic links to keep yourself to one copy of ZF.

Are you trying to modify your source code to include the license headers and PHPdoc? If so, what I have done in the past is have a simple build step that adds the information you need. Each file type can have the appropriate header information. You can have nice tags to tell the system to ignore files, or only run on controllers.

Good Luck,
Jacob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文