| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Used by the QCubed Code Generator to describe a database Stored Procedure |
|---|
| 4 | * |
|---|
| 5 | * @package Codegen |
|---|
| 6 | * |
|---|
| 7 | * @property string $Name |
|---|
| 8 | * @property string $Schema |
|---|
| 9 | * @property string $ClassName |
|---|
| 10 | * @property QStoredProcedureParameter[] $ParameterArray |
|---|
| 11 | */ |
|---|
| 12 | class QStoredProcedure extends QBaseClass { |
|---|
| 13 | |
|---|
| 14 | ///////////////////////////// |
|---|
| 15 | // Protected Member Variables |
|---|
| 16 | ///////////////////////////// |
|---|
| 17 | |
|---|
| 18 | /** |
|---|
| 19 | * Name of the table (as defined in the database) |
|---|
| 20 | * @var string Name |
|---|
| 21 | */ |
|---|
| 22 | protected $strName; |
|---|
| 23 | |
|---|
| 24 | /** |
|---|
| 25 | * Schema of the table (as defined in the database) |
|---|
| 26 | * @var string Schema |
|---|
| 27 | */ |
|---|
| 28 | protected $strSchema; |
|---|
| 29 | |
|---|
| 30 | /** |
|---|
| 31 | * Name as a PHP Class |
|---|
| 32 | * @var string ClassName |
|---|
| 33 | */ |
|---|
| 34 | protected $strClassName; |
|---|
| 35 | |
|---|
| 36 | /** |
|---|
| 37 | * Array of Parameter objects (as indexed by Parameter name) |
|---|
| 38 | * @var QStoredProcedureParameter[] ParameterArray |
|---|
| 39 | */ |
|---|
| 40 | protected $objParameterArray; |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | ///////////////////// |
|---|
| 44 | // Public Constructor |
|---|
| 45 | ///////////////////// |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Default Constructor. Simply sets up the Procedure Name and Schema |
|---|
| 49 | * |
|---|
| 50 | * @param string $strName Name of the Table |
|---|
| 51 | * @param string $strSchema Schema of the Table |
|---|
| 52 | */ |
|---|
| 53 | public function __construct($strName, $strSchema) { |
|---|
| 54 | $this->strName = $strName; |
|---|
| 55 | $this->strSchema = $strSchema; |
|---|
| 56 | $this->objParameterArray = array(); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | * return the QStoredProcedureParameter object related to that parameter name |
|---|
| 62 | * @return QStoredProcedureParameter |
|---|
| 63 | */ |
|---|
| 64 | public function GetParameterByName($strParameterName) { |
|---|
| 65 | if ($this->objParameterArray) { |
|---|
| 66 | foreach ($this->objParameterArray as $objParameter){ |
|---|
| 67 | if ($objParameter->Name == $strColumnName) |
|---|
| 68 | return $objParameter; |
|---|
| 69 | } |
|---|
| 70 | } |
|---|
| 71 | return null; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /** |
|---|
| 75 | * Search within the stored procedure's parameters for the given name |
|---|
| 76 | * @return boolean |
|---|
| 77 | */ |
|---|
| 78 | public function HasParameter($strParameterName){ |
|---|
| 79 | return ($this->GetParameterByName($strParameterName) !== null); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | //////////////////// |
|---|
| 83 | // Public Overriders |
|---|
| 84 | //////////////////// |
|---|
| 85 | |
|---|
| 86 | /** |
|---|
| 87 | * Override method to perform a property "Get" |
|---|
| 88 | * This will get the value of $strName |
|---|
| 89 | * |
|---|
| 90 | * @param string $strName Name of the property to get |
|---|
| 91 | * @return mixed |
|---|
| 92 | */ |
|---|
| 93 | public function __get($strName) { |
|---|
| 94 | switch ($strName) { |
|---|
| 95 | case 'Name': |
|---|
| 96 | return $this->strName; |
|---|
| 97 | case 'Schema': |
|---|
| 98 | return $this->strSchema; |
|---|
| 99 | case 'ClassName': |
|---|
| 100 | return $this->strClassName; |
|---|
| 101 | case 'ParameterArray': |
|---|
| 102 | return (array) $this->objParameterArray; |
|---|
| 103 | default: |
|---|
| 104 | try { |
|---|
| 105 | return parent::__get($strName); |
|---|
| 106 | } catch (QCallerException $objExc) { |
|---|
| 107 | $objExc->IncrementOffset(); |
|---|
| 108 | throw $objExc; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | /** |
|---|
| 114 | * Override method to perform a property "Set" |
|---|
| 115 | * This will set the property $strName to be $mixValue |
|---|
| 116 | * |
|---|
| 117 | * @param string $strName Name of the property to set |
|---|
| 118 | * @param string $mixValue New value of the property |
|---|
| 119 | * @return mixed |
|---|
| 120 | */ |
|---|
| 121 | public function __set($strName, $mixValue) { |
|---|
| 122 | try { |
|---|
| 123 | switch ($strName) { |
|---|
| 124 | case 'Name': |
|---|
| 125 | return $this->strName = QType::Cast($mixValue, QType::String); |
|---|
| 126 | case 'Schema': |
|---|
| 127 | return $this->strSchema = QType::Cast($mixValue, QType::String); |
|---|
| 128 | case 'ClassName': |
|---|
| 129 | return $this->strClassName = QType::Cast($mixValue, QType::String); |
|---|
| 130 | case 'ParameterArray': |
|---|
| 131 | return $this->objParameterArray = QType::Cast($mixValue, QType::ArrayType); |
|---|
| 132 | default: |
|---|
| 133 | return parent::__set($strName, $mixValue); |
|---|
| 134 | } |
|---|
| 135 | } catch (QCallerException $objExc) { |
|---|
| 136 | $objExc->IncrementOffset(); |
|---|
| 137 | throw $objExc; |
|---|
| 138 | } |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | ?> |
|---|