Not signed in (Sign In)

Categories

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

Help keep Vanilla free:
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
  1.  # 1
    I'm curious if it would be possible to use call_user_func_array in library/Framework/Framework.Class.Delegation.php @ 46. This would not not change any current behavior of the delegation system. However, it would add new behavior, which would be to allow any sort of callback function to be called. It would allow extension developers to pack up their functions into classes.

    I've tested this in my own environment, and it works fine when using Vanilla with the IssueTracker extension and when using my own application built on the Lussumo Framework.

    Here's the changed CallDelegate() function (file library/Framework/Framework.Class.Delegation.php @ 41):<?php
    // Executes all functions associated with the specified delegate
    function CallDelegate($DelegateName) {
    if (array_key_exists($DelegateName, $this->Delegates)) {
    $FunctionCount = count($this->Delegates[$DelegateName]);
    for ($i = 0; $i < $FunctionCount; $i++) {
    call_user_func_array($this->Delegates[$DelegateName][$i], array(&$this));
    }
    }
    }
    ?>

    Any thoughts about this change? Questions? Anyone want to commit it to SVN?
    •  
      CommentAuthorWallPhone
    • CommentTimeDec 14th 2007
     # 2
    I'm not very familiar with this function, but from reading the php documentation, my only question is why use call_user_func_array instead of call_user_func?

    It also seems there is a minuscule drop in performance, but I agree the benefits could outweigh that. Another issue is that the benefits are only realized if extension authors wrap their extensions into classes--which there is little incentive to do for backward compatibility and extra work involved.

    Anybody else want to chime in?
    • CommentAuthorsirlancelot
    • CommentTimeDec 14th 2007 edited
     # 3
    call_user_func_array() is used so that $this can be added as reference to prevent duplication of the object. I chose that method function because the documentation of call_user_func() say that it can't handle references in the parameters.

    The reason behind this change is that I'm using the Framework for my own projects and required this type of functionality.

    I realize adoption of this new functionality will not be fast, but if Mark plans on using the Framework for Vanilla 2, this would certainly be a nice addition ;)

    Thanks for considering it.
    • CommentAuthorgerry22
    • CommentTimeDec 14th 2007
     # 4
    can you give an example of it would be used?
  2.  # 5
    This feature could be applied to any number of scenarios. I would consider it "expected behavior" for such a modular system. The main advantage is that it would help keep the global namespace free of collisions. I see function names like [DelegateName]_[FunctionName]() and when a user has a lot of extensions enabled the risk of running in to a collision are greater.

    If this feature were implemented, extension developers would be able to wrap all their functions into a class and the Framework would be able to make calls to methods within the class.

    Sure, the function naming scheme will probably stick for ease of readability, but at least this will avoid function naming collisions.
Add your comments
    Username Password
  • Format comments as