-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathToolkitServiceCw.php
199 lines (175 loc) · 5.8 KB
/
ToolkitServiceCw.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
namespace ToolkitApi\CW;
use ToolkitApi\Toolkit;
/**
* ToolkitServiceCw extends the standard Zend/PHP wrapper
* with specific Compatibility Wrapper (CW) features.
* @author aseiden
*/
class ToolkitServiceCw extends Toolkit
{
public static $instance = null;
public function __construct($database, $userOrI5NamingFlag, $password, $extensionPrefix, $isPersistent = false)
{
parent::__construct($database, $userOrI5NamingFlag, $password, $extensionPrefix, $isPersistent);
}
/**
* need to define this so we get Cw object and not parent object
*
* @param string $databaseNameOrResource
* @param string $userOrI5NamingFlag
* @param string $password
* @param string $extensionPrefix
* @param bool $isPersistent
* @param bool $forceNew
* @return bool|null
*/
public static function getInstance($databaseNameOrResource = '*LOCAL', $userOrI5NamingFlag = '', $password = '', $extensionPrefix = '', $isPersistent = false, $forceNew = false)
{
// if we're forcing a new instance, close db conn first if exists.
if ($forceNew && self::hasInstance() && isset(self::$instance->conn))
{
self::$instance->disconnect();
}
// if we're forcing a new instance, or an instance hasn't been created yet, create one
if ($forceNew || self::$instance == NULL) {
$toolkitService = __CLASS__;
self::$instance = new $toolkitService($databaseNameOrResource, $userOrI5NamingFlag, $password, $extensionPrefix, $isPersistent);
}
if (self::$instance) {
// instance exists
return self::$instance;
} else {
// some problem
return false;
}
}
/**
* Return true if an instance of this object has already been created.
* Return false if no instance has been instantiated.
*
* Same as the method in ToolkitApi\Toolkit.
* Cwclasses has its own instance variable so we need this method here, too.
*
* Useful when users need to know if a "toolkit connection" has already been made.
* Usage:
* $isConnected = Toolkit::hasInstance();
*
* @return boolean
*/
public static function hasInstance()
{
if (isset(self::$instance) && is_object(self::$instance)) {
return true;
} else {
return false;
}
}
/**
* @param $num
*/
public function setPrivateConnNum($num)
{
$this->_privateConnNum = $num;
}
/**
* @return null
*/
public function getPrivateConnNum()
{
return $this->_privateConnNum;
}
/**
* establish whether the connection is new or not. Used by i5_get_property()
*
* @param bool $isNew
*/
public function setIsNewConn($isNew = true)
{
$this->_isNewConn = $isNew;
}
/**
* @return bool
*/
public function isNewConn()
{
return $this->_isNewConn;
}
/**
* when script ends, non-persistent connection should close
*/
public function __destruct()
{
/* call to disconnect() function to down connection */
$disconnect = false;
// CW only: if connection is in a separate job and nonpersistent, end job (mimicking behavior of old toolkit)
if (!$this->isStateless() && !$this->getIsPersistent()) {
$disconnect = true;
}
if ($disconnect) {
$this->disconnect();
}
// parent destruct clears the object
// parent::__destruct();
// need to clear extended cwclasses instance as well.
if ($disconnect) {
self::$instance = null;
}
}
/**
* Get the most recent system error code, if available.
* TODO this may not work because CPFs are done at a class level (data areas etc.)
*/
public function getCPFErr()
{
// TODO get from Verify_CPFError or the other one
return $this->CPFErr;
}
/**
* After calling a program or command, we can export output as variables.
* This method creates an array that can later be extracted into variables.
* param array $outputDesc Format of output params 'CODE'=>'CODEvar' where the value becomes a PHP var name
* param array $outputValues Optional. Array of output values to export
*
* @param array $outputDesc
* @param array $outputValues
* @return boolean true on success, false on some error
*/
public function setOutputVarsToExport(array $outputDesc, array $outputValues)
{
// for each piece of output, export it according to var name given in $outputDesc.
if ($outputValues && is_array($outputValues) && count($outputValues)) {
// initialize
$this->_outputVarsToExport = array();
foreach ($outputValues as $paramName=>$value) {
if (isset($outputDesc[$paramName])) {
$variableNameToExport = $outputDesc[$paramName];
// create the global variable named by $ varName.
$GLOBALS[$variableNameToExport] = $value;
$this->_outputVarsToExport[$variableNameToExport] = $value;
}
}
}
return true;
}
/**
* @return array
*/
public function getOutputVarsToExport()
{
return $this->_outputVarsToExport;
}
/**
* pass in array of job attributes => values to update in the current job.
* returns true on success, false on failure (failure probably means lack of authority).
*
* @param array $attrs
* @return bool
*/
public function changeJob(array $attrs)
{
$cmdString = 'CHGJOB';
$success = i5_command($cmdString, $attrs);
return $success;
}
}