爱代码社区公告



  • 本社区旨在分享和交流关于程序员的工作、生活、以及其他相关事情。请遵守法律法规,请勿发布违法信息,违者自行承担法律后果!


Log in to reply
 

最新帖子

最新内容

  • S

    MediaWiki has their own mechanism of defining hooks in their methods, and ways of registering functions to be executed for a given point of execution...

    http://www.mediawiki.org/wiki/Hooks (might be a good place to start)

    read more
  • S

    Why not use "Observer Pattern" for this? You can add an Object to your body and trigger the actions the attached classed hold. If you want to refine it, you can create a specific method inside each Observer object that defines the stage of the execution. This will likely be more programming at first, but gives a very clean interface for attaching more functionallity to your classes.

    For a concrete examample, this IBM dev article (btw its worth reading as a whole) should give you a nice impression of this pattern.

    read more
  • S

    How I Usually do things when it comes to hooks is create a HookLoader class which will store two types of hooks, PRE and POST. as PHP Is a single threaded interpreter there would be no such thing as DURING.

    Take this example:

    $Hooks = new HookLoader(); $Hook->Run("PRE","database_connect"); $Database->Connect(); $Hook->Run("POST","database_connect");

    each hook in the hook directory should be name like so:

    name_pre_database_connect.hook.php

    Hook files would be formatted like so:

    {name}_{type}_{event}.hook.php

    This will allow you to create unlimited amount of hooks.

    preferably i would make hook class abstract and static, this you can just run the hook calls within the actual object, therefore adding new libraries would be integrated as long as they have the Hook::run("type","event");

    read more
  • S

    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.

    Closed 7 years ago.

    I'm wondering what the best way is of handling hooks in a PHP application
    - so I can insert custom or 'plug in' functionality without modifying the main body of code.

    I know Wordpress features something like this. Is it really alright to do something as follows:

    if (file_exists('file_before'){ include('file_before'); } print 'hello'; if (file_exists('file_after'){ include('file_after'); }

    read more
  • S

    The reason why you don't get the "True"-s back is because they are under a different json-tag - they are under "plausible_answers" instead of answers I think. In your code the answers_dict is only pulled from the "answers" tag from the json - so you never actually loop over the plausible_answers list where the tag would be set to True

    read more

推荐阅读