• <small id='d0tWb'></small><noframes id='d0tWb'>

  • <i id='d0tWb'><tr id='d0tWb'><dt id='d0tWb'><q id='d0tWb'><span id='d0tWb'><b id='d0tWb'><form id='d0tWb'><ins id='d0tWb'></ins><ul id='d0tWb'></ul><sub id='d0tWb'></sub></form><legend id='d0tWb'></legend><bdo id='d0tWb'><pre id='d0tWb'><center id='d0tWb'></center></pre></bdo></b><th id='d0tWb'></th></span></q></dt></tr></i><div id='d0tWb'><tfoot id='d0tWb'></tfoot><dl id='d0tWb'><fieldset id='d0tWb'></fieldset></dl></div>

    <legend id='d0tWb'><style id='d0tWb'><dir id='d0tWb'><q id='d0tWb'></q></dir></style></legend>

  • <tfoot id='d0tWb'></tfoot>

      • <bdo id='d0tWb'></bdo><ul id='d0tWb'></ul>

        PHP钩子系统怎么做?

        时间:2023-10-02
      1. <legend id='q4uNy'><style id='q4uNy'><dir id='q4uNy'><q id='q4uNy'></q></dir></style></legend>

            <tfoot id='q4uNy'></tfoot>

            <small id='q4uNy'></small><noframes id='q4uNy'>

                <tbody id='q4uNy'></tbody>
            • <i id='q4uNy'><tr id='q4uNy'><dt id='q4uNy'><q id='q4uNy'><span id='q4uNy'><b id='q4uNy'><form id='q4uNy'><ins id='q4uNy'></ins><ul id='q4uNy'></ul><sub id='q4uNy'></sub></form><legend id='q4uNy'></legend><bdo id='q4uNy'><pre id='q4uNy'><center id='q4uNy'></center></pre></bdo></b><th id='q4uNy'></th></span></q></dt></tr></i><div id='q4uNy'><tfoot id='q4uNy'></tfoot><dl id='q4uNy'><fieldset id='q4uNy'></fieldset></dl></div>

                  <bdo id='q4uNy'></bdo><ul id='q4uNy'></ul>
                  本文介绍了PHP钩子系统怎么做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  您如何在 PHP 应用程序中实现钩子系统以在其执行之前或之后更改代码.hookloader 类的基本架构如何用于 PHP CMS(甚至是简单的应用程序).那么如何将其扩展为完整的插件/模块加载器?

                  How do you impliment a hook system in a PHP application to change the code before or after it executes. How would the basic architecture of a hookloader class be for a PHP CMS (or even a simple application). How then could this be extended into a full plugins/modules loader?

                  (另外,有没有关于 CMS 挂钩系统的书籍或教程?)

                  (Also, are there any books or tutorials on a CMS hook system?)

                  推荐答案

                  您可以构建一个事件系统 简单 或复杂,随您的需要.

                  You can build an events system as simple or complex as you want it.

                  /**
                   * Attach (or remove) multiple callbacks to an event and trigger those callbacks when that event is called.
                   *
                   * @param string $event name
                   * @param mixed $value the optional value to pass to each callback
                   * @param mixed $callback the method or function to call - FALSE to remove all callbacks for event
                   */
                  function event($event, $value = NULL, $callback = NULL)
                  {
                      static $events;
                  
                      // Adding or removing a callback?
                      if($callback !== NULL)
                      {
                          if($callback)
                          {
                              $events[$event][] = $callback;
                          }
                          else
                          {
                              unset($events[$event]);
                          }
                      }
                      elseif(isset($events[$event])) // Fire a callback
                      {
                          foreach($events[$event] as $function)
                          {
                              $value = call_user_func($function, $value);
                          }
                          return $value;
                      }
                  }
                  

                  添加事件

                  event('filter_text', NULL, function($text) { return htmlspecialchars($text); });
                  // add more as needed
                  event('filter_text', NULL, function($text) { return nl2br($text); });
                  // OR like this
                  //event('filter_text', NULL, 'nl2br');
                  

                  那就这样称呼吧

                  $text = event('filter_text', $_POST['text']);
                  

                  或者像这样删除该事件的所有回调

                  Or remove all callbacks for that event like this

                  event('filter_text', null, false);
                  

                  这篇关于PHP钩子系统怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何安装 bcmath 模块? 下一篇:ZF2:ZfcUser 模块的自定义用户映射器

                  相关文章

                  最新文章

                  1. <i id='Vf1cN'><tr id='Vf1cN'><dt id='Vf1cN'><q id='Vf1cN'><span id='Vf1cN'><b id='Vf1cN'><form id='Vf1cN'><ins id='Vf1cN'></ins><ul id='Vf1cN'></ul><sub id='Vf1cN'></sub></form><legend id='Vf1cN'></legend><bdo id='Vf1cN'><pre id='Vf1cN'><center id='Vf1cN'></center></pre></bdo></b><th id='Vf1cN'></th></span></q></dt></tr></i><div id='Vf1cN'><tfoot id='Vf1cN'></tfoot><dl id='Vf1cN'><fieldset id='Vf1cN'></fieldset></dl></div>

                    <legend id='Vf1cN'><style id='Vf1cN'><dir id='Vf1cN'><q id='Vf1cN'></q></dir></style></legend>

                    <small id='Vf1cN'></small><noframes id='Vf1cN'>

                    • <bdo id='Vf1cN'></bdo><ul id='Vf1cN'></ul>
                    <tfoot id='Vf1cN'></tfoot>