Configuring Amfphp

Amfphp should work as is without changing the configuration. However if you do need to change something, here is what is currently configurable :

  • service class location. There are two ways control this. You can either: add a folder containing any number of service classes. To do this add a path to that folder to « serviceFolderPaths », or simply replace it. Or you can add a service class. This is for more advanced uses and gives you full control over the name of the service, the path of the file containing the class, and the name of the class itself. To do this add a « ClassFindInfo » object to « serviceNames2ClassFindInfo » For example:

    $yourServicePath = dirname(__FILE__) . '/YourService.php';
    $yourServiceClassFindInfo = new Amfphp_Core_Common_ClassFindInfo($yourServicePath, "YourService");
    $this->serviceNames2ClassFindInfo["YourService"] = $yourServiceClassFindInfo;

    In both cases, use absolute paths, be careful of the case and in the case of folders finish with a « / ».

  • argument count checking. By default, Amfphp will check that the number of arguments you pass to a service method matches the number expected. You can disable this by setting « checkArgumentCount » to false.
  • plugin location. Currently all plugins must be in the same folder, defined by « pluginsFolder ». The default is Amfphp/Plugins.
  • plugin configuration. When plugins are instanciated they receive an associative array of values to which to set their parameters. So, to set the configuration of a plugin, add such an array to « pluginsConfig » For example to change param1 and param2 of TestPlugin, do this :

    $this->pluginsConfig["TestPlugin"] = {param1:"value1", param2:";value2"};
  • disabled plugins. If you want to disable a plugin but still keep it in your plugins folder, add its name to « disabledPlugins ». For example:

    $this->disabledPlugins[] = "AmfphpLogger";

You can configure Amfphp by extending or modifying the Amfphp_Core_Config class, or changing the config object at runtime.

  • Modifying it directly is the quick and dirty method, but it means that if it changes in future versions you will have more trouble upgrading.
  • Changing the config at runtime is ok for small tweaks, and it won’t bother you when upgrading. This can be done in your index .php script. To use the default config, the example gateway.php has the following line:

    $gateway = Amfphp_Core_HttpRequestGatewayFactory::createGateway();

    The createGateway method takes an optional configuration object as parameter. So replace it by

    $config = new Amfphp_Core_Config();//do something with config object here
    $gateway = Amfphp_Core_HttpRequestGatewayFactory::createGateway($config);
  • Extending the Amfphp_Core_Config class to contain your own config is the cleanest way, but it takes a bit more effort. To do so create a « MyConfig » class that inherits from Amfphp_Core_Config, and use the following code in the gateway.php script:

    $myConfig = new MyConfig();
    $gateway = Amfphp_Core_HttpRequestGatewayFactory::createGateway($myConfig);


  1. Seb

    30 Mai 11

    Would it be possible to wrap code samples in tags? I find it very hard to read...

  2. ariels

    30 Mai 11

    yes, it’s already planned

  3. ariels

    18 Oct 11

    ok somehow the formatting got mangled, and it should be fixed. If any one has trouble reading the code here please comment!

  4. luongle

    11 Nov 11

    New docs is very general, we need more details. Also, let me ask how to add beforeFilter as version 1.9?

  5. ariels

    22 Nov 11

    @luangle what more details do you need? There is no beforeFilter now, rather a plugin system.

  6. ChristianL

    25 Sep 14

    Information on where to put these lines. In index.php? There is no $this, so should it be replaced by $config or $gateway? You are writing about gatepay.php, but now it is index.php, right?
    Please give us more examples including the information on the file name and line where to put the code snippets.
    What I miss is a complete code where the service path is changed and where some configurations are set (i. e. plugins and argument count checking switched on / off). I think this would help many users that are new to amf (2.x) a lot.


  7. ChristianL

    25 Sep 14

    Configuration is quite easy, when you know where and how 🙂

    Here is a index.php (or gateway.php) for amfPHP v2.2 that is placed in the document root and amfPHP itself is located in a library folder.

    To get an idea what can be configured, have a look in the Amfphp_Core_Config class (/Core/Config.php).

    * The path to the services
    $servicePath = realpath(dirname(__FILE__) . '/application/services/amf/');

    * includes
    * @package Amfphp
    * */
    require_once dirname(__FILE__) . '/library/Amfphp/ClassLoader.php';

    $config = new Amfphp_Core_Config();
    $config->serviceFolders = array($servicePath);
    $config->checkArgumentCount = false;

    * main entry point (gateway) for service calls. instanciates the gateway class and uses it to handle the call.
    $gateway = Amfphp_Core_HttpRequestGatewayFactory::createGateway($config);

    //use this to change the current folder to the services folder. Be careful of the case.


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