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:
    $mirrorServicePath = dirname(__FILE__) . '/MirrorService.php';
    $mirrorServiceClassFindInfo = new Amfphp_Core_Common_ClassFindInfo($mirrorServicePath, "MirrorService");
    $this->serviceNames2ClassFindInfo["MirrorService"] = $mirrorServiceClassFindInfo;
    

    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";
    
  • forceAmf3.

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);
    

Comments

  1. Seb

    May 30, 2011

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

  2. Ariel Sommeria-Klein

    October 18, 2011

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

  3. luongle

    November 11, 2011

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

Add a comment

You must be logged in to comment.