WebSphere Message Broker, Version 8.0.0.7 Operating Systems: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS

See information about the latest product version

Writing PHP code

Use these instructions to create your PHP code.

  1. In the Broker Application Development perspective, click File > New > Other. The Select a wizard pane is displayed.
  2. Select File from the list of resources, then click Next.
  3. Select the required parent folder from the list, then type the name of your new PHP script file in the File Name field. Ensure that the file you specify has an extension of .php (for example, Hello.php). The Eclipse text editor opens, with an empty pane in which you can type your PHP code.
  4. Type your PHP code into your new PHP script file, by using the Eclipse text editor. The PHP script must be contained within the <?php and ?> tags:
    <?php
    
    // Body of the script
    
    ?>

    You can create a PHP script with or without a class and evaluate method. The option you choose affects both the content of the script and the setting of the PHPCompute node's Invoke evaluate method property:

    • Create a script including a class and evaluate method:

      The Invoke evaluate method property of the PHPCompute node is selected by default, therefore a class and evaluate method are expected in the PHP script.

      The PHP code must contain a class with the same name as the PHP file (Hello, for example), and this class must contain a function called evaluate, with parameters for the input and output message assemblies:

      <?php
      
      class Hello {
      
      		/**
      		 * An example of MessageBrokerSimpleTransform
      		 * @MessageBrokerSimpleTransform
      		 */
      		function evaluate($output_assembly, $input_assembly)	{
      			// transformation code here
      			// $output_assembly ->XMLNSC->... = $input_assembly->XMLNSC->...
      		}
      
      }
      
      ?>

      For more information about the @MessageBrokerSimpleTransform annotation shown in this example, see Using annotations.

    • Create a script without a class and evaluate method:
      The global variable $assembly makes the incoming message assembly available to the script. The incoming message and message assembly are read only. As a result, for message transformation, you must make a new copy of the message and the assembly containing the new message:
      <?php
      
      $output_message = new MbsMessage();
      
      // transformation code here
      // $output_message->XMLNSC->... = $assembly->XMLNSC->...
      
      $output_assembly = new MbsMessageAssembly($assembly, $output_message);
      $output_assembly->propagate("out");
      
      ?>

      The Invoke evaluate method property of the PHPCompute node is selected by default, therefore a class and evaluate method are expected in the PHP script. If you use a PHP script without a class and evaluate method, remember to clear the Invoke evaluate method property of the PHPCompute node.

      You must explicitly propagate the message assembly to one of the output terminals before the end of the script.

When you have created your PHP code, associate it with the PHPCompute node by following the instructions in Associating PHP code with a PHPCompute node.

For information about the PHP scripting language, see the PHP: Hypertext Preprocessor Web site.

Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2016Copyright IBM Corporation 1999, 2016.

        
        Last updated:
        
        Last updated: 2016-05-23 14:46:34


Task topicTask topic | Version 8.0.0.7 | ac69012_