Contents:
Zend 5250 Bridge Object Oriented API
Zend 5250 Bridge Procedural API Functions
Zend 5250 Bridge Use Case Examples
The 5250 Bridge APIs have two interfaces: object oriented and procedural functions. If a developer is not comfortable using object oriented (class access) methods in PHP he can use regular procedural functions to access the same APIs.
The 'Zend_5250' is the main class that manages communication with the 5250 Session and interfaces with 5250 screen information. It includes connection methods, methods to submit commands, and function key action methods.
The Zend_5250 class uses the following:
<?php
class Zend_5250 {
/**
* @param string $jobId
* @param Zend_5250_Handler $storageHandler If not set, a default (session based)
storage will be used
*/
public function __construct($jobId = null, Zend_5250_Handler $storageHandler = null) {
}
/**
* Returns true if the bridge was already connected, othewise - false
*
* @return boolean
*/
public function isConnected() {
}
/**
* Create a connection to 5250 bridge and fetch the current stage
(either from the bridge or from the storage)
*
* @param string $username
* @param string $password
* @return Zend_5250_Response
*/
public function connect($username = '', $password = '') {
}
/**
* Sends a request to the 5250 bridge
* Once user sets all desired data in the input fields (using the setInputField()
method), this function
* should be called with the command the user has selected
(command, can be one of the 'F' keys, enter,
* page up, etc.)
* @param string $command
* @return Zend_5250_Response
*/
public function submit($command = Zend_5250::ENTER) {
}
/**
* Disconnecting from 5250 bridge (closing connection to application)
*/
public function disconnect() {
}
/**
* Sets data into input field specified by $id
* @param int $id
* @param string $value
*/
public function setInputField($id, $value) {
}
/**
* Sets the focus of the page to a specified field
*
* @param Zend_FieldData $fieldData
*/
public function setFocusedField(Zend_FieldData $fieldData) {
}
/**
* Returns the screen size, width x height
*
* @return array with 2 elements: height and width
*/
public function getScreenSize() {
}
/**
* Returns an array containing the i5 5250 Bridge color palette
* Color code is the key of the array and the color name is the value
*
* @static
* @return array
*/
public static function getColorPalette() {
}
const F1 = 'F1';
const F2 = 'F2';
const F3 = 'F3';
const F4 = 'F4';
const F5 = 'F5';
const F6 = 'F6';
const F7 = 'F7';
const F8 = 'F8';
const F9 = 'F9';
const F10 = 'F10';
const F11 = 'F11';
const F12 = 'F12';
const F13 = 'F13';
const F14 = 'F14';
const F15 = 'F15';
const F16 = 'F16';
const F17 = 'F17';
const F18 = 'F18';
const F19 = 'F19';
const F20 = 'F20';
const F21 = 'F21';
const F22 = 'F22';
const F23 = 'F23';
const F24 = 'F24';
const CLEAR = 'CLEAR';
const ENTER = 'ENTER';
const HELP = 'HELP';
const PAGEDN = 'PAGEDN';
const PAGEUP = 'PAGEUP';
const ROLLLF = 'ROLLLF';
const ROLLRT = 'ROLLRT';
const PRINTKEY = 'PRINT';
const BACKSP = 'BACKSP';
const FORWARD = 'FORWARD';
}?>
Interface for saving 5250 bridge XML strings. The entire communication between the 5250 session and PHP is done via an XML file that has to be saved between requests in order to maintain a session with IBM i. The implementation of this interface allows this. The user can implement this interface in case the default handler provided by Zend is not sufficient, and the user wants to save XML strings using a different method.
<?php
interface Zend_5250_Handler {
/**
* Sets a unique job ID that will be used for storing session data
*
* @param string $jobId
*/
public function setJobId($jobId);
/**
* Returns whether or not a stage (XML string) is stored in this storage
*
* @return bool
*/
public function isStored();
/**
* Returns the XML string
*
* @return string
*/
public function getXmlString();
/**
* Sets the XML string
* @param string $value
*/
public function setXmlString($value);
/**
* Unsetting XML string saved so far
*/
public function destroy();
}?>
This Class contains information about the page: input and output fields, focused field and application error.
<?php
class Zend_5250_Response {
/**
* Create a response object for a 5250 bridge request
* @param array $inputFields
* @param array $outputFields
* @param Zend_FieldData|false $focusedField
* @param string $applicationError
*/
public function __construct($inputFields, $outputFields, $focusedField, $applicationError) {
}
/**
* Returns all input fields available at this stage
* @return array of Zend_FieldData_Input objects
*/
public function getInputFields() {
}
/**
* Return input field specified by the given ID
* @param int $id
* @return Zend_FieldData_Input
*/
public function getInputField($id) {
}
/**
* Returned the input field currently in focus
* @return False/Zend_FieldData_Output in case of no input fields the return value is false
*/
public function getFocusedField() {
}
/**
* Returns the number of input fields available in this stage
* @return int
*/
public function getInputFieldsCount() {
}
/**
* Return all the output fields available at this stage
* @return array of Zend_FieldData_Output objects
*/
public function getOutputFields() {
}
/**
* Return output field specified by the given ID
* @param int $id
* @return Zend_FieldData_Output
*/
public function getOutputField($id) {
}
/**
* Returns the number of output fields available in this stage
* @return int
*/
public function getOutputFieldsCount() {
}
/**
* Returns the string of application error or empty string
*
* @return string
*/
public function getApplicationError() {
}
}
}?>
This Class contains information about the output field data: id, row, column, length, color and value.
<?php
/**
* The Zend_FieldData_Output class represents the output field
*/
class Zend_FieldData_Output extends Zend_FieldData {
}?>
This Class contains information about the input field data: id, row, column, length, color, value, font, type and format.
<?php
class Zend_FieldData_Input {
/**
* Saves the field's data
*
* @param integer $id
* @param SimpleXMLElement $field
*/
public function __construct($id, SimpleXMLElement $field) {
}
/**
* @return string
*/
public function getType() {
}
/**
* @return string
*/
public function getFont() {
}
/**
* @return string
*/
public function getFormat() {
}
?>
This is an abstract class that contains the common data of input and output fields, which are id, row, column, length, color and value.
<?php
abstract class Zend_FieldData {
public function __construct($id, SimpleXMLElement $field);
/**
* @return int The unique ID of this field data
*/
public function getId() {
}
/**
* @return int Height position of the field in the page
*/
public function getRow() {
}
/**
* @return int Width position of the field in the page
*/
public function getColumn() {
}
/**
* @return int The length of this field value
*/
public function getLength() {
}
/**
* @return int Color code as appear in the color pallete
*/
public function getColor() {
}
/**
* @return string This field value
*/
public function getValue() {
}
}
?>
The procedural functions are a collection of functions allowing access to the same 5250 Bridge API as the object oriented classes.
The procedural API is a collection of functions that wrap the real object oriented API.
zend_5250_open($jobId = null)
Description: Starts a session according to the provided job id.
Return Values: @return Zend_5250_Resource_Connection
Parameters:
zend_5250_connect($connection, $username = '', $password = '')
Description: Creates a connection to the 5250 Bridge with the provided username, password and library.
Return Values: @return Zend_5250_Response
Parameters:
zend_5250_is_connected($connection);
Description: Returns true if the bridge was already connected, otherwise - false
Return Values: @return boolean
Parameters:
zend_5250_submit($connection, $command = 'ENTER');
Description: Sends a request to the 5250 bridge. Once the user sets all desired data in the input fields (using the setInputField() method), this function should be called with the command the user has selected (commands, can be one of the 'F' keys, enter, page up, etc.)
Return Values: @return Zend_5250_Response
Parameters:
zend_5250_disconnect($connection)
Description: Disconnects the 5250 bridge (closing the connection to the application)
Return Values:
Parameters:
zend_5250_set_input_field($connection, $id, $value);
Description: Sets data into an input field specified by $id
Return Values:
Parameters:
zend_5250_set_focused_field($connection, $filed);
Description: Sets the focus of the page to a specified field
Return Values:
Parameters:
zend_5250_get_screen_size($response)
Description: Returns the size of the screen, width x height
Return Values: @return array with 2 elements: height and width
zend_5250_get_color_palette();
Description: Returns an array containing the i5 5250 Bridge color palette Color code is the key of the array and the color name is the value
Return Values: @return array
zend_5250_get_input_fields($response);
Description: Returns all input fields available at this stage
Return Values: @return array of arrays
Parameters:
zend_5250_get_input_field($response, $id);
Description: Returns an input field specified by the given ID
Return Values: @return array
Parameters:
zend_5250_get_focused_field($response);
Description: Returns the field currently in focus
Return Values: @return array
Parameters:
zend_5250_get_input_fields_count($response);
Description: Returns the number of input fields available at this stage
Return Values: @return int
Parameters:
zend_5250_get_output_fields($response)
Description: Returns the number of output fields available at this stage
Return Values: @return array of arrays
Parameters:
zend_5250_get_output_field($response, $id);
Description: Returns an output field specified by the given ID
Return Values: @return array
Parameters:
zend_5250_get_output_fields_count($response);
Description: Returns the number of output fields available in this stage
Return Values: @return int
Parameters:
zend_5250_get_application_error($response);
Description: Returns an application error if it occurred
Return Values: @return string
Parameters:
zend_5250_get_error()
Description: Returns a function error if it occurred
Return Values: @return string
The following code samples demonstrate how to perform various functions using the 5250 Bridge API, using both Procedural functions and Object Oriented methods.
The following is sample code for starting and logging on to a 5250 session:
Procedural
<?php
set_include_path('/usr/local/zendsvr/5250/API/');
require_once('Zend/5250/Zend_ProceduralApi.php');
$connection = zend_5250_open();
zend_5250_connect($connection);
zend_5250_set_input_field($connection ,'0','user');
zend_5250_set_input_field($connection ,'1','password');
// press ENTER
zend_5250_submit($connection);
zend_5250_disconnect($connection);
?>
Object Oriented
<?php
set_include_path('/usr/local/zendsvr/5250/API/');
require_once('Zend/5250.php');
$bridge = new Zend_5250();
$response = $bridge->connect();
$bridge->setInputField('0','user');
$bridge->setInputField('1','password');
// press ENTER
$response = $bridge->submit();
$bridge->disconnect();
?>
The following is sample code for running the "WRKSYSVAL" command in a 5250 session:
Procedural
<?php
set_include_path('/usr/local/zendsvr/5250/API/');
require_once('Zend/5250/ProceduralApi.php');
$connection = zend_5250_open();
$response = zend_5250_connect($connection);
zend_5250_set_input_field($connection ,'0','user');
zend_5250_set_input_field($connection ,'1','password');
// press ENTER
zend_5250_submit($connection);
$output_field = zend_5250_get_output_field($response, 5);
if (trim($output_field['value']) == 'Press Enter to continue.') {
$response = zend_5250_submit($connection);
}
// get focused field
$focusedField = zend_5250_get_focused_field($response);
// set input field #0 to 'wrksysval'
zend_5250_set_input_field($connection, 0, 'wrksysval');
// press ENTER
zend_5250_submit($connection);
// press EXIT
zend_5250_submit($connection, Zend_5250::F12);
zend_5250_disconnect($connection);
?>
Object Oriented
<?php
set_include_path('/usr/local/zendsvr/5250/API/');
require_once('Zend/5250.php');
$bridge = new Zend_5250();
$response = $bridge->connect();
$bridge->setInputField('0','user');
$bridge->setInputField('1','password');
// press ENTER
$response = $bridge->submit();
if (trim($response->getOutputField(5)->getValue()) == 'Press Enter to continue.') {
$response = $bridge->submit();
}
// get focused field
$focusedField = $response->getFocusedField();
// set input field #0 to 'wrksysval'
$bridge->setInputField(0, 'wrksysval);
// press ENTER
$response = $bridge->submit();
// press EXIT
$response = $bridge->submit(Zend_5250::F12);
$bridge->disconnect();
?>
The following is sample code for running a ’"multi-request", where 2 different 5250 sessions are run in parallel from the same PHP application:
Procedural
<?php
set_include_path('/usr/local/zendsvr/5250/API/');
require_once('Zend/5250/ProceduralApi.php');
$connection1 = zend_5250_open(1);
$response = zend_5250_connect($connection1);
zend_5250_set_input_field($connection1 ,'0','user');
zend_5250_set_input_field($connection1 ,'1','password');
// press ENTER
zend_5250_submit($connection1);
$connection2 = zend_5250_open(2);
$response = zend_5250_connect($connection2);
zend_5250_set_input_field($connection2 ,'0','user');
zend_5250_set_input_field($connection2 ,'1','password');
// press ENTER
zend_5250_submit($connection2);
zend_5250_disconnect($connection1);
zend_5250_disconnect($connection2);
?>
Object Oriented
<?php
set_include_path('/usr/local/zendsvr/5250/API/');
require_once('Zend/5250.php');
$bridge1 = new Zend_5250(1);
$response = $bridge1->connect();
$bridge1->setInputField('0','user');
$bridge1->setInputField('1','password');
$response = $bridge1->submit();
$bridge2 = new Zend_5250(2);
$response = $bridge2->connect();
$bridge2->setInputField('0','user');
$bridge2->setInputField('1','password');
$response = $bridge2->submit();
$bridge1->disconnect();
$bridge2->disconnect();
?>
|
|
Related Links: |
|
|
|