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

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

        PHP钩子系统怎么做?

        How to do a PHP hook system?(PHP钩子系统怎么做?)

      1. <legend id='NH20q'><style id='NH20q'><dir id='NH20q'><q id='NH20q'></q></dir></style></legend>
          <tbody id='NH20q'></tbody>

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

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

              • <bdo id='NH20q'></bdo><ul id='NH20q'></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钩子系统怎么做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                • <small id='dLbdp'></small><noframes id='dLbdp'>

                  <legend id='dLbdp'><style id='dLbdp'><dir id='dLbdp'><q id='dLbdp'></q></dir></style></legend>
                    • <bdo id='dLbdp'></bdo><ul id='dLbdp'></ul>
                        <tbody id='dLbdp'></tbody>

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

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