Developing Plugins

The plugin must be a class. The Amfphp_Core_PluginManager class is responsable for including the PHP file and instanciating the plugin. The plugin receives an optional associative array containing values to override the default plugin configuration. This array is defined by the user in the general Amfphp configuration. The convention here is that the key is the name of the plugin parameter, and the value is the new value to set the parameter to. For example receiving [sourceUrl => « http://bla »] should set the plugin parameter « sourceUrl » to « http://bla ». This should be done in the constructor.

The second thing that must be done in the constructor is to register the plugin for Amfphp filters. This is done by getting the filter manager and calling its addFilter method. The first parameter is the name of the hook, the second the object on which to call the hook(typically the plugin, or « $this »), and the third is the name of the method to call. Here is a simple plugin example that filters the deserialized request.

[sourcecode language= »php »]
class TestPlugin {

/**
* dummy parameter
* @var String
*/
public $sourceUrl;

/**
* constructor.
* @param array $config optional key/value pairs in an associative array. Used to override default configuration values.
*/
public function __construct(array $config = null) {
//default
$this->sourceUrl =  »;
if ($config) {
if (isset($config[‘sourceUrl’])) {
$this->sourceUrl = $config[‘sourceUrl’];
}
}

$filterManager = Amfphp_Core_FilterManager::getInstance();
$filterManager->addFilter(Amfphp_Core_Gateway::FILTER_DESERIALIZED_REQUEST, $this, ‘filterDeserializedRequest’);
}

/**
* sets deserialized request to “bla”
* @param mixed $deserializedRequest
* @return mixed
*/
public function filterDeserializedRequest($deserializedRequest) {

return ‘bla’;
}

}
[/sourcecode]

Comments

  1. David

    24 Mai 11

    the method call in this example does not match:

    $filterManager->addFilter(Amfphp_Core_Gateway::FILTER_REQUEST_DESERIALIZED, $this, “filterRequestDeserialized”);

    and the function called is:
    public function requestDeserializedFilter

  2. ariels

    25 Mai 11

    thanks for the tip off, I’ll change this ASAP when we finish the doc.

  3. Silver

    21 Août 12

    Hi,

    I don’t understand the example.
    I need to deserialize an amf from another site, and i do not see how to get the data back from your exemple.
    I give the url and i get bla in return? why not returning the data translated?

    Thank you

  4. ariels

    21 Août 12

    If you need to query another site, do so within a service. You shouldn’t need to use the plugin system for that. This is doable, but is not among the classic use cases of amfPHP. Use the Amfphp_Core_Amf_Deserializer class for this.

  5. Silver

    21 Août 12

    Thanks,
    I have already try, i try to get the raw data for the Amfphp_Core_Amf_Deserializer class form flex using URLLoaderDataFormat.BINARY and another try by sending the
    var bytes:ByteArray = new ByteArray();
    bytes.writeObject(myAmfLoader.data);
    and i have a Malformed Amf Packet.
    So it’s still not very clear for me how to use amfphp deserializer

    Thank you for your patience

Laissez un commentaire

News letter

Evénements Silex Labs sur Paris et sa région: Inscrivez vous à la Newsletter mensuelle

Silex Labs community Tweets

Facebook page