Using Runtime Library in Custom Scripts

In rare cases, it might happen that you want to run a custom PHP script on behalf of an APS application using the APS PHP runtime classes and methods without declaration of any APS REST operations in the script.

Development Steps

When developing such a script, follow these recommendations.

  1. On the endpoint host where the APS application connector is deployed, prepare a separate folder, probably in your home user directory. Copy the config/ folder of the APS application connector to the new folder. The script will use an application instance SSL certificate (usually, there is only one instance installed) from the config/ folder to authenticate itself in the APS controller.

    # mkdir ~/test
    # cp -r /var/www/html/basic/config ~/test/
    # cd ~/test
    

    Warning

    For security reasons, ensure that the new folder is not available for HTTP access.

  2. In the new folder, create the PHP script, for example, test-cli.php, and inside it specify the path to the APS PHP runtime library:

    <?php
    
    define('APS_PHP_RUNTIME_ROOT', '/usr/share/aps/php/');
    
    ?>
    
  3. In the script, include the files containing the definition of the APS PHP classes and methods:

    require_once 'aps/2/apsc.php';
    require_once 'aps/2/aps.php';
    

    Note

    Unlike typical implementations, we avoid here the inclusion of aps/2/runtime.php to exclude the verification of every incoming REST request for the existence of a corresponding APS type and an operation.

  4. Get connected to the APS controller on behalf of the proper APS application instance you want to use. In the following example, the first instance is used:

    $apsc = \APS\Request::getController(\APS\ControllerProxy::listInstances()[0]);
    
  5. Add your custom code, for example:

    $vpses = $apsc->getResources('implementing(http://aps-standard.org/samples/vpsdemo/vps/1.0)');
    print_r($vpses);
    

The script sends a request to the APS controller for a list of resources of the specified APS type. Then, it prints out the received list on the stdout.

Script Execution

Run the sample script in its parent folder, in our example, in ~/test/:

# cd ~/test
# php test-cli.php

The APS controller must return an array of the resources implementing the APS type specified in the request. The scripts prints out the array on the screen similar to the following:

Array
(
   [0] => org\standard\aps\samples\vpsdemo\vps\v1\v0\vps Object
     (
         [name] => V101
         # Other properties of the first resource ...
      )
   [1] => org\standard\aps\samples\vpsdemo\vps\v1\v0\vps Object

     (
         [name] => V101
         # Other properties of the second resource ...
      )
   # Other resources of the same type ...
)