diff --git a/.gitignore b/.gitignore index 8948c33..736117e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,13 @@ # phpstorm project files -.idea +/.idea # netbeans project files -nbproject +/nbproject # zend studio for eclipse project files -.buildpath -.project -.settings +/.buildpath +/.project +/.settings # windows thumbnail cache Thumbs.db @@ -18,10 +18,13 @@ Thumbs.db # composer itself is not needed composer.phar +# composer.lock is not needed for libraries +/composer.lock + # Mac DS_Store Files .DS_Store # phpunit itself is not needed phpunit.phar # local phpunit config -/phpunit.xml \ No newline at end of file +/phpunit.xml diff --git a/LICENCE.md b/LICENSE.md similarity index 100% rename from LICENCE.md rename to LICENSE.md diff --git a/README.md b/README.md index 24c22d1..8b4127b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # FileMaker® PHP-API -FileMaker® PHP API rewrited for PHP 5.5+. -It is compatible with PHP 7.0+ and use PSR-4 autoloading specifications +FileMaker® PHP API rewritten for PHP 5.5+. +It is compatible with PHP 7.0+ and uses PSR-4 autoloading specifications. ## Features This version of the PHP-API add the following feature to the offical API : @@ -10,9 +10,9 @@ This version of the PHP-API add the following feature to the offical API : * 'dateFormat' option to select the input/output date format (not compatible with find requets yet) * 'emptyAsNull' option to return empty value as null * Support setRange() method with PerformScript command (as supported by CWP) -* A method to get the url of your last CWP call ($fm->getLastRequestedUrl()) -* A method to check if a findRequest is empty ($request->isEmpty()) -* A method to get the value list associated to a field from a Record ($record->getValueListTwoField('my_field')) +* A method to get the url of your last CWP call: `$fm->getLastRequestedUrl()` +* A method to check if a findRequest is empty: `$request->isEmpty()` +* A method to get the value list associated to a field from a Record: `$record->getValueListTwoField('my_field')` ## Requirements @@ -43,7 +43,7 @@ STEP 1 : Read the 'Important Notice' below STEP 2 : include the API autoload ```php -require('/path/to/autoloader.php'); +require '/path/to/autoloader.php'; ``` *This step is facultative if you are using composer* @@ -56,7 +56,7 @@ $fm = new FileMaker($database, $host, $username, $password, $options); STEP 4 : use it quite the same way you would use the offical API... -...And enjoy code completion using your favorite IDE and php 7 support without notice/warnings +...And enjoy code completion using your favorite IDE and php 7 support without notice/warnings. You may also find sample usage by reading the `sample.php` file located in the "demo" folder @@ -95,7 +95,7 @@ The major changes compared to the official package are : * API now support Exceptions error handling, you may switch between those behaviors by changing property 'errorHandeling' to 'default' or 'exception' (default value is 'exception') * There is no more 'conf.php' use "setProperty" to define specifics API's settings. You may also use an array of properties on FileMaker instanciation, ie : new FileMaker( $db, $host, $user, $pass, ['property' => 'value']) -You can use the offical [PHP-API guide](https://fmhelp.filemaker.com/docs/14/fr/fms14_cwp_guide.pdf) provided by FieMaker® for everything else. +You can use the offical [PHP-API guide](https://fmhelp.filemaker.com/docs/14/fr/fms14_cwp_guide.pdf) provided by FileMaker® for everything else. ## TODO * Finish PHPunit test diff --git a/composer.json b/composer.json index 2bdf3fc..1ceaec3 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "airmoi/filemaker", "description": "Rewriten FileMaker PHP-API", "keywords": ["filemaker","PHP-API"], - "license": "FileMaker Sofware Licence", + "license": "FileMaker Sofware license", "authors": [ { "name": "Romain Dunand", @@ -13,5 +13,8 @@ "psr-4": { "airmoi\\FileMaker\\": "src/" } + }, + "require-dev": { + "phpunit/phpunit": "^5.6" } } diff --git a/src/Command/Add.php b/src/Command/Add.php index 7394f9c..3e1ca7e 100644 --- a/src/Command/Add.php +++ b/src/Command/Add.php @@ -1,7 +1,7 @@ $value) { if (!is_array($value)) { $this->setField($fieldname, $value, 0); - } - else { - foreach ( $value as $repetition => $repetitionValue ){ + } else { + foreach ($value as $repetition => $repetitionValue) { $this->setField($fieldname, $repetitionValue, $repetition) ; } } @@ -45,10 +45,11 @@ public function __construct(FileMaker $fm, $layout, $values = array()) { * @return \airmoi\FileMaker\Object\Result|FileMakerException * @throws FileMakerException */ - public function execute() { + public function execute() + { if ($this->fm->getProperty('prevalidate')) { $validation = $this->validate(); - if(FileMaker::isError($validation)) { + if (FileMaker::isError($validation)) { return $validation; } } @@ -86,20 +87,26 @@ public function execute() { * * @return string */ - public function setField($field, $value, $repetition = 0) { + public function setField($field, $value, $repetition = 0) + { $fieldInfos = $this->fm->getLayout($this->_layout)->getField($field); /* if(FileMaker::isError($fieldInfos)){ return $fieldInfos; }*/ - + $format = FileMaker::isError($fieldInfos) ? null : $fieldInfos->result; - if( !empty($value) && $this->fm->getProperty('dateFormat') !== null && ($format == 'date' || $format == 'timestamp')){ - if( $format == 'date' ){ - $dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value . ' 00:00:00'); + if (!empty($value) && $this->fm->getProperty('dateFormat') !== null + && ($format === 'date' || $format === 'timestamp') + ) { + if ($format === 'date') { + $dateTime = \DateTime::createFromFormat( + $this->fm->getProperty('dateFormat') . ' H:i:s', + $value . ' 00:00:00' + ); $value = $dateTime->format('m/d/Y'); } else { - $dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value ); - $value = $dateTime->format( 'm/d/Y H:i:s' ); + $dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value); + $value = $dateTime->format('m/d/Y H:i:s'); } } @@ -126,7 +133,8 @@ public function setField($field, $value, $repetition = 0) { * @return string|FileMakerException * @throws FileMakerException */ - public function setFieldFromTimestamp($field, $timestamp, $repetition = 0) { + public function setFieldFromTimestamp($field, $timestamp, $repetition = 0) + { $layout = $this->fm->getLayout($this->_layout); $fieldInfos = $layout->getField($field); switch ($fieldInfos->getResult()) { @@ -137,11 +145,13 @@ public function setFieldFromTimestamp($field, $timestamp, $repetition = 0) { case 'timestamp': return $this->setField($field, date('m/d/Y H:i:s', $timestamp), $repetition); } - $error = new FileMakerException($this->fm, 'Only time, date, and timestamp fields can be set to the value of a timestamp.'); - if($this->fm->getProperty('errorHandling') == 'default') { + $error = new FileMakerException( + $this->fm, + 'Only time, date, and timestamp fields can be set to the value of a timestamp.' + ); + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } - } diff --git a/src/Command/Command.php b/src/Command/Command.php index 52ca4f8..a85797d 100644 --- a/src/Command/Command.php +++ b/src/Command/Command.php @@ -1,306 +1,307 @@ -fm = $fm; - $this->_layout = $layout; - $this->_recordClass = $fm->getProperty('recordClass'); - } - /** - * Requests that the command's result be returned in a layout different - * from the current layout. - * - * @param string $layout Layout to return results in. - * @return self - */ - public function setResultLayout($layout) - { - $this->_resultLayout = $layout; - return $this; - } - - /** - * Sets a ScriptMaker script to be run after the Find result set is - * generated and sorted. - * - * @param string $scriptName Name of the ScriptMaker script to run. - * @param string $scriptParameters Any parameters to pass to the script. - * @return self - */ - public function setScript($scriptName, $scriptParameters = null) - { - $this->_script = $scriptName; - $this->_scriptParams = $scriptParameters; - return $this; - } - - /** - * Sets a ScriptMaker script to be run before performing a command. - * - * @param string $scriptName Name of the ScriptMaker script to run. - * @param string $scriptParameters Any parameters to pass to the script. - * @return self - */ - public function setPreCommandScript($scriptName, $scriptParameters = null) - { - $this->_preReqScript = $scriptName; - $this->_preReqScriptParams = $scriptParameters; - return $this; - } - - /** - * Sets a ScriptMaker script to be run after performing a Find command, - * but before sorting the result set. - * - * @param string $scriptName Name of the ScriptMaker script to run. - * @param string $scriptParameters Any parameters to pass to the script. - * @return self - */ - public function setPreSortScript($scriptName, $scriptParameters = null) - { - $this->_preSortScript = $scriptName; - $this->_preSortScriptParams = $scriptParameters; - return $this; - } - - /** - * Sets the PHP class that the API instantiates to represent records - * returned in any result set. - * - * The default is to use the provided \airmoi\FileMaker\Object\Record class. Any - * substitute classes must provide the same API that \airmoi\FileMaker\Object\Record does, - * either by extending it or re-implementing the necessary methods. The - * user is responsible for defining any custom class before the API - * needs to instantiate it. - * - * @param string $className Name of the class to represent records. - * @return self - */ - public function setRecordClass($className) - { - $this->_recordClass = $className; - return $this; - } - - /** - * Pre-validates either a single field or the entire command. - * - * This method uses the pre-validation rules that are enforceable by the - * PHP engine -- for example, type rules, ranges, and four-digit dates. - * Rules such as "unique" or "existing," or validation by calculation - * field, cannot be pre-validated. - * - * If you pass the optional $fieldName argument, only that field is - * pre-validated. Otherwise, the command is pre-validated as if execute() - * were called with "Enable record data pre-validation" selected in - * FileMaker Server Admin Console. If pre-validation passes, validate() - * returns TRUE. If pre-validation fails, then validate() throws a - * \airmoi\FileMaker\FileMakerValidationException object containing details about what failed - * to pre-validate. - * - * @param string $fieldName Name of field to pre-validate. If empty, - * pre-validates the entire command. - * - * @return bool TRUE, if pre-validation passes. - * @throws FileMakerException - * @throws FileMakerValidationException - */ - public function validate($fieldName = null) - { - if (!is_a($this, Add::class) && !is_a($this, Edit::class)) { - return true; - } - $layout = $this->fm->getLayout($this->_layout); - $validationErrors = new FileMakerValidationException($this->fm); - if ($fieldName === null) { - foreach ($layout->getFields() as $fieldName => $field) { - if (!isset($this->_fields[$fieldName]) || !count($this->_fields[$fieldName])) { - $values = array( - 0 => null - ); - } else { - $values = $this->_fields[$fieldName]; - } - foreach ($values as $value) { - try { - $field->validate($value); - }catch (FileMakerValidationException $e){ - foreach ( $e->getErrors() as $error ) { - $validationErrors->addError($error[0], $error[1], $error[2]); - } - } - } - } - } else { - $field = $layout->getField($fieldName); - if (!isset($this->_fields[$fieldName]) || !count($this->_fields[$fieldName])) { - $values = array( - 0 => null - ); - } else { - $values = $this->_fields[$fieldName]; - } - foreach ($values as $value) { - try { - $field->validate($value); - }catch (FileMakerValidationException $e){ - foreach ( $e->getErrors() as $error ) { - $validationErrors->addError($error[0], $error[1], $error[2]); - } - } - } - } - if ( $validationErrors->numErrors() ) { - if($this->fm->getProperty('errorHandling') == 'default') { - return $validationErrors; - } - throw $validationErrors; - } - return true; - } - - /** - * Executes the command. - * - * @return Result Result object. - */ - public function execute() - { - - } - - /** - * Sets the record ID for this command. - * - * For Edit, Delete, and Duplicate commands, a record ID must be specified. - * It is also possible to find a single record by specifying its record - * ID. This method is ignored by Add and FindAny commands. - * - * @param string $recordId ID of record this command acts upon. - * @return self - */ - public function setRecordId($recordId) - { - $this->recordId = $recordId; - return $this; - } - - /** - * Set a global field to be define before perfoming the command. - * - * - * @param string $fieldName the global field name. - * @param string $fieldValue value to be set. - * @return self - */ - public function setGlobal($fieldName, $fieldValue) - { - $this->_globals[$fieldName] = $fieldValue; - return $this; - } - - /** - * - * @param string $xml - * @return Result|FileMakerException - * @throws FileMakerException - */ - protected function _getResult($xml) { - $parser = new FMResultSet($this->fm); - $parseResult = $parser->parse($xml); - if(FileMaker::isError($parseResult)){ - return $parseResult; - } - - $result = new Result($this->fm); - $parseResult = $parser->setResult($result, $this->_recordClass); - if(FileMaker::isError($parseResult)){ - return $parseResult; - } - - return $result; - } - - protected function _getCommandParams() { - $queryParams = array( - '-db' => $this->fm->getProperty('database' - ), '-lay' => $this->_layout); - - foreach (array( - '_script' => '-script', - '_preReqScript' => '-script.prefind', - '_preSortScript' => '-script.presort' - ) as $varName => $paramName) - { - if ($this->$varName) { - $queryParams[$paramName] = $this->$varName; - $varName .= 'Params'; - if ($this->$varName !== null) { - $queryParams[$paramName . '.param'] = $this->$varName; - } - } - } - if ($this->_resultLayout) { - $queryParams['-lay.response'] = $this->_resultLayout; - } - - foreach ( $this->_globals as $fieldName => $fieldValue ){ - $queryParams[$fieldName.'.global'] = $fieldValue; - } - return $queryParams; - } - -} +fm = $fm; + $this->_layout = $layout; + $this->_recordClass = $fm->getProperty('recordClass'); + } + /** + * Requests that the command's result be returned in a layout different + * from the current layout. + * + * @param string $layout Layout to return results in. + * @return self + */ + public function setResultLayout($layout) + { + $this->_resultLayout = $layout; + return $this; + } + + /** + * Sets a ScriptMaker script to be run after the Find result set is + * generated and sorted. + * + * @param string $scriptName Name of the ScriptMaker script to run. + * @param string $scriptParameters Any parameters to pass to the script. + * @return self + */ + public function setScript($scriptName, $scriptParameters = null) + { + $this->_script = $scriptName; + $this->_scriptParams = $scriptParameters; + return $this; + } + + /** + * Sets a ScriptMaker script to be run before performing a command. + * + * @param string $scriptName Name of the ScriptMaker script to run. + * @param string $scriptParameters Any parameters to pass to the script. + * @return self + */ + public function setPreCommandScript($scriptName, $scriptParameters = null) + { + $this->_preReqScript = $scriptName; + $this->_preReqScriptParams = $scriptParameters; + return $this; + } + + /** + * Sets a ScriptMaker script to be run after performing a Find command, + * but before sorting the result set. + * + * @param string $scriptName Name of the ScriptMaker script to run. + * @param string $scriptParameters Any parameters to pass to the script. + * @return self + */ + public function setPreSortScript($scriptName, $scriptParameters = null) + { + $this->_preSortScript = $scriptName; + $this->_preSortScriptParams = $scriptParameters; + return $this; + } + + /** + * Sets the PHP class that the API instantiates to represent records + * returned in any result set. + * + * The default is to use the provided \airmoi\FileMaker\Object\Record class. Any + * substitute classes must provide the same API that \airmoi\FileMaker\Object\Record does, + * either by extending it or re-implementing the necessary methods. The + * user is responsible for defining any custom class before the API + * needs to instantiate it. + * + * @param string $className Name of the class to represent records. + * @return self + */ + public function setRecordClass($className) + { + $this->_recordClass = $className; + return $this; + } + + /** + * Pre-validates either a single field or the entire command. + * + * This method uses the pre-validation rules that are enforceable by the + * PHP engine -- for example, type rules, ranges, and four-digit dates. + * Rules such as "unique" or "existing," or validation by calculation + * field, cannot be pre-validated. + * + * If you pass the optional $fieldName argument, only that field is + * pre-validated. Otherwise, the command is pre-validated as if execute() + * were called with "Enable record data pre-validation" selected in + * FileMaker Server Admin Console. If pre-validation passes, validate() + * returns TRUE. If pre-validation fails, then validate() throws a + * \airmoi\FileMaker\FileMakerValidationException object containing details about what failed + * to pre-validate. + * + * @param string $fieldName Name of field to pre-validate. If empty, + * pre-validates the entire command. + * + * @return bool TRUE, if pre-validation passes. + * @throws FileMakerException + * @throws FileMakerValidationException + */ + public function validate($fieldName = null) + { + if (!is_a($this, Add::class) && !is_a($this, Edit::class)) { + return true; + } + $layout = $this->fm->getLayout($this->_layout); + $validationErrors = new FileMakerValidationException($this->fm); + if ($fieldName === null) { + foreach ($layout->getFields() as $fieldName => $field) { + if (!isset($this->_fields[$fieldName]) || !count($this->_fields[$fieldName])) { + $values = array( + 0 => null + ); + } else { + $values = $this->_fields[$fieldName]; + } + foreach ($values as $value) { + try { + $field->validate($value); + } catch (FileMakerValidationException $e) { + foreach ($e->getErrors() as $error) { + $validationErrors->addError($error[0], $error[1], $error[2]); + } + } + } + } + } else { + $field = $layout->getField($fieldName); + if (!isset($this->_fields[$fieldName]) || !count($this->_fields[$fieldName])) { + $values = array( + 0 => null + ); + } else { + $values = $this->_fields[$fieldName]; + } + foreach ($values as $value) { + try { + $field->validate($value); + } catch (FileMakerValidationException $e) { + foreach ($e->getErrors() as $error) { + $validationErrors->addError($error[0], $error[1], $error[2]); + } + } + } + } + if ($validationErrors->numErrors()) { + if ($this->fm->getProperty('errorHandling') === 'default') { + return $validationErrors; + } + throw $validationErrors; + } + return true; + } + + /** + * Executes the command. + * + * @return Result Result object. + */ + public function execute() + { + } + + /** + * Sets the record ID for this command. + * + * For Edit, Delete, and Duplicate commands, a record ID must be specified. + * It is also possible to find a single record by specifying its record + * ID. This method is ignored by Add and FindAny commands. + * + * @param string $recordId ID of record this command acts upon. + * @return self + */ + public function setRecordId($recordId) + { + $this->recordId = $recordId; + return $this; + } + + /** + * Set a global field to be define before perfoming the command. + * + * + * @param string $fieldName the global field name. + * @param string $fieldValue value to be set. + * @return self + */ + public function setGlobal($fieldName, $fieldValue) + { + $this->_globals[$fieldName] = $fieldValue; + return $this; + } + + /** + * + * @param string $xml + * @return Result|FileMakerException + * @throws FileMakerException + */ + protected function _getResult($xml) + { + $parser = new FMResultSet($this->fm); + $parseResult = $parser->parse($xml); + if (FileMaker::isError($parseResult)) { + return $parseResult; + } + + $result = new Result($this->fm); + $parseResult = $parser->setResult($result, $this->_recordClass); + if (FileMaker::isError($parseResult)) { + return $parseResult; + } + + return $result; + } + + protected function _getCommandParams() + { + $queryParams = array( + '-db' => $this->fm->getProperty('database'), + '-lay' => $this->_layout + ); + + foreach (array( + '_script' => '-script', + '_preReqScript' => '-script.prefind', + '_preSortScript' => '-script.presort' + ) as $varName => $paramName) { + if ($this->$varName) { + $queryParams[$paramName] = $this->$varName; + $varName .= 'Params'; + if ($this->$varName !== null) { + $queryParams[$paramName . '.param'] = $this->$varName; + } + } + } + if ($this->_resultLayout) { + $queryParams['-lay.response'] = $this->_resultLayout; + } + + foreach ($this->_globals as $fieldName => $fieldValue) { + $queryParams[$fieldName.'.global'] = $fieldValue; + } + return $queryParams; + } +} diff --git a/src/Command/CompoundFind.php b/src/Command/CompoundFind.php index 7facdd6..25c848e 100644 --- a/src/Command/CompoundFind.php +++ b/src/Command/CompoundFind.php @@ -1,7 +1,7 @@ findCriteria; $critCount = count($findCriterias); - $query = $query . '('; + $query .= '('; $i = 0; foreach ($findCriterias as $fieldname => $testvalue) { @@ -105,17 +106,17 @@ public function execute() { $i++; if ($i < $critCount) { - $query = $query . ','; + $query .= ','; } } - $query = $query . ")"; + $query .= ')'; $requestCount++; if ($requestCount <= $totalRequestCount) { $nextRequest = $this->_requests[$precedence + 1]; - if ($nextRequest->omit == true) { - $query = $query . ';!'; + if ($nextRequest->omit === true) { + $query .= ';!'; } else { - $query = $query . ';'; + $query .= ';'; } } } @@ -148,8 +149,10 @@ public function setRange($skip = 0, $max = null) */ public function getRange() { - return array('skip' => $this->_skip, - 'max' => $this->_max); + return array( + 'skip' => $this->_skip, + 'max' => $this->_max + ); } /** @@ -185,7 +188,8 @@ public function getRelatedSetsFilters() 'relatedsetsmax' => $this->_relatedsetsmax); } - public function _setRelatedSetsFilters(&$params) { + public function _setRelatedSetsFilters(&$params) + { if ($this->_relatedsetsfilter) { $params['-relatedsets.filter'] = $this->_relatedsetsfilter; } @@ -194,7 +198,8 @@ public function _setRelatedSetsFilters(&$params) { } } - public function _setSortParams(&$params) { + public function _setSortParams(&$params) + { foreach ($this->_sortFields as $precedence => $fieldname) { $params['-sortfield.' . $precedence] = $fieldname; } @@ -203,7 +208,8 @@ public function _setSortParams(&$params) { } } - public function _setRangeParams(&$params) { + public function _setRangeParams(&$params) + { if ($this->_skip) { $params['-skip'] = $this->_skip; } diff --git a/src/Command/Delete.php b/src/Command/Delete.php index 88d560f..7fc05e8 100644 --- a/src/Command/Delete.php +++ b/src/Command/Delete.php @@ -1,7 +1,7 @@ recordId = $recordId; } - + /** - * + * * @return \airmoi\FileMaker\Object\Result|FileMakerException * @throws FileMakerException */ - public function execute() { + public function execute() + { if (empty($this->recordId)) { $error = new FileMakerException($this->fm, 'Delete commands require a record id.'); - if($this->fm->getProperty('errorHandling') == 'default') { + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; diff --git a/src/Command/Duplicate.php b/src/Command/Duplicate.php index 96f07dd..719ca1c 100644 --- a/src/Command/Duplicate.php +++ b/src/Command/Duplicate.php @@ -1,7 +1,7 @@ recordId = $recordId; } - + /** * Return a Result object with the duplicated record * use Result->getFirstRecord() to get the record - * + * * @return Result|FileMakerException * @throws FileMakerException */ - public function execute() { + public function execute() + { if (empty($this->recordId)) { $error = new FileMakerException($this->fm, 'Duplicate commands require a record id.'); - if($this->fm->getProperty('errorHandling') == 'default') { + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; diff --git a/src/Command/Edit.php b/src/Command/Edit.php index bd2586c..8a36f95 100644 --- a/src/Command/Edit.php +++ b/src/Command/Edit.php @@ -1,7 +1,7 @@ value pairs. - * To set field repetitions, use a numerically indexed array for - * the value of a field, with the numeric keys corresponding to the + * @param array $updatedValues Associative array of field name => value pairs. + * To set field repetitions, use a numerically indexed array for + * the value of a field, with the numeric keys corresponding to the * repetition number to set. */ public function __construct(FileMaker $fm, $layout, $recordId, $updatedValues = []) @@ -39,34 +39,34 @@ public function __construct(FileMaker $fm, $layout, $recordId, $updatedValues = $this->_deleteRelated = null; foreach ($updatedValues as $fieldname => $value) { if (!is_array($value)) { - $this->setField($fieldname, $value, 0); - } - else { - foreach ( $value as $repetition => $repetitionValue ){ + $this->setField($fieldname, $value, 0); + } else { + foreach ($value as $repetition => $repetitionValue) { $this->setField($fieldname, $repetitionValue, $repetition) ; } } } } - + /** - * + * * @return \airmoi\FileMaker\Object\Result|FileMakerException|FileMakerValidationException * @throws FileMakerException|FileMakerValidationException */ - public function execute() { + public function execute() + { $params = $this->_getCommandParams(); if (empty($this->recordId)) { - $error = new FileMakerException ($this->fm, 'Edit commands require a record id.'); - if($this->fm->getProperty('errorHandling') == 'default') { + $error = new FileMakerException($this->fm, 'Edit commands require a record id.'); + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } if (!count($this->_fields)) { - if ($this->_deleteRelated == null) { - $error = new FileMakerException ($this->fm, 'There are no changes to make.'); - if($this->fm->getProperty('errorHandling') == 'default') { + if ($this->_deleteRelated === null) { + $error = new FileMakerException($this->fm, 'There are no changes to make.'); + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -75,15 +75,15 @@ public function execute() { if ($this->fm->getProperty('prevalidate')) { $validation = $this->validate(); - if(FileMaker::isError($validation)) { + if (FileMaker::isError($validation)) { return $validation; } } $layout = $this->fm->getLayout($this->_layout); - + $params['-edit'] = true; - if ($this->_deleteRelated == null) { + if ($this->_deleteRelated === null) { foreach ($this->_fields as $fieldname => $values) { if (strpos($fieldname, '.') !== false) { list ($fieldname, $infos) = explode('.', $fieldname, 2); @@ -101,7 +101,7 @@ public function execute() { } } } - if ($this->_deleteRelated != null) { + if ($this->_deleteRelated !== null) { $params['-delete.related'] = $this->_deleteRelated; } $params['-recid'] = $this->recordId; @@ -119,7 +119,7 @@ public function execute() { * @param string $value Value for the field. * @param integer $repetition Field repetition number to set, * Defaults to the first repetition. - * + * * @return string|FileMakerException * @throws FileMakerException */ @@ -129,39 +129,44 @@ public function setField($field, $value, $repetition = 0) /*if(FileMaker::isError($fieldInfos)){ return $fieldInfos; }*/ - + $format = FileMaker::isError($fieldInfos) ? null : $fieldInfos->result; - - if( !empty($value) && $this->fm->getProperty('dateFormat') !== null && ($format == 'date' || $format == 'timestamp')){ - if( $format == 'date' ){ - $dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value . ' 00:00:00'); + + if (!empty($value) && $this->fm->getProperty('dateFormat') !== null + && ($format === 'date' || $format === 'timestamp') + ) { + if ($format === 'date') { + $dateTime = \DateTime::createFromFormat( + $this->fm->getProperty('dateFormat') . ' H:i:s', + $value . ' 00:00:00' + ); $value = $dateTime->format('m/d/Y'); } else { - $dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value ); - $value = $dateTime->format( 'm/d/Y H:i:s' ); + $dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value); + $value = $dateTime->format('m/d/Y H:i:s'); } } - + $this->_fields[$field][$repetition] = $value; return $value; } /** * Sets the new value for a date, time, or timestamp field from a - * UNIX timestamp value. + * UNIX timestamp value. * - * If the field is not a date or time field, then this method returns + * If the field is not a date or time field, then this method returns * an Error object. Otherwise, returns TRUE. * - * If layout data for the target of this command has not already + * If layout data for the target of this command has not already * been loaded, calling this method loads layout data so that * the type of the field can be checked. * * @param string $field Name of the field to set. * @param string $timestamp Timestamp value. - * @param integer $repetition Field repetition number to set. + * @param integer $repetition Field repetition number to set. * Defaults to the first repetition. - * + * * @return string|FileMakerException * @throws FileMakerException */ @@ -176,15 +181,18 @@ public function setFieldFromTimestamp($field, $timestamp, $repetition = 0) return $field; } switch ($field->getResult()) { - case 'date' : + case 'date': return $this->setField($field, date('m/d/Y', $timestamp), $repetition); - case 'time' : + case 'time': return $this->setField($field, date('H:i:s', $timestamp), $repetition); - case 'timestamp' : + case 'timestamp': return $this->setField($field, date('m/d/Y H:i:s', $timestamp), $repetition); } - $error = new FileMakerException($this->fm, 'Only time, date, and timestamp fields can be set to the value of a timestamp.'); - if($this->fm->getProperty('errorHandling') == 'default') { + $error = new FileMakerException( + $this->fm, + 'Only time, date, and timestamp fields can be set to the value of a timestamp.' + ); + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -193,14 +201,14 @@ public function setFieldFromTimestamp($field, $timestamp, $repetition = 0) /** * Sets the modification ID for this command. * - * Before you edit a record, you can use the - * {@link Record::getModificationId()} method to get the record's - * modification ID. By specifying a modification ID when you execute an - * Edit command, you can make sure that you are editing the current version - * of a record. If the modification ID value you specify does not match the - * current modification ID value in the database, the Edit command is not - * allowed and an error code is returned. - * + * Before you edit a record, you can use the + * {@link Record::getModificationId()} method to get the record's + * modification ID. By specifying a modification ID when you execute an + * Edit command, you can make sure that you are editing the current version + * of a record. If the modification ID value you specify does not match the + * current modification ID value in the database, the Edit command is not + * allowed and an error code is returned. + * * @param integer $modificationId Modification ID. */ public function setModificationId($modificationId) @@ -208,8 +216,8 @@ public function setModificationId($modificationId) $this->_modificationId = $modificationId; } - public function setDeleteRelated($relatedRecordId) { + public function setDeleteRelated($relatedRecordId) + { $this->_deleteRelated = $relatedRecordId; } - } diff --git a/src/Command/Find.php b/src/Command/Find.php index c511df5..76af268 100644 --- a/src/Command/Find.php +++ b/src/Command/Find.php @@ -1,245 +1,248 @@ -_findCriteria[$fieldname] = $testvalue; - return $this; - } - - /** - * Clears all existing criteria from this Find command. - * - * @return self - */ - public function clearFindCriteria() - { - $this->_findCriteria = []; - return $this; - } - - /** - * Adds a sorting rule to this Find command. - * - * @param string $fieldname Name of the field to sort by. - * @param integer $precedence Integer from 1 to 9, inclusive. A value - * of 1 sorts records based on this sorting rule first, a value of - * 2 sorts records based on this sorting rule only when two or more - * records have the same value after the first sorting rule is - * applied, and so on. - * @param mixed $order Direction of the sort. Specify the - * FileMaker::SORT_ASCEND constant, the FileMaker::SORT_DESCEND - * constant, or the name of a value list specified as a string. - * - * @return self - */ - public function addSortRule($fieldname, $precedence, $order = null) - { - $this->_sortRules[$precedence] = $fieldname; - if ($order !== null) { - $this->_sortOrders[$precedence] = $order; - } - return $this; - } - - /** - * Clears all existing sorting rules from this Find command. - * - * @return self - */ - public function clearSortRules() - { - $this->_sortRules = array(); - $this->_sortOrders = array(); - return $this; - } - - public function execute() { - $params = $this->_getCommandParams(); - $this->_setSortParams($params); - $this->_setRangeParams($params); - $this->_setRelatedSetsFilters($params); - if (count($this->_findCriteria) || $this->recordId) { - $params['-find'] = true; - } else { - $params['-findall'] = true; - } - if ($this->recordId) { - $params['-recid'] = $this->recordId; - } - if ($this->_operator) { - $params['-lop'] = $this->_operator; - } - foreach ($this->_findCriteria as $field => $value) { - $params[$field] = $value; - } - $result = $this->fm->execute($params); - if (FileMaker::isError($result)) { - return $result; - } - return $this->_getResult($result); - } - - /** - * Specifies how the find criteria in this Find command are combined - * as either a logical AND or OR search. - * - * If not specified, the default is a logical AND. - * - * @param integer $operator Specify the FileMaker::FIND_AND or - * FileMaker::FIND_OR constant. - * - * @return self - */ - public function setLogicalOperator($operator) - { - switch ($operator) { - case FileMaker::FIND_AND: - case FileMaker::FIND_OR: - $this->_operator = $operator; - break; - } - return $this; - } - - /** - * Sets a range to request only part of the result set. - * - * @param integer $skip Number of records to skip past. Default is 0. - * @param integer $max Maximum number of records to return. - * Default is all. - * - * @return self - */ - public function setRange($skip = 0, $max = null) - { - $this->_skip = $skip; - $this->_max = $max; - return $this; - } - - /** - * Returns the current range settings. - * - * @return array Associative array with two keys: 'skip' for - * the current skip setting, and 'max' for the current maximum - * number of records. If either key does not have a value, the - * returned value for that key is NULL. - */ - public function getRange() - { - return array('skip' => $this->_skip, - 'max' => $this->_max); - } - - /** - * Sets a filter to restrict the number of related records to return from - * a portal. - * - * The filter limits the number of related records returned by respecting - * the settings specified in the FileMaker Pro Portal Setup dialog box. - * - * @param string $relatedsetsfilter Specify one of these values to - * control filtering: - * - 'layout': Apply the settings specified in the FileMaker Pro - * Portal Setup dialog box. The records are sorted based - * on the sort defined in the Portal Setup dialog box, - * with the record set filtered to start with the - * specified "Initial row." - * - 'none': Return all related records in the portal without - * filtering or presorting them. - * - * @param string $relatedsetsmax If the "Show vertical scroll bar" setting - * is enabled in the Portal Setup dialog box, specify one of these - * values: - * - an integer value: Return this maximum number of related records - * after the initial record. - * - 'all': Return all of the related records in the portal. - * If "Show vertical scroll bar" is disabled, the Portal - * Setup dialog box's "Number of rows" setting determines - * the maximum number of related records to return. - * - * @return self - */ - public function setRelatedSetsFilters($relatedsetsfilter, $relatedsetsmax = null) - { - $this->_relatedsetsfilter = $relatedsetsfilter; - $this->_relatedsetsmax = $relatedsetsmax; - return $this; - } - - /** - * Returns the current settings for the related records filter and - * the maximum number of related records to return. - * - * @return array Associative array with two keys: 'relatedsetsfilter' for - * the portal filter setting, and 'relatedsetsmax' for the maximum - * number of records. If either key does not have a value, the returned - * for that key is NULL. - */ - public function getRelatedSetsFilters() - { - return array('relatedsetsfilter' => $this->_relatedsetsfilter, - 'relatedsetsmax' => $this->_relatedsetsmax); - } - - protected function _setRelatedSetsFilters(&$params) { - if ($this->_relatedsetsfilter) { - $params['-relatedsets.filter'] = $this->_relatedsetsfilter; - } - if ($this->_relatedsetsmax) { - $params['-relatedsets.max'] = $this->_relatedsetsmax; - } - } - - protected function _setSortParams(&$params) { - foreach ($this->_sortRules as $precedence => $fieldname) { - $params['-sortfield.' . $precedence] = $fieldname; - } - foreach ($this->_sortOrders as $precedence => $order) { - $params['-sortorder.' . $precedence] = $order; - } - } - - protected function _setRangeParams(&$params) { - if ($this->_skip) { - $params['-skip'] = $this->_skip; - } - if ($this->_max) { - $params['-max'] = $this->_max; - } - } - -} +_findCriteria[$fieldname] = $testvalue; + return $this; + } + + /** + * Clears all existing criteria from this Find command. + * + * @return self + */ + public function clearFindCriteria() + { + $this->_findCriteria = []; + return $this; + } + + /** + * Adds a sorting rule to this Find command. + * + * @param string $fieldname Name of the field to sort by. + * @param integer $precedence Integer from 1 to 9, inclusive. A value + * of 1 sorts records based on this sorting rule first, a value of + * 2 sorts records based on this sorting rule only when two or more + * records have the same value after the first sorting rule is + * applied, and so on. + * @param mixed $order Direction of the sort. Specify the + * FileMaker::SORT_ASCEND constant, the FileMaker::SORT_DESCEND + * constant, or the name of a value list specified as a string. + * + * @return self + */ + public function addSortRule($fieldname, $precedence, $order = null) + { + $this->_sortRules[$precedence] = $fieldname; + if ($order !== null) { + $this->_sortOrders[$precedence] = $order; + } + return $this; + } + + /** + * Clears all existing sorting rules from this Find command. + * + * @return self + */ + public function clearSortRules() + { + $this->_sortRules = array(); + $this->_sortOrders = array(); + return $this; + } + + public function execute() + { + $params = $this->_getCommandParams(); + $this->_setSortParams($params); + $this->_setRangeParams($params); + $this->_setRelatedSetsFilters($params); + if (count($this->_findCriteria) || $this->recordId) { + $params['-find'] = true; + } else { + $params['-findall'] = true; + } + if ($this->recordId) { + $params['-recid'] = $this->recordId; + } + if ($this->_operator) { + $params['-lop'] = $this->_operator; + } + foreach ($this->_findCriteria as $field => $value) { + $params[$field] = $value; + } + $result = $this->fm->execute($params); + if (FileMaker::isError($result)) { + return $result; + } + return $this->_getResult($result); + } + + /** + * Specifies how the find criteria in this Find command are combined + * as either a logical AND or OR search. + * + * If not specified, the default is a logical AND. + * + * @param integer $operator Specify the FileMaker::FIND_AND or + * FileMaker::FIND_OR constant. + * + * @return self + */ + public function setLogicalOperator($operator) + { + switch ($operator) { + case FileMaker::FIND_AND: + case FileMaker::FIND_OR: + $this->_operator = $operator; + break; + } + return $this; + } + + /** + * Sets a range to request only part of the result set. + * + * @param integer $skip Number of records to skip past. Default is 0. + * @param integer $max Maximum number of records to return. + * Default is all. + * + * @return self + */ + public function setRange($skip = 0, $max = null) + { + $this->_skip = $skip; + $this->_max = $max; + return $this; + } + + /** + * Returns the current range settings. + * + * @return array Associative array with two keys: 'skip' for + * the current skip setting, and 'max' for the current maximum + * number of records. If either key does not have a value, the + * returned value for that key is NULL. + */ + public function getRange() + { + return array('skip' => $this->_skip, + 'max' => $this->_max); + } + + /** + * Sets a filter to restrict the number of related records to return from + * a portal. + * + * The filter limits the number of related records returned by respecting + * the settings specified in the FileMaker Pro Portal Setup dialog box. + * + * @param string $relatedsetsfilter Specify one of these values to + * control filtering: + * - 'layout': Apply the settings specified in the FileMaker Pro + * Portal Setup dialog box. The records are sorted based + * on the sort defined in the Portal Setup dialog box, + * with the record set filtered to start with the + * specified "Initial row." + * - 'none': Return all related records in the portal without + * filtering or presorting them. + * + * @param string $relatedsetsmax If the "Show vertical scroll bar" setting + * is enabled in the Portal Setup dialog box, specify one of these + * values: + * - an integer value: Return this maximum number of related records + * after the initial record. + * - 'all': Return all of the related records in the portal. + * If "Show vertical scroll bar" is disabled, the Portal + * Setup dialog box's "Number of rows" setting determines + * the maximum number of related records to return. + * + * @return self + */ + public function setRelatedSetsFilters($relatedsetsfilter, $relatedsetsmax = null) + { + $this->_relatedsetsfilter = $relatedsetsfilter; + $this->_relatedsetsmax = $relatedsetsmax; + return $this; + } + + /** + * Returns the current settings for the related records filter and + * the maximum number of related records to return. + * + * @return array Associative array with two keys: 'relatedsetsfilter' for + * the portal filter setting, and 'relatedsetsmax' for the maximum + * number of records. If either key does not have a value, the returned + * for that key is NULL. + */ + public function getRelatedSetsFilters() + { + return array('relatedsetsfilter' => $this->_relatedsetsfilter, + 'relatedsetsmax' => $this->_relatedsetsmax); + } + + protected function _setRelatedSetsFilters(&$params) + { + if ($this->_relatedsetsfilter) { + $params['-relatedsets.filter'] = $this->_relatedsetsfilter; + } + if ($this->_relatedsetsmax) { + $params['-relatedsets.max'] = $this->_relatedsetsmax; + } + } + + protected function _setSortParams(&$params) + { + foreach ($this->_sortRules as $precedence => $fieldname) { + $params['-sortfield.' . $precedence] = $fieldname; + } + foreach ($this->_sortOrders as $precedence => $order) { + $params['-sortorder.' . $precedence] = $order; + } + } + + protected function _setRangeParams(&$params) + { + if ($this->_skip) { + $params['-skip'] = $this->_skip; + } + if ($this->_max) { + $params['-max'] = $this->_max; + } + } +} diff --git a/src/Command/FindAll.php b/src/Command/FindAll.php index be1e385..5ad4d4b 100644 --- a/src/Command/FindAll.php +++ b/src/Command/FindAll.php @@ -1,7 +1,7 @@ _getCommandParams(); + public function execute() + { + $params = $this->_getCommandParams(); $params['-findall'] = true; $this->_setSortParams($params); $this->_setRangeParams($params); - $result = $this->fm->execute($params); - return $this->_getResult($result); + return $this->_getResult($this->fm->execute($params)); } - } diff --git a/src/Command/FindAny.php b/src/Command/FindAny.php index 7bed300..19ba5bd 100644 --- a/src/Command/FindAny.php +++ b/src/Command/FindAny.php @@ -1,7 +1,7 @@ _getCommandParams(); + public function execute() + { + $params = $this->_getCommandParams(); $params['-findany'] = true; - $result = $this->fm->execute($params); - return $this->_getResult($result); + return $this->_getResult($this->fm->execute($params)); } - } diff --git a/src/Command/FindRequest.php b/src/Command/FindRequest.php index 288bc1b..e4382fe 100644 --- a/src/Command/FindRequest.php +++ b/src/Command/FindRequest.php @@ -1,81 +1,81 @@ -omit = false; - } - - /** - * Sets whether this request is an omit request. - * - * An omit request removes the matching records from the final result set. - * - * @param boolean $value TRUE if this is an omit request. Otherwise, FALSE. - * - * @return self - */ - public function setOmit($value) - { - $this->omit = $value; - return $this; - } - - /** - * Adds a criterion to this find request. - * - * @param string $fieldname Name of the field being tested. - * @param string $testvalue Value of the field to test against. - * - * @return self - */ - public function addFindCriterion($fieldname, $testvalue) - { - $this->findCriteria[$fieldname] = $testvalue; - return $this; - } - - /** - * Clears all existing criteria from this find request. - * - * @return self - */ - public function clearFindCriteria() - { - $this->findCriteria = array(); - return $this; - } - - /** - * - * @return bool true if the request as no criterion set - */ - public function isEmpty() { - return sizeof($this->findCriteria) === 0; - } - -} +omit = false; + } + + /** + * Sets whether this request is an omit request. + * + * An omit request removes the matching records from the final result set. + * + * @param boolean $value TRUE if this is an omit request. Otherwise, FALSE. + * + * @return self + */ + public function setOmit($value) + { + $this->omit = $value; + return $this; + } + + /** + * Adds a criterion to this find request. + * + * @param string $fieldname Name of the field being tested. + * @param string $testvalue Value of the field to test against. + * + * @return self + */ + public function addFindCriterion($fieldname, $testvalue) + { + $this->findCriteria[$fieldname] = $testvalue; + return $this; + } + + /** + * Clears all existing criteria from this find request. + * + * @return self + */ + public function clearFindCriteria() + { + $this->findCriteria = array(); + return $this; + } + + /** + * + * @return bool true if the request as no criterion set + */ + public function isEmpty() + { + return empty($this->findCriteria); + } +} diff --git a/src/Command/PerformScript.php b/src/Command/PerformScript.php index 86f4349..95ed174 100644 --- a/src/Command/PerformScript.php +++ b/src/Command/PerformScript.php @@ -1,92 +1,94 @@ -_script = $scriptName; - $this->_scriptParams = $scriptParameters; - } - - /** - * Sets a range to request only part of the result set. - * - * @param integer $skip Number of records to skip past. Default is 0. - * @param integer $max Maximum number of records to return. - * Default is all. - * - * @return self - */ - public function setRange($skip = 0, $max = null) - { - $this->_skip = $skip; - $this->_max = $max; - return $this; - } - - /** - * Returns the current range settings. - * - * @return array Associative array with two keys: 'skip' for - * the current skip setting, and 'max' for the current maximum - * number of records. If either key does not have a value, the - * returned value for that key is NULL. - */ - public function getRange() - { - return array('skip' => $this->_skip, - 'max' => $this->_max); - } - - /** - * - * @return Result - */ - public function execute() { - $params = $this->_getCommandParams(); - $params['-findany'] = true; - $this->_setRangeParams($params); - $cUrlResponse = $this->fm->execute($params); - return $this->_getResult($cUrlResponse); - } - - protected function _setRangeParams(&$params) { - if ($this->_skip) { - $params['-skip'] = $this->_skip; - } - if ($this->_max) { - $params['-max'] = $this->_max; - } - } - -} +_script = $scriptName; + $this->_scriptParams = $scriptParameters; + } + + /** + * Sets a range to request only part of the result set. + * + * @param integer $skip Number of records to skip past. Default is 0. + * @param integer $max Maximum number of records to return. + * Default is all. + * + * @return self + */ + public function setRange($skip = 0, $max = null) + { + $this->_skip = $skip; + $this->_max = $max; + return $this; + } + + /** + * Returns the current range settings. + * + * @return array Associative array with two keys: 'skip' for + * the current skip setting, and 'max' for the current maximum + * number of records. If either key does not have a value, the + * returned value for that key is NULL. + */ + public function getRange() + { + return array( + 'skip' => $this->_skip, + 'max' => $this->_max + ); + } + + /** + * + * @return Result + */ + public function execute() + { + $params = $this->_getCommandParams(); + $params['-findany'] = true; + $this->_setRangeParams($params); + return $this->_getResult($this->fm->execute($params)); + } + + protected function _setRangeParams(&$params) + { + if ($this->_skip) { + $params['-skip'] = $this->_skip; + } + if ($this->_max) { + $params['-max'] = $this->_max; + } + } +} diff --git a/src/FileMaker.php b/src/FileMaker.php index deecfa7..91aa861 100644 --- a/src/FileMaker.php +++ b/src/FileMaker.php @@ -3,9 +3,9 @@ * FileMaker API for PHP * * @package FileMaker - * + * * @copyright Copyright (c) 2016 by 1-more-thing (http://1-more-thing.com) All rights reserved. - * @licence BSD + * @license BSD */ namespace airmoi\FileMaker; @@ -18,17 +18,17 @@ * and gets information about the API. * * @package FileMaker - * + * * @author Romain Dunand */ -class FileMaker +class FileMaker { private static $_apiVersion = '2.1.0'; private static $_minServerVersion = '10.0.0.0'; /** * * @var array The FileMaker connection properties - * You may access and manipulate thoes properties using + * You may access and manipulate thoes properties using * [[getProperty()]] and [[setPropety()]] methods */ private $_properties = [ @@ -47,14 +47,14 @@ class FileMaker 'emptyAsNull' => false, //Returns null value instead of empty strings on empty field value 'errorHandling' => 'exception', //Default to use old school FileMaker Errors trapping, 'exception' to handle errors as exceptions ]; - + /** * @var \Log PEAR Log object */ private $_logger = null; - + /** - * @var Layout[] a pseudo cache for layouts to prevent unnecessary call's to Custom Web Publishing engine + * @var Layout[] a pseudo cache for layouts to prevent unnecessary call's to Custom Web Publishing engine */ private static $_layouts = []; @@ -169,7 +169,7 @@ public static function getMinServerVersion() * @param string $password Password for account. * @param array $options An array of options. */ - public function __construct($database = NULL, $hostspec = NULL, $username = NULL, $password = NULL, $options = []) + public function __construct($database = null, $hostspec = null, $username = null, $password = null, $options = []) { if (!is_null($hostspec)) { $this->setProperty('hostspec', $hostspec); @@ -183,8 +183,8 @@ public function __construct($database = NULL, $hostspec = NULL, $username = NULL if (!is_null($password)) { $this->setProperty('password', $password); } - - foreach($options as $key => $value) { + + foreach ($options as $key => $value) { $this->setProperty($key, $value); } } @@ -199,9 +199,9 @@ public function __construct($database = NULL, $hostspec = NULL, $username = NULL */ public function setProperty($prop, $value) { - if(!array_key_exists($prop, $this->_properties)) { + if (!array_key_exists($prop, $this->_properties)) { $error = new FileMakerException($this, 'Unsupported property ' . $prop); - if($this->getProperty('errorHandling') === 'default'){ + if ($this->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -249,7 +249,7 @@ public function setLogger($logger) */ if (!is_a($logger, 'Log')) { $error = new FileMakerException($this, 'setLogger() must be passed an instance of PEAR::Log'); - if($this->getProperty('errorHandling') == 'default') { + if ($this->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -326,7 +326,7 @@ public function newDuplicateCommand($layout, $recordId) */ public function newFindCommand($layout) { - return new Command\Find($this,$layout); + return new Command\Find($this, $layout); } /** @@ -413,7 +413,8 @@ public function newPerformScriptCommand($layout, $scriptName, $scriptParameters * @return Object\Record|FileMakerException New Record object or a FileMakerError. * @throws FileMakerException */ - public function createRecord($layoutName, $fieldValues = array()) { + public function createRecord($layoutName, $fieldValues = array()) + { $layout = $this->getLayout($layoutName); $record = new $this->_properties['recordClass']($layout); /* @var $record Object\Record */ @@ -426,7 +427,7 @@ public function createRecord($layoutName, $fieldValues = array()) { } else { $error = $record->setField($fieldName, $fieldValue); } - if(FileMaker::isError($error)){ + if (FileMaker::isError($error)) { return $error; } } @@ -445,18 +446,19 @@ public function createRecord($layoutName, $fieldValues = array()) { * @return Object\Record|FileMakerException * @throws FileMakerException */ - public function getRecordById($layout, $recordId) { + public function getRecordById($layout, $recordId) + { $request = $this->newFindCommand($layout); $request->setRecordId($recordId); $result = $request->execute(); if (FileMaker::isError($result)) { return $request; } - + $record = $result->getRecords(); if (!$record) { $error = new FileMakerException($this, 'Record . ' . $recordId . ' not found in layout "' . $layout . '".'); - if($this->getProperty('errorHandling') == 'default') { + if ($this->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -472,27 +474,28 @@ public function getRecordById($layout, $recordId) { * @return Layout|FileMakerException Layout. * @throws FileMakerException */ - public function getLayout($layoutName) { - if (isset(self::$_layouts[$layoutName]) ) { + public function getLayout($layoutName) + { + if (isset(self::$_layouts[$layoutName])) { return self::$_layouts[$layoutName]; } - + $request = $this->execute(array('-db' => $this->getProperty('database'), '-lay' => $layoutName, '-view' => true)); if (FileMaker::isError($request)) { return $request; } - + $parser = new FMResultSet($this); $result = $parser->parse($request); - if(FileMaker::isError($result)){ + if (FileMaker::isError($result)) { return $result; } $layout = new Layout($this); $result = $parser->setLayout($layout); - if(FileMaker::isError($result)){ + if (FileMaker::isError($result)) { return $result; } @@ -508,12 +511,13 @@ public function getLayout($layoutName) { * @return array|FileMakerException List of database names. * @throws FileMakerException */ - public function listDatabases() { + public function listDatabases() + { $request = $this->execute(array('-dbnames' => true)); if (FileMaker::isError($request)) { return $request; } - + $parser = new FMResultSet($this); $result = $parser->parse($request); @@ -532,16 +536,17 @@ public function listDatabases() { * @return array|FileMakerException List of script names. * @throws FileMakerException */ - public function listScripts() { + public function listScripts() + { $request = $this->execute(array('-db' => $this->getProperty('database'), '-scriptnames' => true)); if (FileMaker::isError($request)) { return $request; } - + $parser = new FMResultSet($this); $result = $parser->parse($request); - if(FileMaker::isError($result)){ + if (FileMaker::isError($result)) { return $result; } @@ -560,16 +565,21 @@ public function listScripts() { * @return array|FileMakerException List of layout names. * @throws FileMakerException */ - public function listLayouts() { - $request = $this->execute(array('-db' => $this->getProperty('database'), - '-layoutnames' => true)); + public function listLayouts() + { + $request = $this->execute( + array( + '-db' => $this->getProperty('database'), + '-layoutnames' => true + ) + ); if (FileMaker::isError($request)) { return $request; } - + $parser = new FMResultSet($this); $result = $parser->parse($request); - if(FileMaker::isError($result)){ + if (FileMaker::isError($result)) { return $result; } @@ -579,13 +589,13 @@ public function listLayouts() { } return $list; } - - function log($message, $level) + + public function log($message, $level) { if ($this->_logger === null) { return; } - + $logLevel = $this->getProperty('logLevel'); if ($logLevel === null || $level > $logLevel) { return; @@ -600,8 +610,8 @@ function log($message, $level) case self::LOG_ERR: $this->_logger->log($message, PEAR_LOG_ERR); break; - } -} + } + } /** * Returns the data for the specified container field. @@ -622,23 +632,24 @@ function log($message, $level) * @return string|FileMakerException Raw field data. * @throws FileMakerException if remote container field or curl not active. */ - public function getContainerData($url) { + public function getContainerData($url) + { if (!function_exists('curl_init')) { $error = new FileMakerException($this, 'cURL is required to use the FileMaker API.'); - if($this->getProperty('errorHandling') == 'default') { + if ($this->getProperty('errorHandling') === 'default') { return $error; } throw $error; } - if (strncasecmp($url, '/fmi/xml/cnt', 11) != 0) { + if (strncasecmp($url, '/fmi/xml/cnt', 11) !== 0) { $error = new FileMakerException($this, 'getContainerData() does not support remote containers'); - if($this->getProperty('errorHandling') == 'default') { + if ($this->getProperty('errorHandling') === 'default') { return $error; } throw $error; } else { $hostspec = $this->getProperty('hostspec'); - if (substr($hostspec, -1, 1) == '/') { + if (substr($hostspec, -1, 1) === '/') { $hostspec = substr($hostspec, 0, -1); } $hostspec .= $url; @@ -650,16 +661,19 @@ public function getContainerData($url) { curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FAILONERROR, true); - $isHeadersSent = FALSE; + $isHeadersSent = false; if (!headers_sent()) { - $isHeadersSent = TRUE; + $isHeadersSent = true; curl_setopt($curl, CURLOPT_HEADER, true); } $this->_setCurlWPCSessionCookie($curl); if ($this->getProperty('username')) { $authString = base64_encode($this->getProperty('username') . ':' . $this->getProperty('password')); - $headers = array('Authorization: Basic ' . $authString, 'X-FMI-PE-ExtendedPrivilege: IrG6U+Rx0F5bLIQCUb9gOw=='); + $headers = array( + 'Authorization: Basic ' . $authString, + 'X-FMI-PE-ExtendedPrivilege: IrG6U+Rx0F5bLIQCUb9gOw==' + ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); } else { curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-FMI-PE-ExtendedPrivilege: IrG6U+Rx0F5bLIQCUb9gOw==')); @@ -676,8 +690,11 @@ public function getContainerData($url) { } $this->log($curlResponse, FileMaker::LOG_DEBUG); if ($curlError = curl_errno($curl)) { - $error = new FileMakerException($this, 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl)); - if($this->getProperty('errorHandling') == 'default') { + $error = new FileMakerException( + $this, + 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl) + ); + if ($this->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -695,47 +712,63 @@ public function getContainerData($url) { * @return string|FileMakerException the cUrl response * @throws FileMakerException */ - public function execute($params, $grammar = 'fmresultset') { + public function execute($params, $grammar = 'fmresultset') + { if (!function_exists('curl_init')) { $error = new FileMakerException($this, 'cURL is required to use the FileMaker API.'); - if($this->getProperty('errorHandling') == 'default') { + if ($this->getProperty('errorHandling') === 'default') { return $error; } throw $error; } - + $RESTparams = array(); foreach ($params as $option => $value) { - if (strtolower($this->getProperty('charset')) != 'utf-8' && $value !== true) { + if (($value !== true) && strtolower($this->getProperty('charset')) !== 'utf-8') { $value = utf8_encode($value); } $RESTparams[] = urlencode($option) . ($value === true ? '' : '=' . urlencode($value)); } - + $host = $this->getProperty('hostspec'); - if (substr($host, -1, 1) != '/') { + if (substr($host, -1, 1) !== '/') { $host .= '/'; } $host .= 'fmi/xml/' . $grammar . '.xml'; $this->log('Request for ' . $host, FileMaker::LOG_INFO); - + $curl = curl_init($host); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FAILONERROR, true); - $curlHeadersSent = FALSE; + $curlHeadersSent = false; if (!headers_sent()) { - $curlHeadersSent = TRUE; + $curlHeadersSent = true; curl_setopt($curl, CURLOPT_HEADER, true); } $this->_setCurlWPCSessionCookie($curl); if ($this->getProperty('username')) { - $auth = base64_encode(utf8_decode($this->getProperty('username')) . ':' . utf8_decode($this->getProperty('password'))); + $auth = base64_encode( + utf8_decode($this->getProperty('username')) . ':' . utf8_decode($this->getProperty('password')) + ); $authHeader = 'Authorization: Basic ' . $auth; - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=utf-8', 'X-FMI-PE-ExtendedPrivilege: IrG6U+Rx0F5bLIQCUb9gOw==', $authHeader)); + curl_setopt( + $curl, + CURLOPT_HTTPHEADER, + array( + 'Content-Type: application/x-www-form-urlencoded; charset=utf-8', 'X-FMI-PE-ExtendedPrivilege: IrG6U+Rx0F5bLIQCUb9gOw==', + $authHeader + ) + ); } else { - curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=utf-8', 'X-FMI-PE-ExtendedPrivilege: IrG6U+Rx0F5bLIQCUb9gOw==')); + curl_setopt( + $curl, + CURLOPT_HTTPHEADER, + array( + 'Content-Type: application/x-www-form-urlencoded; charset=utf-8', 'X-FMI-PE-ExtendedPrivilege: IrG6U+Rx0F5bLIQCUb9gOw==' + ) + ); } curl_setopt($curl, CURLOPT_POSTFIELDS, implode('&', $RESTparams)); @@ -746,24 +779,42 @@ public function execute($params, $grammar = 'fmresultset') { } $this->lastRequestedUrl = $host . '?' . implode('&', $RESTparams); $this->log($this->lastRequestedUrl, FileMaker::LOG_DEBUG); - + $curlResponse = curl_exec($curl); $this->log($curlResponse, FileMaker::LOG_DEBUG); if ($curlError = curl_errno($curl)) { - - if ($curlError == 52) { - $error = new FileMakerException( $this, 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl) . ' - The Web Publishing Core and/or FileMaker Server services are not running.', $curlError); - - } else if ($curlError == 22) { + if ($curlError === 52) { + $error = new FileMakerException( + $this, + 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl) + . ' - The Web Publishing Core and/or FileMaker Server services are not running.', + $curlError + ); + } elseif ($curlError === 22) { if (stristr("50", curl_error($curl))) { - $error = new FileMakerException( $this, 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl) . ' - The Web Publishing Core and/or FileMaker Server services are not running.', $curlError); + $error = new FileMakerException( + $this, + 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl) + . ' - The Web Publishing Core and/or FileMaker Server services are not running.', + $curlError + ); } else { - $error = new FileMakerException( $this, 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl) . ' - This can be due to an invalid username or password, or if the FMPHP privilege is not enabled for that user.', $curlError); + $error = new FileMakerException( + $this, + 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl) + . ' - This can be due to an invalid username or password, or if the FMPHP privilege is not ' + . 'enabled for that user.', + $curlError + ); } } else { - $error = new FileMakerException( $this, 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl), $curlError); + $error = new FileMakerException( + $this, + 'cURL Communication Error: (' . $curlError . ') ' . curl_error($curl), + $curlError + ); } - if($this->getProperty('errorHandling') == 'default') { + if ($this->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -790,12 +841,13 @@ public function execute($params, $grammar = 'fmresultset') { * * @return string Fully qualified URL to container field contents */ - public function getContainerDataURL($url) { - if (strncasecmp($url, '/fmi/xml/cnt', 11) != 0) { + public function getContainerDataURL($url) + { + if (strncasecmp($url, '/fmi/xml/cnt', 11) !== 0) { $decodedUrl = htmlspecialchars_decode($url); } else { $decodedUrl = $this->getProperty('hostspec'); - if (substr($decodedUrl, -1, 1) == '/') { + if (substr($decodedUrl, -1, 1) === '/') { $decodedUrl = substr($decodedUrl, 0, -1); } $decodedUrl .= $url; @@ -808,8 +860,9 @@ public function getContainerDataURL($url) { * Set curl Sesion cookie * @param Resource $curl a cUrl handle ressource */ - private function _setCurlWPCSessionCookie($curl) { - if(!$this->getProperty('useCookieSession')) { + private function _setCurlWPCSessionCookie($curl) + { + if (!$this->getProperty('useCookieSession')) { return; } if (isset($_COOKIE["WPCSessionID"])) { @@ -825,13 +878,14 @@ private function _setCurlWPCSessionCookie($curl) { * Pass WPC session cookie to client for later auth * @param string $curlResponse a curl response */ - private function _setClientWPCSessionCookie($curlResponse) { - if(!$this->getProperty('useCookieSession')) { + private function _setClientWPCSessionCookie($curlResponse) + { + if (!$this->getProperty('useCookieSession')) { return; } $found = preg_match('/WPCSessionID="([^;]*)";/m', $curlResponse, $matches); /* Update WPCSession Cookie if needed */ - if ($found && @$_COOKIE['WPCSessionID'] != $matches[1]) { + if ($found && @$_COOKIE['WPCSessionID'] !== $matches[1]) { setcookie("WPCSessionID", $matches[1]); $_COOKIE['WPCSessionID'] = $matches[1]; } @@ -842,7 +896,8 @@ private function _setClientWPCSessionCookie($curlResponse) { * @param string $curlResponse a curl response * @return int content length, -1 if not provided by headers */ - private function _getContentLength($curlResponse) { + private function _getContentLength($curlResponse) + { $found = preg_match('/Content-Length: (\d+)/', $curlResponse, $matches); if ($found) { return $matches[1]; @@ -856,7 +911,8 @@ private function _getContentLength($curlResponse) { * @param string $curlResponse a curl response * @return string curlResponse without xml header */ - private function _eliminateXMLHeader($curlResponse) { + private function _eliminateXMLHeader($curlResponse) + { $isXml = strpos($curlResponse, "_properties)) { $this->_properties[$name] = $value; } else { @@ -901,8 +959,9 @@ public function __set($name, $value) { * @param array|string $value * @return array|string */ - public function toOutputCharset($value) { - if (strtolower($this->getProperty('charset')) != 'iso-8859-1') { + public function toOutputCharset($value) + { + if (strtolower($this->getProperty('charset')) !== 'iso-8859-1') { return $value; } if (is_array($value)) { @@ -922,26 +981,29 @@ public function toOutputCharset($value) { * Returns the last URL call to xml engine * @return string */ - public function getLastRequestedUrl(){ + public function getLastRequestedUrl() + { return $this->lastRequestedUrl; } - public function dateConvertInput($value) { - if($this->getProperty('dateFormat') === null){ + public function dateConvertInput($value) + { + if ($this->getProperty('dateFormat') === null) { return $value; } try { $date = \DateTime::createFromFormat($this->getProperty('dateFormat'), $value); return $date->format('m/d/Y'); - } catch (\Exception $e) { + } catch (\Exception $e) { $this->log('Could not convert string to a valid DateTime : ' . $e->getMessage(), FileMaker::LOG_ERR); return $value; } } - public function dateConvertOutput($value) { - if($this->getProperty('dateFormat') === null){ + public function dateConvertOutput($value) + { + if ($this->getProperty('dateFormat') === null) { return $value; } try { @@ -952,5 +1014,4 @@ public function dateConvertOutput($value) { return $value; } } - } diff --git a/src/FileMakerException.php b/src/FileMakerException.php index b7bdaf2..c18dbc6 100644 --- a/src/FileMakerException.php +++ b/src/FileMakerException.php @@ -1,11 +1,10 @@ _fm = $fm; - if ( $code !== null) + if ($code !== null) { $message = $this->getErrorString($code); - + } + parent::__construct($message, $code, $previous); } - + /** - * Returns the string representation of $this->code in the language - * currently set for PHP error messages in FileMaker Server Admin + * Returns the string representation of $this->code in the language + * currently set for PHP error messages in FileMaker Server Admin * Console. - * + * * You should call getMessage() in most cases, if you are not sure whether * the error is a FileMaker Web Publishing Engine error with an error code. * @@ -78,15 +78,14 @@ public function getErrorString($code) } /** - * Indicates whether the error is a detailed pre-validation error + * Indicates whether the error is a detailed pre-validation error * or a FileMaker Web Publishing Engine error. * - * @return boolean FALSE, to indicate that this is an error from the + * @return boolean FALSE, to indicate that this is an error from the * Web Publishing Engine. */ public function isValidationError() { return false; } - } diff --git a/src/FileMakerValidationException.php b/src/FileMakerValidationException.php index 75df001..764ad36 100644 --- a/src/FileMakerValidationException.php +++ b/src/FileMakerValidationException.php @@ -1,7 +1,7 @@ message = implode("\n", $messages); } - - private static function getValidationErrorString(Field $field, $rule, $value) { + + private static function getValidationErrorString(Field $field, $rule, $value) + { switch ($rule) { case FileMaker::RULE_FOURDIGITYEAR: $message = 'Please enter a four digit number for the year in field %1$s'; break; - case FileMaker::RULE_DATE_FIELD : + case FileMaker::RULE_DATE_FIELD: $message = 'Please enter a valid date for field %1$s'; break; - case FileMaker::RULE_MAXCHARACTERS : + case FileMaker::RULE_MAXCHARACTERS: $message = 'Value in field %1$s exceeds maximum number of allowed characters (%2$d)'; break; - case FileMaker::RULE_NOTEMPTY : + case FileMaker::RULE_NOTEMPTY: $message = 'Field %1$s is required'; break; case FileMaker::RULE_NUMERICONLY: @@ -67,7 +68,7 @@ private static function getValidationErrorString(Field $field, $rule, $value) { default: $message = 'Incorrect value for field %1$s (%3$s)'; } - + return sprintf($message, $field->getName(), $field->maxCharacters, $value); } diff --git a/src/Object/Field.php b/src/Object/Field.php index 0e888a1..d659c3e 100644 --- a/src/Object/Field.php +++ b/src/Object/Field.php @@ -1,7 +1,7 @@ layout = $layout; } @@ -61,7 +61,7 @@ public function getLayout() } /** - * Returns TRUE if data in this field is auto-entered or FALSE + * Returns TRUE if data in this field is auto-entered or FALSE * if it is entered manually. * * @return boolean Auto-entered status of this field. @@ -105,7 +105,7 @@ public function validate($value) { $isValid = false; $validationError = new FileMakerValidationException($this->layout->fm); - + foreach ($this->getValidationRules() as $rule) { switch ($rule) { case FileMaker::RULE_NOTEMPTY: @@ -113,14 +113,14 @@ public function validate($value) $validationError->addError($this, $rule, $value); } break; - case FileMaker::RULE_NUMERICONLY : + case FileMaker::RULE_NUMERICONLY: if (!empty($value)) { if ($this->checkNumericOnly($value)) { $validationError->addError($this, $rule, $value); } } break; - case FileMaker::RULE_MAXCHARACTERS : + case FileMaker::RULE_MAXCHARACTERS: if (!empty($value)) { $strlen = strlen($value); if ($strlen > $this->maxCharacters) { @@ -128,67 +128,70 @@ public function validate($value) } } break; - case FileMaker::RULE_TIMEOFDAY : - case FileMaker::RULE_TIME_FIELD : + case FileMaker::RULE_TIMEOFDAY: + case FileMaker::RULE_TIME_FIELD: if (!empty($value)) { if (!$this->checkTimeFormat($value)) { - $validationError->addError($this, $rule, $value); } else { - $this->checkTimeValidity($value, $rule, $validationError, FALSE); + $this->checkTimeValidity($value, $rule, $validationError, false); } } break; - case FileMaker::RULE_TIMESTAMP_FIELD : + case FileMaker::RULE_TIMESTAMP_FIELD: if (!empty($value)) { if (!$this->checkTimeStampFormat($value)) { - $validationError->addError($this, $rule, $value); } else { $this->checkDateValidity($value, $rule, $validationError); - $this->checkTimeValidity($value, $rule, $validationError, FALSE); + $this->checkTimeValidity($value, $rule, $validationError, false); } } break; - case FileMaker::RULE_DATE_FIELD : + case FileMaker::RULE_DATE_FIELD: if (!empty($value)) { if (!$this->checkDateFormat($value)) { - $validationError->addError($this, $rule, $value); } else { $this->checkDateValidity($value, $rule, $validationError); } } break; - case FileMaker::RULE_FOURDIGITYEAR : + case FileMaker::RULE_FOURDIGITYEAR: if (!empty($value)) { switch ($this->result) { - case 'timestamp' : + case 'timestamp': if ($this->checkTimeStampFormatFourDigitYear($value)) { - preg_match('#^([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})[-,/,\\\\]([0-9]{4})#', $value, $matches); + preg_match( + '#^([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})[-,/,\\\\]([0-9]{4})#', + $value, + $matches + ); $month = $matches[1]; $day = $matches[2]; $year = $matches[3]; if ($year < 1 || $year > 4000) { $validationError->addError($this, $rule, $value); - } else - if (!checkdate($month, $day, $year)) { + } elseif (!checkdate($month, $day, $year)) { $validationError->addError($this, $rule, $value); } else { - $this->checkTimeValidity($value, $rule, $validationError, FALSE); + $this->checkTimeValidity($value, $rule, $validationError, false); } } else { - $validationError->addError($this, $rule, $value); } break; - default : - preg_match('#([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})[-,/,\\\\]([0-9]{1,4})#', $value, $matches); - if (count($matches) != 3) { + default: + preg_match( + '#([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})[-,/,\\\\]([0-9]{1,4})#', + $value, + $matches + ); + if (count($matches) !== 3) { $validationError->addError($this, $rule, $value); } else { $strlen = strlen($matches[2]); - if ($strlen != 4) { + if ($strlen !== 4) { $validationError->addError($this, $rule, $value); } else { if ($matches[2] < 1 || $matches[2] > 4000) { @@ -214,41 +217,41 @@ public function validate($value) } /** - * Returns an array of FileMaker::RULE_* constants for each rule - * set on this field that can be evaluated by the PHP engine. - * - * Rules such as "unique" and "exists" can only be pre-validated on the + * Returns an array of FileMaker::RULE_* constants for each rule + * set on this field that can be evaluated by the PHP engine. + * + * Rules such as "unique" and "exists" can only be pre-validated on the * Database Server and are not included in this list. * * @return array Local rule array. */ public function getLocalValidationRules() { - $rules = array(); + $rules = array(); foreach (array_keys($this->validationRules) as $rule) { switch ($rule) { - case FileMaker::RULE_NOTEMPTY : + case FileMaker::RULE_NOTEMPTY: $rules[] = $rule; break; - case FileMaker::RULE_NUMERICONLY : + case FileMaker::RULE_NUMERICONLY: $rules[] = $rule; break; - case FileMaker::RULE_MAXCHARACTERS : + case FileMaker::RULE_MAXCHARACTERS: $rules[] = $rule; break; - case FileMaker::RULE_FOURDIGITYEAR : + case FileMaker::RULE_FOURDIGITYEAR: $rules[] = $rule; break; - case FileMaker::RULE_TIMEOFDAY : + case FileMaker::RULE_TIMEOFDAY: $rules[] = $rule; break; - case FileMaker::RULE_TIMESTAMP_FIELD : + case FileMaker::RULE_TIMESTAMP_FIELD: $rules[] = $rule; break; - case FileMaker::RULE_DATE_FIELD : + case FileMaker::RULE_DATE_FIELD: $rules[] = $rule; break; - case FileMaker::RULE_TIME_FIELD : + case FileMaker::RULE_TIME_FIELD: $rules[] = $rule; break; } @@ -265,9 +268,9 @@ public function getMaxCharacters() { return $this->maxCharacters; } - + /** - * Returns an array of FileMaker::RULE_* constants for each rule + * Returns an array of FileMaker::RULE_* constants for each rule * set on this field. * * @return array Rule array. @@ -302,15 +305,15 @@ public function hasValidationRule($validationRule) } /** - * Returns any additional information for the specified pre-validation - * rule. + * Returns any additional information for the specified pre-validation + * rule. * - * Used for range rules and other rules that have additional + * Used for range rules and other rules that have additional * pre-validation parameters. * - * @param integer $validationRule FileMaker::RULE_* constant - * to get information for. - * + * @param integer $validationRule FileMaker::RULE_* constant + * to get information for. + * * @return array Any extra information for $validationRule. */ public function describeValidationRule($validationRule) @@ -322,17 +325,17 @@ public function describeValidationRule($validationRule) } /** - * Return an array of arrays containing the extra information for - * all pre-validation rules on this field that can be evaluated by the - * PHP engine. - * - * Rules such as "unique" and "exists" can be validated only - * on the Database Server and are not included in this list. - * Indexes of the outer array are FileMaker::RULE_* constants, + * Return an array of arrays containing the extra information for + * all pre-validation rules on this field that can be evaluated by the + * PHP engine. + * + * Rules such as "unique" and "exists" can be validated only + * on the Database Server and are not included in this list. + * Indexes of the outer array are FileMaker::RULE_* constants, * and values are the same array returned by describeValidationRule(). * - * @return array An associative array of all extra pre-validation - * information, with rule constants as indexes and extra + * @return array An associative array of all extra pre-validation + * information, with rule constants as indexes and extra * information as the values. */ public function describeLocalValidationRules() @@ -340,28 +343,28 @@ public function describeLocalValidationRules() $rules = array(); foreach ($this->validationRules as $rule => $description) { switch ($rule) { - case FileMaker::RULE_NOTEMPTY : + case FileMaker::RULE_NOTEMPTY: $rules[$rule] = $description; break; - case FileMaker::RULE_NUMERICONLY : + case FileMaker::RULE_NUMERICONLY: $rules[$rule] = $description; break; - case FileMaker::RULE_MAXCHARACTERS : + case FileMaker::RULE_MAXCHARACTERS: $rules[$rule] = $description; break; - case FileMaker::RULE_FOURDIGITYEAR : + case FileMaker::RULE_FOURDIGITYEAR: $rules[$rule] = $description; break; - case FileMaker::RULE_TIMEOFDAY : + case FileMaker::RULE_TIMEOFDAY: $rules[$rule] = $description; break; - case FileMaker::RULE_TIMESTAMP_FIELD : + case FileMaker::RULE_TIMESTAMP_FIELD: $rules[$rule] = $description; break; - case FileMaker::RULE_DATE_FIELD : + case FileMaker::RULE_DATE_FIELD: $rules[$rule] = $description; break; - case FileMaker::RULE_TIME_FIELD : + case FileMaker::RULE_TIME_FIELD: $rules[$rule] = $description; break; } @@ -372,8 +375,8 @@ public function describeLocalValidationRules() /** * Returns any additional information for all pre-validation rules. * - * @return array An associative array of all extra pre-validation - * information, with FileMaker::RULE_* constants + * @return array An associative array of all extra pre-validation + * information, with FileMaker::RULE_* constants * as keys and extra information as the values. */ public function describeValidationRules() @@ -404,10 +407,10 @@ public function getType() } /** - * Returns the list of choices from the value list associated with this - * field. + * Returns the list of choices from the value list associated with this + * field. * - * If this field is not associated with a value list, this method returns + * If this field is not associated with a value list, this method returns * NULL. * * @param string $listName Name of the value list. @@ -421,7 +424,7 @@ public function getValueList($listName = null) } /** - * Returns the control style type of this field -- for example, + * Returns the control style type of this field -- for example, * 'EDITTEXT', 'POPUPLIST', 'POPUPMENU', 'CHECKBOX', 'RADIOBUTTONS' or * 'CALENDAR'. * @@ -433,28 +436,40 @@ public function getStyleType() $extendedInfos = $this->layout->loadExtendedInfo(); return $this->styleType; } - - public function checkTimeStampFormatFourDigitYear($value) { - return (preg_match('#^[ ]*([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})[-,/,\\\\]([0-9]{4})[ ]*([0-9]{1,2})[:]([0-9]{1,2})([:][0-9]{1,2})?([ ]*((AM|PM)|(am|pm)))?[ ]*$#', $value)); + + public function checkTimeStampFormatFourDigitYear($value) + { + return preg_match( + '#^[ ]*([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})[-,/,\\\\]([0-9]{4})[ ]*([0-9]{1,2})[:]([0-9]{1,2})([:][0-9]{1,2})?([ ]*((AM|PM)|(am|pm)))?[ ]*$#', + $value + ); } - public function checkTimeStampFormat($value) { - return (preg_match('#^[ ]*([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})([-,/,\\\\]([0-9]{1,4}))?[ ]*([0-9]{1,2})[:]([0-9]{1,2})([:][0-9]{1,2})?([ ]*((AM|PM)|(am|pm)))?[ ]*$#', $value)); + public function checkTimeStampFormat($value) + { + return preg_match( + '#^[ ]*([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})([-,/,\\\\]([0-9]{1,4}))?[ ]*([0-9]{1,2})[:]([0-9]{1,2})([:][0-9]{1,2})?([ ]*((AM|PM)|(am|pm)))?[ ]*$#', + $value + ); } - public function checkDateFormat($value) { - return (preg_match('#^[ ]*([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})([-,/,\\\\]([0-9]{1,4}))?[ ]*$#', $value)); + public function checkDateFormat($value) + { + return preg_match('#^[ ]*([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})([-,/,\\\\]([0-9]{1,4}))?[ ]*$#', $value); } - public function checkTimeFormat($value) { - return (preg_match('#^[ ]*([0-9]{1,2})[:]([0-9]{1,2})([:][0-9]{1,2})?([ ]*((AM|PM)|(am|pm)))?[ ]*$#', $value)); + public function checkTimeFormat($value) + { + return preg_match('#^[ ]*([0-9]{1,2})[:]([0-9]{1,2})([:][0-9]{1,2})?([ ]*((AM|PM)|(am|pm)))?[ ]*$#', $value); } - public function checkNumericOnly($value) { + public function checkNumericOnly($value) + { return (!is_numeric($value)); } - public function checkDateValidity($value, $rule, FileMakerValidationException $validationError) { + public function checkDateValidity($value, $rule, FileMakerValidationException $validationError) + { preg_match('#([0-9]{1,2})[-,/,\\\\]([0-9]{1,2})([-,/,\\\\]([0-9]{1,4}))?#', $value, $matches); if ($matches[4]) { $strlen = strlen($matches[4]); @@ -477,7 +492,8 @@ public function checkDateValidity($value, $rule, FileMakerValidationException $v } } - public function checkTimeValidity($value, $rule, FileMakerValidationException $validationError, $shortHoursFormat) { + public function checkTimeValidity($value, $rule, FileMakerValidationException $validationError, $shortHoursFormat) + { if ($shortHoursFormat) { $format = 12; } else { @@ -491,13 +507,12 @@ public function checkTimeValidity($value, $rule, FileMakerValidationException $v } if ($hours < 0 || $hours > $format) { $validationError->addError($this, $rule, $value); - } else if ($minutes < 0 || $minutes > 59) { + } elseif ($minutes < 0 || $minutes > 59) { $validationError->addError($this, $rule, $value); - } else - if (isset($seconds)) { - if ($seconds < 0 || $seconds > 59) + } elseif (isset($seconds)) { + if ($seconds < 0 || $seconds > 59) { $validationError->addError($this, $rule, $value); + } } } - } diff --git a/src/Object/Layout.php b/src/Object/Layout.php index 1a3b824..e4e5023 100644 --- a/src/Object/Layout.php +++ b/src/Object/Layout.php @@ -1,7 +1,7 @@ fields[$fieldName])) { return $this->fields[$fieldName]; } - if( $pos = strpos($fieldName, ':')){ + if ($pos = strpos($fieldName, ':')) { $relatedSet = substr($fieldName, 0, $pos); //$fieldName = substr($fieldName, $pos+1, strlen($fieldName)); return $this->getRelatedSet($relatedSet)->getField($fieldName); } $error = new FileMakerException($this->fm, 'Field "'.$fieldName.'" Not Found'); - if($this->fm->getProperty('errorHandling') == 'default') { + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -121,7 +121,7 @@ public function listRelatedSets() } /** - * Returns a RelatedSet object that describes the specified + * Returns a RelatedSet object that describes the specified * portal. * * @param string|FileMakerException $relatedSet Name of the related table for a portal. @@ -131,27 +131,28 @@ public function listRelatedSets() */ public function getRelatedSet($relatedSet) { - if (isset($this->relatedSets[$relatedSet])) { + if (isset($this->relatedSets[$relatedSet])) { return $this->relatedSets[$relatedSet]; } $error = new FileMakerException($this->fm, 'RelatedSet "'.$relatedSet.'" Not Found in layout '. $this->getName()); - if($this->fm->getProperty('errorHandling') == 'default') { + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } - + /** * Check wether a portal based on the given table occurrence exists * @param string $relatedSet Table occurrence name to test * @return bool true if related set exist */ - public function hasRelatedSet($relatedSet) { + public function hasRelatedSet($relatedSet) + { return isset($this->relatedSets[$relatedSet]); } /** - * Returns an associative array with the related table names of all + * Returns an associative array with the related table names of all * portals as keys and RelatedSet objects as the array values. * * @return RelatedSet[] Array of {@link RelatedSet} objects. @@ -174,9 +175,10 @@ public function listValueLists() if (FileMaker::isError($ExtendedInfos)) { return $ExtendedInfos; } - if($this->valueLists !== null) + if ($this->valueLists !== null) { return array_keys($this->valueLists); - + } + return []; } @@ -184,7 +186,7 @@ public function listValueLists() * Returns the list of defined values in the specified value list. * * @param string $listName Name of value list. - * @param string $recid Record from which the value list should be + * @param string $recid Record from which the value list should be * displayed. * * @return array|FileMakerException List of defined values. @@ -204,14 +206,14 @@ public function getValueList($listName, $recid = null) $this->valueLists[$listName] : null; } - + /** - * Returns the list of defined values in the specified value list. - * This method supports single, 2nd only, and both fields value lists. + * Returns the list of defined values in the specified value list. + * This method supports single, 2nd only, and both fields value lists. * * @param string $valueList Name of value list. - * @param string $recid Record from which the value list should be + * @param string $recid Record from which the value list should be * displayed. * * @return array|FileMakerException of display names and its corresponding value from the value list @@ -226,18 +228,17 @@ public function getValueListTwoFields($valueList, $recid = null) } return isset($this->valueLists[$valueList]) ? $this->valueListTwoFields[$valueList] : []; - } /** - * Returns a multi-level associative array of value lists. - * The top-level array has names of value lists as keys and arrays as - * values. The second level arrays are the lists of defined values from + * Returns a multi-level associative array of value lists. + * The top-level array has names of value lists as keys and arrays as + * values. The second level arrays are the lists of defined values from * each value list. * - * @param string $recid Record from which the value list should be + * @param string $recid Record from which the value list should be * displayed. - * + * * @return array|FileMakerException Array of value-list arrays. * @throws FileMakerException * @deprecated Use getValueListTwoFields instead. @@ -253,15 +254,15 @@ public function getValueLists($recid = null) } /** - * Returns a multi-level associative array of value lists. - * The top-level array has names of value lists as keys and associative arrays as - * values. The second level associative arrays are lists of display name and its corresponding + * Returns a multi-level associative array of value lists. + * The top-level array has names of value lists as keys and associative arrays as + * values. The second level associative arrays are lists of display name and its corresponding * value from the value list. * - * @param string|FileMakerException $recid Record from which the value list should be + * @param string|FileMakerException $recid Record from which the value list should be * displayed. * @throws FileMakerException - * + * * @return array Array of value-list associative arrays. */ public function getValueListsTwoFields($recid = null) @@ -278,7 +279,7 @@ public function getValueListsTwoFields($recid = null) * * @access private * - * @param string $recid Record from which to load extended information. + * @param string $recid Record from which to load extended information. * * @return boolean TRUE, if successful. * @throws FileMakerException; @@ -286,7 +287,6 @@ public function getValueListsTwoFields($recid = null) public function loadExtendedInfo($recid = null) { if (!$this->extended || $recid != null) { - if ($recid != null) { $result = $this->fm->execute(array('-db' => $this->fm->getProperty('database'), '-lay' => $this->getName(), @@ -302,7 +302,7 @@ public function loadExtendedInfo($recid = null) if (FileMaker::isError($parseResult)) { return $parseResult; } - + $parser->setExtendedInfo($this); $this->extended = true; } diff --git a/src/Object/Record.php b/src/Object/Record.php index ef246a3..3afe1b4 100644 --- a/src/Object/Record.php +++ b/src/Object/Record.php @@ -1,663 +1,701 @@ -layout = $layout; - $this->fm = $layout->fm; - } - - /** - * Returns the layout this record is associated with. - * - * @return Layout This record's layout. - */ - public function getLayout() { - return $this->layout; - } - - /** - * Returns a list of the names of all fields in the record. - * - * Only the field names are returned. If you need additional - * information, examine the Layout object provided by the - * parent object's {@link Result::getLayout()} method. - * - * @return array List of field names as strings. - */ - public function getFields() { - return $this->layout->listFields(); - } - - /** - * Returns the HTML-encoded value of the specified field. - * - * This method converts some special characters in the field value to - * HTML entities. For example, '&', '"', '<', and '>' are converted to - * '&', '"', '<', and '>', respectively. - * - * @param string $field Name of field. - * @param integer $repetition Field repetition number to get. - * Defaults to the first repetition. - * @param boolean $unencoded - * - * @return null|string|FileMakerException Encoded field value. - * @throws FileMakerException - */ - public function getField($field, $repetition = 0, $unencoded = false) { - if( !is_null($this->parent) && !strpos($field, '::')){ - $field = $this->relatedSetName. '::' . $field; - } - if (!isset($this->fields[$field])) { - $this->fm->log('Field "' . $field . '" not found.', FileMaker::LOG_INFO); - return null; - } - if (!isset($this->fields[$field][$repetition])) { - $this->fm->log('Repetition "' . (int) $repetition . '" does not exist for "' . $field . '".', FileMaker::LOG_INFO); - return null; - } - $format = $this->layout->getField($field)->result; - $value = $this->fields[$field][$repetition]; - - if(empty($value) && $this->fm->getProperty('emptyAsNull')) { - return null; - } - if( !empty($value) && preg_match('/\d{2}.\d{2}.\d{4}/', $value) && $this->fm->getProperty('dateFormat') !== null && ($format == 'date' || $format == 'timestamp')){ - if( $format == 'date' ){ - if(!$dateTime = \DateTime::createFromFormat('m/d/Y H:i:s', $value . ' 00:00:00')) { - $error = new FileMakerException($this->fm, $field . ' could not be converted to a valid timestamp ('. $value .')'); - if($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - return $dateTime->format($this->fm->getProperty('dateFormat')); - } else { - if(!$dateTime = \DateTime::createFromFormat('m/d/Y H:i:s', $value )){ - $error = new FileMakerException($this->fm, $field . ' could not be converted to a valid timestamp ('. $value .')'); - if($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - return $dateTime->format($this->fm->getProperty('dateFormat') . ' H:i:s' ); - } - } - elseif(!empty($value) && $format == 'number'){ - $value = preg_replace('/,/', '.', $value); - } - return $unencoded ? $value : htmlspecialchars($value); - } - - /** - * Returns the two field value list associated with the given field in Record's layout. - * - * @param string $fieldName Field's Name - * @return array|\airmoi\FileMaker\FileMakerException - * @see Layout::getValueListTwoFields - */ - public function getFieldValueListTwoFields($fieldName) { - if( !is_null($this->parent) && !strpos($fieldName, '::')){ - $fieldName = $this->relatedSetName. '::' . $fieldName; - } - if (!isset($this->fields[$fieldName])) { - $this->fm->log('Field "' . $fieldName . '" not found.', FileMaker::LOG_INFO); - return []; - } - - //Force load extendedInfos as Field's valueList property is not set until extended infos are retrieved - $ExtendedInfos = $this->layout->loadExtendedInfo($this->recordId); - if (FileMaker::isError($ExtendedInfos)) { - return $ExtendedInfos; - } - - $field = $this->layout->getField($fieldName); - if (FileMaker::isError($field)) { - return []; - } - //Get the value list if field has one - if($field->valueList !== null){ - return $this->layout->getValueListTwoFields($this->layout->fields[$fieldName]->valueList, $this->recordId ); - } - return []; - } - - /** - * Returns the unencoded value of the specified field. - * - * This method does not convert special characters in the field value to - * HTML entities. - * @deprecated since version 2.0 use getField($field, $repetition = 0, $unencoded = true) instead - * @param string $field Name of field. - * @param integer $repetition Field repetition number to get. - * Defaults to the first repetition. - * - * @return string Unencoded field value. - */ - public function getFieldUnencoded($field, $repetition = 0) { - return $this->getField($field, $repetition, true); - } - - /** - * Returns the value of the specified field as a UNIX - * timestamp. - * - * If the field is a date field, the timestamp is - * for the field date at midnight. It the field is a time field, - * the timestamp is for that time on January 1, 1970. Timestamp - * (date and time) fields map directly to the UNIX timestamp. If the - * specified field is not a date or time field, or if the timestamp - * generated would be out of range, then this method throws a - * FileMakerException object instead. - * - * @param string $field Name of the field. - * @param integer $repetition Field repetition number to get. - * Defaults to the first repetition. - * @return FileMakerException|int Timestamp value. - * @throws FileMakerException - * @throws null - */ - public function getFieldAsTimestamp($field, $repetition = 0) { - $value = $this->getField($field, $repetition); - $fieldType = $this->layout->getField($field); - $error = null; - $dateFormat = $this->fm->getProperty('dateFormat') !== null ? $this->fm->getProperty('dateFormat') : "m/d/Y"; - switch ($fieldType->getResult()) { - case 'date': - - if(!$dateTime = \DateTime::createFromFormat( $dateFormat . ' H:i:s', $value . ' 00:00:00' )) { - $error = new FileMakerException($this->fm, 'Failed to parse "' . $value . '" as a FileMaker date value.'); - } - break; - case 'time': - if(!$dateTime = \DateTime::createFromFormat( 'Y-m-d H:i:s', '1970-01-01' . $value )) { - $error = new FileMakerException($this->fm, 'Failed to parse "' . $value . '" as a FileMaker date value.'); - } - break; - case 'timestamp': - if(!$dateTime = \DateTime::createFromFormat( $dateFormat . ' H:i:s', '1970-01-01' . $value )) { - $error = new FileMakerException($this->fm, 'Failed to parse "' . $value . '" as a FileMaker date value.'); - } - break; - default: - $error = new FileMakerException($this->fm, 'Only time, date, and timestamp fields can be converted to UNIX timestamps.'); - break; - } - if($error !== null && $this->fm->getProperty('errorHandling') == 'default') { - return $error; - } elseif ( $error !== null ) { - throw $error; - } - return $dateTime->format("U"); - } - - /** - * Sets the value of $field. - * - * @param string $field Name of the field. - * @param string $value New value of the field. - * @param integer $repetition Field repetition number to set. - * Defaults to the first repetition. - * - * @return string|FileMakerException - * @throws FileMakerException - */ - public function setField($field, $value, $repetition = 0) { - - if( !is_null($this->parent) && !strpos($field, '::')){ - $field = $this->relatedSetName. '::' . $field; - } - if ( !array_key_exists($field, $this->layout->fields)) { - $error = new FileMakerException($this->fm, 'Field "'.$field.'" is missing'); - if($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - - $format = $this->layout->getField($field)->result; - if( !empty($value) && $this->fm->getProperty('dateFormat') !== null && ($format == 'date' || $format == 'timestamp')){ - if( $format == 'date' ){ - if(!$dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value . ' 00:00:00', new \DateTimeZone(date_default_timezone_get()))) { - $error = new FileMakerException($this->fm, $value . ' could not be converted to a valid timestamp for field ' . $field . ' (expected format '. $this->fm->getProperty('dateFormat') .')'); - if($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - $value = $dateTime->format('m/d/Y'); - } else { - if(!$dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value, new \DateTimeZone(date_default_timezone_get()))) { - $error = new FileMakerException($this->fm, $value . ' could not be converted to a valid timestamp for field ' . $field . ' (expected format '. $this->fm->getProperty('dateFormat') .')'); - if($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - $value = $dateTime->format( 'm/d/Y H:i:s' ); - } - } - - $this->fields[$field][$repetition] = $value; - $this->_modifiedFields[$field][$repetition] = true; - return $value; - } - - /** - * Sets the new value for a date, time, or timestamp field from a - * UNIX timestamp value. - * - * If the field is not a date or time field, then returns an error. - * Otherwise, returns TRUE. - * - * If layout data for the target of this command has not already - * been loaded, calling this method loads layout data so that - * the type of the field can be checked. - * - * @todo use DateTime instead of date() to handle pre-epoch timestamps - * - * @param string $field Name of the field to set. - * @param string $timestamp Timestamp value. - * @param integer $repetition Field repetition number to set. - * Defaults to the first repetition. - * - * @return string - * @throws FileMakerException - */ - public function setFieldFromTimestamp($field, $timestamp, $repetition = 0) { - $fieldType = $this->layout->getField($field); - if (FileMaker::isError($fieldType)) { - return $fieldType; - } - switch ($fieldType->getResult()) { - case 'date': - return $this->setField($field, date('m/d/Y', $timestamp), $repetition); - case 'time': - return $this->setField($field, date('H:i:s', $timestamp), $repetition); - case 'timestamp': - return $this->setField($field, date('m/d/Y H:i:s', $timestamp), $repetition); - } - $error = new FileMakerException($this->fm, 'Only time, date, and timestamp fields can be set to the value of a timestamp.'); - if($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - - /** - * Returns the record ID of this object. - * - * @return string Record ID. - */ - public function getRecordId() { - return $this->recordId; - } - - /** - * Returns the modification ID of this record. - * - * The modification ID is an incremental counter that specifies the current - * version of a record. See the {@link Edit::setModificationId()} - * method. - * - * @return integer Modification ID. - */ - public function getModificationId() { - return $this->modificationId; - } - - /** - * Returns any Record objects in the specified portal or throw a FileMakerException - * object if there are no related records - * - * @param string $relatedSet Name of the portal to return records from. - * - * @return Record[] Array of Record objects from $relatedSet. - * @throws FileMakerException - */ - public function getRelatedSet($relatedSet) { - if (!isset($this->relatedSets[$relatedSet])) { - $error = new FileMakerException($this->fm, 'Related set "' . $relatedSet . '" not present.'); - if($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - return $this->relatedSets[$relatedSet]; - } - - /** - * Creates a new record in the specified portal. - * - * @param string $relatedSet Name of the portal to create a new record in. - * - * @return Record A new, blank record. - * @throws FileMakerException - */ - public function newRelatedRecord($relatedSet) { - $relatedSetInfos = $this->layout->getRelatedSet($relatedSet); - if(FileMaker::isError($relatedSetInfos)){ - return $relatedSetInfos; - } - $record = new Record($relatedSetInfos); - $record->setParent($this); - $record->relatedSetName = $relatedSet; - return $record; - } - - /** - * Returns the parent record, if this record is a child record in a portal. - * - * @return Record Parent record. - */ - public function getParent() { - return $this->parent; - } - - /** - * Set the parent record, if this record is a child record in a portal. - * - * @param Record $record - * - * @return Record Parent record. - */ - public function setParent($record) { - $this->parent = $record; - } - - /** - * Pre-validates either a single field or the entire record. - * - * This method uses the pre-validation rules that are enforceable by the - * PHP engine -- for example, type rules, ranges, and four-digit dates. - * Rules such as "unique" or "existing," or validation by calculation - * field, cannot be pre-validated. - * - * If you pass the optional $fieldName argument, only that field is - * pre-validated. Otherwise, the record is pre-validated as if commit() - * were called with "Enable record data pre-validation" selected in - * FileMaker Server Admin Console. If pre-validation passes, validate() - * returns TRUE. If pre-validation fails, then validate() throws a - * FileMakerValidationException object containing details about what failed - * to pre-validate. - * - * @param string $fieldName Name of field to pre-validate. If empty, - * pre-validates the entire record. - * - * @return boolean|\airmoi\FileMaker\FileMakerValidationException TRUE, if pre-validation passes for $value. - * @throws \airmoi\FileMaker\FileMakerValidationException - */ - public function validate($fieldName = null) { - $command = $this->fm->newAddCommand($this->layout->getName(), $this->fields); - return $command->validate($fieldName); - } - - /** - * Saves any changes to this record in the database on the Database Server. - * - * @return boolean|FileMakerException TRUE, if successful. - * @throws FileMakerException - */ - public function commit() { - if ($this->fm->getProperty('prevalidate')) { - $validation = $this->validate(); - if (FileMaker::isError($validation)) { - return $validation; - } - } - if (is_null($this->parent)) { - if ($this->recordId) { - return $this->_commitEdit(); - } else { - return $this->_commitAdd(); - } - } else { - if (!$this->parent->getRecordId()) { - throw new FileMakerException($this->fm, 'You must commit the parent record first before you can commit its children.'); - } - if ($this->recordId) { - return $this->_commitEditChild(); - } else { - return $this->_commitAddChild(); - } - } - } - - /** - * Deletes this record from the database on the Database Server. - * - * @return Result|FileMakerException Response object. - * @throws FileMakerException - */ - public function delete() { - if (empty($this->recordId)) { - $error = new FileMakerException($this->fm, 'You cannot delete a record that does not exist on the server.'); - if ($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - if ($this->parent) { - $editCommand = $this->fm->newEditCommand($this->parent->layout->getName(), $this->parent->recordId, []); - $editCommand->setDeleteRelated($this->layout->getName() . "." . $this->recordId); - - return $editCommand->execute(); - } else { - $layoutName = $this->layout->getName(); - - $editCommand = $this->fm->newDeleteCommand($layoutName, $this->recordId); - return $editCommand->execute(); - } - } - - /** - * Gets a specific related record. - * - * @access private - * - * @param string $relatedSetName Name of the portal. - * @param string $recordId Record ID of the record in the portal. - * - * @return Record|FileMakerException Record object. - * @throws FileMakerException - */ - public function getRelatedRecordById($relatedSetName, $recordId) { - try { - $relatedSet = $this->getRelatedSet($relatedSetName); - } - catch (FileMakerException $e) { - $error = new FileMakerException($this->fm, 'Related set "' . $relatedSetName . '" not present.'); - if ($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - - foreach ($relatedSet as $record) { - if ($record->getRecordId() == $recordId) { - return $record; - } - } - $error = new FileMakerException($this->fm, 'Record not present.'); - if($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - - /** - * - * @return boolean|FileMakerException TRUE on success - * @throws FileMakerException - */ - private function _commitAdd() { - $addCommand = $this->fm->newAddCommand($this->layout->getName(), $this->fields); - $result = $addCommand->execute(); - if(FileMaker::isError($result)){ - return $result; - } - $records = $result->getFirstRecord(); - return $this->_updateFrom($records); - } - - /** - * - * @return boolean|FileMakerException TRUE on success - * @throws FileMakerException - */ - private function _commitEdit() { - $editedFields=[]; - foreach ($this->fields as $fieldName => $repetitions) { - foreach ($repetitions as $repetition => $value) { - if (isset($this->_modifiedFields[$fieldName][$repetition])) { - $editedFields[$fieldName][$repetition] = $value; - } - } - } - $command = $this->fm->newEditCommand($this->layout->getName(), $this->recordId, $editedFields); - $result = $command->execute(); - if (FileMaker::isError($result)) { - return $result; - } - $records = $result->getFirstRecord(); - return $this->_updateFrom($records); - } - - /** - * - * @return boolean|FileMakerException TRUE on success - * @throws FileMakerException - */ - private function _commitAddChild() { - $childs = array(); - foreach ($this->fields as $fieldName => $repetitions) { - $childs[$fieldName . '.0'] = $repetitions; - } - $command = $this->fm->newEditCommand($this->parent->layout->getName(), $this->parent->getRecordId(), $childs); - $result = $command->execute(); - if (FileMaker::isError($result)) { - return $result; - } - $records = $result->getRecords(); - $record = $records[0]; - $relatedSet = $record->getRelatedSet($this->layout->getName()); - if (FileMaker::isError($relatedSet)) { - return $relatedSet; - } - $lastRecord = array_pop($relatedSet); - /* - * Add record to parents relatedSet - */ - $this->parent->relatedSets[$this->layout->getName()][] = $this; - return $this->_updateFrom($lastRecord); - } - - /** - * - * @return boolean|FileMakerException TRUE on success - * @throws FileMakerException - */ - private function _commitEditChild() { - $modifiedFields=[]; - foreach ($this->fields as $fieldName => $repetitions) { - foreach ($repetitions as $repetition => $value) { - if (!empty($this->_modifiedFields[$fieldName][$repetition])) { - $modifiedFields[$fieldName . '.' . $this->recordId][$repetition] = $value; - } - } - } - $editCommand = $this->fm->newEditCommand($this->parent->layout->getName(), $this->parent->getRecordId(), $modifiedFields); - $result = $editCommand->execute(); - if (FileMaker::isError($result)) { - return $result; - } - $records = $result->getRecords(); - $firstRecord = $records[0]; - $relatedSet = $firstRecord->getRelatedSet($this->layout->getName()); - if (FileMaker::isError($relatedSet)) { - return $relatedSet; - } - foreach ($relatedSet as $record) { - if ($record->getRecordId() == $this->recordId) { - return $this->_updateFrom($record); - break; - } - } - $error = new FileMakerException($this->fm, 'Failed to find the updated child in the response.'); - if($this->fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - - /** - * - * @param Record $record - * @return boolean - */ - private function _updateFrom(Record $record) { - $this->recordId = $record->getRecordId(); - $this->modificationId = $record->getModificationId(); - $this->fields = $record->fields; - $this->layout = $record->layout; - $this->relatedSets = & $record->relatedSets; - $this->_modifiedFields = array(); - return true; - } - -} +layout = $layout; + $this->fm = $layout->fm; + } + + /** + * Returns the layout this record is associated with. + * + * @return Layout This record's layout. + */ + public function getLayout() + { + return $this->layout; + } + + /** + * Returns a list of the names of all fields in the record. + * + * Only the field names are returned. If you need additional + * information, examine the Layout object provided by the + * parent object's {@link Result::getLayout()} method. + * + * @return array List of field names as strings. + */ + public function getFields() + { + return $this->layout->listFields(); + } + + /** + * Returns the HTML-encoded value of the specified field. + * + * This method converts some special characters in the field value to + * HTML entities. For example, '&', '"', '<', and '>' are converted to + * '&', '"', '<', and '>', respectively. + * + * @param string $field Name of field. + * @param integer $repetition Field repetition number to get. + * Defaults to the first repetition. + * @param boolean $unencoded + * + * @return null|string|FileMakerException Encoded field value. + * @throws FileMakerException + */ + public function getField($field, $repetition = 0, $unencoded = false) + { + if (!is_null($this->parent) && !strpos($field, '::')) { + $field = $this->relatedSetName. '::' . $field; + } + if (!isset($this->fields[$field])) { + $this->fm->log('Field "' . $field . '" not found.', FileMaker::LOG_INFO); + return null; + } + if (!isset($this->fields[$field][$repetition])) { + $this->fm->log('Repetition "' . (int) $repetition . '" does not exist for "' . $field . '".', FileMaker::LOG_INFO); + return null; + } + $format = $this->layout->getField($field)->result; + $value = $this->fields[$field][$repetition]; + + if (empty($value) && $this->fm->getProperty('emptyAsNull')) { + return null; + } + if (!empty($value) && preg_match('/\d{2}.\d{2}.\d{4}/', $value) && $this->fm->getProperty('dateFormat') !== null && ($format == 'date' || $format == 'timestamp')) { + if ($format == 'date') { + if (!$dateTime = \DateTime::createFromFormat('m/d/Y H:i:s', $value . ' 00:00:00')) { + $error = new FileMakerException($this->fm, $field . ' could not be converted to a valid timestamp ('. $value .')'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + return $dateTime->format($this->fm->getProperty('dateFormat')); + } else { + if (!$dateTime = \DateTime::createFromFormat('m/d/Y H:i:s', $value)) { + $error = new FileMakerException($this->fm, $field . ' could not be converted to a valid timestamp ('. $value .')'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + return $dateTime->format($this->fm->getProperty('dateFormat') . ' H:i:s'); + } + } elseif (!empty($value) && $format == 'number') { + $value = preg_replace('/,/', '.', $value); + } + return $unencoded ? $value : htmlspecialchars($value); + } + + /** + * Returns the two field value list associated with the given field in Record's layout. + * + * @param string $fieldName Field's Name + * @return array|\airmoi\FileMaker\FileMakerException + * @see Layout::getValueListTwoFields + */ + public function getFieldValueListTwoFields($fieldName) + { + if (!is_null($this->parent) && !strpos($fieldName, '::')) { + $fieldName = $this->relatedSetName. '::' . $fieldName; + } + if (!isset($this->fields[$fieldName])) { + $this->fm->log('Field "' . $fieldName . '" not found.', FileMaker::LOG_INFO); + return []; + } + + //Force load extendedInfos as Field's valueList property is not set until extended infos are retrieved + $ExtendedInfos = $this->layout->loadExtendedInfo($this->recordId); + if (FileMaker::isError($ExtendedInfos)) { + return $ExtendedInfos; + } + + $field = $this->layout->getField($fieldName); + if (FileMaker::isError($field)) { + return []; + } + //Get the value list if field has one + if ($field->valueList !== null) { + return $this->layout->getValueListTwoFields($this->layout->fields[$fieldName]->valueList, $this->recordId); + } + return []; + } + + /** + * Returns the unencoded value of the specified field. + * + * This method does not convert special characters in the field value to + * HTML entities. + * @deprecated since version 2.0 use getField($field, $repetition = 0, $unencoded = true) instead + * @param string $field Name of field. + * @param integer $repetition Field repetition number to get. + * Defaults to the first repetition. + * + * @return string Unencoded field value. + */ + public function getFieldUnencoded($field, $repetition = 0) + { + return $this->getField($field, $repetition, true); + } + + /** + * Returns the value of the specified field as a UNIX + * timestamp. + * + * If the field is a date field, the timestamp is + * for the field date at midnight. It the field is a time field, + * the timestamp is for that time on January 1, 1970. Timestamp + * (date and time) fields map directly to the UNIX timestamp. If the + * specified field is not a date or time field, or if the timestamp + * generated would be out of range, then this method throws a + * FileMakerException object instead. + * + * @param string $field Name of the field. + * @param integer $repetition Field repetition number to get. + * Defaults to the first repetition. + * @return FileMakerException|int Timestamp value. + * @throws FileMakerException + */ + public function getFieldAsTimestamp($field, $repetition = 0) + { + $value = $this->getField($field, $repetition); + $fieldType = $this->layout->getField($field); + $error = null; + $dateFormat = $this->fm->getProperty('dateFormat') !== null ? $this->fm->getProperty('dateFormat') : 'm/d/Y'; + switch ($fieldType->getResult()) { + case 'date': + // e. g. "12/24/2016" + if (!$dateTime = \DateTime::createFromFormat($dateFormat . ' H:i:s', $value . ' 00:00:00')) { + $error = new FileMakerException( + $this->fm, + 'Failed to parse "' . $value . '" as a FileMaker date value.' + ); + } + break; + case 'time': + // e. g. "12:00:00" + if (!$dateTime = \DateTime::createFromFormat('Y-m-d H:i:s', '1970-01-01 ' . $value)) { + $error = new FileMakerException( + $this->fm, + 'Failed to parse "' . $value . '" as a FileMaker time value.' + ); + } + break; + case 'timestamp': + // e. g. "12/24/2016 12:00:00" + if (!$dateTime = \DateTime::createFromFormat($dateFormat . ' H:i:s', $value)) { + $error = new FileMakerException( + $this->fm, + 'Failed to parse "' . $value . '" as a FileMaker timestamp value.' + ); + } + break; + default: + $error = new FileMakerException( + $this->fm, + 'Only time, date, and timestamp fields can be converted to UNIX timestamps.' + ); + break; + } + if ($error !== null) { + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } else { + throw $error; + } + } + + return $dateTime->format('U'); + } + + /** + * Sets the value of $field. + * + * @param string $field Name of the field. + * @param string $value New value of the field. + * @param integer $repetition Field repetition number to set. + * Defaults to the first repetition. + * + * @return string|FileMakerException + * @throws FileMakerException + */ + public function setField($field, $value, $repetition = 0) + { + + if (!is_null($this->parent) && !strpos($field, '::')) { + $field = $this->relatedSetName. '::' . $field; + } + if (!array_key_exists($field, $this->layout->fields)) { + $error = new FileMakerException($this->fm, 'Field "'.$field.'" is missing'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + + $format = $this->layout->getField($field)->result; + if (!empty($value) && $this->fm->getProperty('dateFormat') !== null && ($format == 'date' || $format == 'timestamp')) { + if ($format == 'date') { + if (!$dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value . ' 00:00:00', new \DateTimeZone(date_default_timezone_get()))) { + $error = new FileMakerException($this->fm, $value . ' could not be converted to a valid timestamp for field ' . $field . ' (expected format '. $this->fm->getProperty('dateFormat') .')'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + $value = $dateTime->format('m/d/Y'); + } else { + if (!$dateTime = \DateTime::createFromFormat($this->fm->getProperty('dateFormat') . ' H:i:s', $value, new \DateTimeZone(date_default_timezone_get()))) { + $error = new FileMakerException($this->fm, $value . ' could not be converted to a valid timestamp for field ' . $field . ' (expected format '. $this->fm->getProperty('dateFormat') .')'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + $value = $dateTime->format('m/d/Y H:i:s'); + } + } + + $this->fields[$field][$repetition] = $value; + $this->_modifiedFields[$field][$repetition] = true; + return $value; + } + + /** + * Sets the new value for a date, time, or timestamp field from a + * UNIX timestamp value. + * + * If the field is not a date or time field, then returns an error. + * Otherwise, returns TRUE. + * + * If layout data for the target of this command has not already + * been loaded, calling this method loads layout data so that + * the type of the field can be checked. + * + * @todo use DateTime instead of date() to handle pre-epoch timestamps + * + * @param string $field Name of the field to set. + * @param string $timestamp Timestamp value. + * @param integer $repetition Field repetition number to set. + * Defaults to the first repetition. + * + * @return string + * @throws FileMakerException + */ + public function setFieldFromTimestamp($field, $timestamp, $repetition = 0) + { + $fieldType = $this->layout->getField($field); + if (FileMaker::isError($fieldType)) { + return $fieldType; + } + switch ($fieldType->getResult()) { + case 'date': + return $this->setField($field, date('m/d/Y', $timestamp), $repetition); + case 'time': + return $this->setField($field, date('H:i:s', $timestamp), $repetition); + case 'timestamp': + return $this->setField($field, date('m/d/Y H:i:s', $timestamp), $repetition); + } + $error = new FileMakerException($this->fm, 'Only time, date, and timestamp fields can be set to the value of a timestamp.'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + + /** + * Returns the record ID of this object. + * + * @return string Record ID. + */ + public function getRecordId() + { + return $this->recordId; + } + + /** + * Returns the modification ID of this record. + * + * The modification ID is an incremental counter that specifies the current + * version of a record. See the {@link Edit::setModificationId()} + * method. + * + * @return integer Modification ID. + */ + public function getModificationId() + { + return $this->modificationId; + } + + /** + * Returns any Record objects in the specified portal or throw a FileMakerException + * object if there are no related records + * + * @param string $relatedSet Name of the portal to return records from. + * + * @return Record[] Array of Record objects from $relatedSet. + * @throws FileMakerException + */ + public function getRelatedSet($relatedSet) + { + if (!isset($this->relatedSets[$relatedSet])) { + $error = new FileMakerException($this->fm, 'Related set "' . $relatedSet . '" not present.'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + return $this->relatedSets[$relatedSet]; + } + + /** + * Creates a new record in the specified portal. + * + * @param string $relatedSet Name of the portal to create a new record in. + * + * @return Record A new, blank record. + * @throws FileMakerException + */ + public function newRelatedRecord($relatedSet) + { + $relatedSetInfos = $this->layout->getRelatedSet($relatedSet); + if (FileMaker::isError($relatedSetInfos)) { + return $relatedSetInfos; + } + $record = new Record($relatedSetInfos); + $record->setParent($this); + $record->relatedSetName = $relatedSet; + return $record; + } + + /** + * Returns the parent record, if this record is a child record in a portal. + * + * @return Record Parent record. + */ + public function getParent() + { + return $this->parent; + } + + /** + * Set the parent record, if this record is a child record in a portal. + * + * @param Record $record + * + * @return Record Parent record. + */ + public function setParent($record) + { + $this->parent = $record; + } + + /** + * Pre-validates either a single field or the entire record. + * + * This method uses the pre-validation rules that are enforceable by the + * PHP engine -- for example, type rules, ranges, and four-digit dates. + * Rules such as "unique" or "existing," or validation by calculation + * field, cannot be pre-validated. + * + * If you pass the optional $fieldName argument, only that field is + * pre-validated. Otherwise, the record is pre-validated as if commit() + * were called with "Enable record data pre-validation" selected in + * FileMaker Server Admin Console. If pre-validation passes, validate() + * returns TRUE. If pre-validation fails, then validate() throws a + * FileMakerValidationException object containing details about what failed + * to pre-validate. + * + * @param string $fieldName Name of field to pre-validate. If empty, + * pre-validates the entire record. + * + * @return boolean|\airmoi\FileMaker\FileMakerValidationException TRUE, if pre-validation passes for $value. + * @throws \airmoi\FileMaker\FileMakerValidationException + */ + public function validate($fieldName = null) + { + $command = $this->fm->newAddCommand($this->layout->getName(), $this->fields); + return $command->validate($fieldName); + } + + /** + * Saves any changes to this record in the database on the Database Server. + * + * @return boolean|FileMakerException TRUE, if successful. + * @throws FileMakerException + */ + public function commit() + { + if ($this->fm->getProperty('prevalidate')) { + $validation = $this->validate(); + if (FileMaker::isError($validation)) { + return $validation; + } + } + if (is_null($this->parent)) { + if ($this->recordId) { + return $this->_commitEdit(); + } else { + return $this->_commitAdd(); + } + } else { + if (!$this->parent->getRecordId()) { + throw new FileMakerException($this->fm, 'You must commit the parent record first before you can commit its children.'); + } + if ($this->recordId) { + return $this->_commitEditChild(); + } else { + return $this->_commitAddChild(); + } + } + } + + /** + * Deletes this record from the database on the Database Server. + * + * @return Result|FileMakerException Response object. + * @throws FileMakerException + */ + public function delete() + { + if (empty($this->recordId)) { + $error = new FileMakerException($this->fm, 'You cannot delete a record that does not exist on the server.'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + if ($this->parent) { + $editCommand = $this->fm->newEditCommand($this->parent->layout->getName(), $this->parent->recordId, []); + $editCommand->setDeleteRelated($this->layout->getName() . "." . $this->recordId); + + return $editCommand->execute(); + } else { + $layoutName = $this->layout->getName(); + + $editCommand = $this->fm->newDeleteCommand($layoutName, $this->recordId); + return $editCommand->execute(); + } + } + + /** + * Gets a specific related record. + * + * @access private + * + * @param string $relatedSetName Name of the portal. + * @param string $recordId Record ID of the record in the portal. + * + * @return Record|FileMakerException Record object. + * @throws FileMakerException + */ + public function getRelatedRecordById($relatedSetName, $recordId) + { + try { + $relatedSet = $this->getRelatedSet($relatedSetName); + } catch (FileMakerException $e) { + $error = new FileMakerException($this->fm, 'Related set "' . $relatedSetName . '" not present.'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + + foreach ($relatedSet as $record) { + if ($record->getRecordId() == $recordId) { + return $record; + } + } + $error = new FileMakerException($this->fm, 'Record not present.'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + + /** + * + * @return boolean|FileMakerException TRUE on success + * @throws FileMakerException + */ + private function _commitAdd() + { + $addCommand = $this->fm->newAddCommand($this->layout->getName(), $this->fields); + $result = $addCommand->execute(); + if (FileMaker::isError($result)) { + return $result; + } + $records = $result->getFirstRecord(); + return $this->_updateFrom($records); + } + + /** + * + * @return boolean|FileMakerException TRUE on success + * @throws FileMakerException + */ + private function _commitEdit() + { + $editedFields=[]; + foreach ($this->fields as $fieldName => $repetitions) { + foreach ($repetitions as $repetition => $value) { + if (isset($this->_modifiedFields[$fieldName][$repetition])) { + $editedFields[$fieldName][$repetition] = $value; + } + } + } + $command = $this->fm->newEditCommand($this->layout->getName(), $this->recordId, $editedFields); + $result = $command->execute(); + if (FileMaker::isError($result)) { + return $result; + } + $records = $result->getFirstRecord(); + return $this->_updateFrom($records); + } + + /** + * + * @return boolean|FileMakerException TRUE on success + * @throws FileMakerException + */ + private function _commitAddChild() + { + $childs = array(); + foreach ($this->fields as $fieldName => $repetitions) { + $childs[$fieldName . '.0'] = $repetitions; + } + $command = $this->fm->newEditCommand($this->parent->layout->getName(), $this->parent->getRecordId(), $childs); + $result = $command->execute(); + if (FileMaker::isError($result)) { + return $result; + } + $records = $result->getRecords(); + $record = $records[0]; + $relatedSet = $record->getRelatedSet($this->layout->getName()); + if (FileMaker::isError($relatedSet)) { + return $relatedSet; + } + $lastRecord = array_pop($relatedSet); + /* + * Add record to parents relatedSet + */ + $this->parent->relatedSets[$this->layout->getName()][] = $this; + return $this->_updateFrom($lastRecord); + } + + /** + * + * @return boolean|FileMakerException TRUE on success + * @throws FileMakerException + */ + private function _commitEditChild() + { + $modifiedFields=[]; + foreach ($this->fields as $fieldName => $repetitions) { + foreach ($repetitions as $repetition => $value) { + if (!empty($this->_modifiedFields[$fieldName][$repetition])) { + $modifiedFields[$fieldName . '.' . $this->recordId][$repetition] = $value; + } + } + } + $editCommand = $this->fm->newEditCommand($this->parent->layout->getName(), $this->parent->getRecordId(), $modifiedFields); + $result = $editCommand->execute(); + if (FileMaker::isError($result)) { + return $result; + } + $records = $result->getRecords(); + $firstRecord = $records[0]; + $relatedSet = $firstRecord->getRelatedSet($this->layout->getName()); + if (FileMaker::isError($relatedSet)) { + return $relatedSet; + } + foreach ($relatedSet as $record) { + if ($record->getRecordId() == $this->recordId) { + return $this->_updateFrom($record); + break; + } + } + $error = new FileMakerException($this->fm, 'Failed to find the updated child in the response.'); + if ($this->fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + + /** + * + * @param Record $record + * @return boolean + */ + private function _updateFrom(Record $record) + { + $this->recordId = $record->getRecordId(); + $this->modificationId = $record->getModificationId(); + $this->fields = $record->fields; + $this->layout = $record->layout; + $this->relatedSets = & $record->relatedSets; + $this->_modifiedFields = array(); + return true; + } +} diff --git a/src/Object/RelatedSet.php b/src/Object/RelatedSet.php index e543b15..11ff370 100644 --- a/src/Object/RelatedSet.php +++ b/src/Object/RelatedSet.php @@ -1,7 +1,7 @@ fields[$fieldName]; } $error = new FileMakerException($this->fm, 'Field '.$fieldName.' Not Found in Layout '. $this->layout->getName()); - if($this->fm->getProperty('errorHandling') == 'default') { + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } /** - * Returns an associative array with the names of all fields as keys and + * Returns an associative array with the names of all fields as keys and * Field objects as the array values. * * @return array Array of {@link Field} objects. @@ -104,10 +104,9 @@ public function getFields() public function loadExtendedInfo() { $error = new FileMakerException($this->fm, 'Related sets do not support extended information.'); - if($this->fm->getProperty('errorHandling') == 'default') { + if ($this->fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; } - } diff --git a/src/Object/Result.php b/src/Object/Result.php index f66da36..2bb3299 100644 --- a/src/Object/Result.php +++ b/src/Object/Result.php @@ -1,7 +1,7 @@ records[sizeof($this->records) - 1]; } - } diff --git a/src/Parser/FMPXMLLAYOUT.php b/src/Parser/FMPXMLLAYOUT.php index dc5cde6..e0a75e5 100644 --- a/src/Parser/FMPXMLLAYOUT.php +++ b/src/Parser/FMPXMLLAYOUT.php @@ -1,7 +1,7 @@ _fm = $fm; } /** - * + * * @param string $xmlResponse * @return boolean|FileMakerException * @throws FileMakerException */ - public function parse($xmlResponse) { + public function parse($xmlResponse) + { if (empty($xmlResponse)) { $error = new FileMakerException($this->_fm, 'Did not receive an XML document from the server.'); - if($this->_fm->getProperty('errorHandling') == 'default') { + if ($this->_fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -55,8 +58,15 @@ public function parse($xmlResponse) { xml_set_element_handler($this->_xmlParser, '_start', '_end'); xml_set_character_data_handler($this->_xmlParser, '_cdata'); if (!@xml_parse($this->_xmlParser, $xmlResponse)) { - $error = new FileMakerException($this->_fm, sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_xmlParser)), xml_get_current_line_number($this->_xmlParser))); - if($this->_fm->getProperty('errorHandling') == 'default') { + $error = new FileMakerException( + $this->_fm, + sprintf( + 'XML error: %s at line %d', + xml_error_string(xml_get_error_code($this->_xmlParser)), + xml_get_current_line_number($this->_xmlParser) + ) + ); + if ($this->_fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -64,7 +74,7 @@ public function parse($xmlResponse) { xml_parser_free($this->_xmlParser); if (!empty($this->errorCode)) { $error = new FileMakerException($this->_fm, null, $this->errorCode); - if($this->_fm->getProperty('errorHandling') == 'default') { + if ($this->_fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -75,15 +85,16 @@ public function parse($xmlResponse) { /** * Add extended infos to a Layout object - * + * * @param Layout $layout * @return FileMakerException * @throws FileMakerException */ - public function setExtendedInfo(Layout $layout) { + public function setExtendedInfo(Layout $layout) + { if (!$this->_isParsed) { $error = new FileMakerException($this->_fm, 'Attempt to set extended information before parsing data.'); - if($this->_fm->getProperty('errorHandling') == 'default') { + if ($this->_fm->getProperty('errorHandling') === 'default') { return $error; } throw $error; @@ -93,11 +104,11 @@ public function setExtendedInfo(Layout $layout) { foreach ($this->_fields as $fieldName => $fieldInfos) { try { $field = $layout->getField($fieldName); - if(!FileMaker::isError($field)) { + if (!FileMaker::isError($field)) { $field->styleType = $fieldInfos['styleType']; $field->valueList = $fieldInfos['valueList'] ? $fieldInfos['valueList'] : null; } - } catch ( \Exception $e ) { + } catch (\Exception $e) { //Field may be missing when it is stored in a portal, ommit error } } @@ -105,12 +116,13 @@ public function setExtendedInfo(Layout $layout) { /** * xml_parser start element handler - * + * * @param resource $parser * @param string $type * @param array $datas */ - private function _start($parser, $type, $datas) { + private function _start($parser, $type, $datas) + { $datas = $this->_fm->toOutputCharset($datas); switch ($type) { case 'FIELD': @@ -135,11 +147,12 @@ private function _start($parser, $type, $datas) { /** * xml_parser end element handler - * + * * @param resource $parser * @param string $type */ - private function _end($parser, $type) { + private function _end($parser, $type) + { switch ($type) { case 'FIELD': $this->_fieldName = null; @@ -154,13 +167,13 @@ private function _end($parser, $type) { /** * xml_parser character data handler (cdata) - * + * * @param resource $parser * @param string $datas */ - public function _cdata($parser, $datas) { + public function _cdata($parser, $datas) + { if ($this->_valueList !== null && preg_match('|\S|', $datas)) { - if ($this->inside_data) { $value = $this->_valueListTwoFields[$this->_valueList][$this->_displayValue]; $datas = $value . $datas; @@ -174,12 +187,13 @@ public function _cdata($parser, $datas) { /** * Add values to an existing array - * + * * @param array $array * @param array $values * @return boolean */ - public function associative_array_push(&$array, $values) { + public function associative_array_push(&$array, $values) + { if (is_array($values)) { foreach ($values as $key => $value) { $array[$key] = $value; @@ -188,5 +202,4 @@ public function associative_array_push(&$array, $values) { } return false; } - } diff --git a/src/Parser/FMResultSet.php b/src/Parser/FMResultSet.php index a936263..8ce957d 100644 --- a/src/Parser/FMResultSet.php +++ b/src/Parser/FMResultSet.php @@ -1,360 +1,381 @@ -_fm = $fm; - } - - /** - * Parse the provided xml - * - * @param string $xml - * @return FileMakerException|boolean - * @throws FileMakerException - */ - public function parse($xml) { - if (empty($xml)) { - $error = new FileMakerException($this->_fm, 'Did not receive an XML document from the server.'); - if($this->_fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - $this->_xmlParser = xml_parser_create('UTF-8'); - xml_set_object($this->_xmlParser, $this); - xml_parser_set_option($this->_xmlParser, XML_OPTION_CASE_FOLDING, false); - xml_parser_set_option($this->_xmlParser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); - xml_set_element_handler($this->_xmlParser, '_start', '_end'); - xml_set_character_data_handler($this->_xmlParser, '_cdata'); - if (!@xml_parse($this->_xmlParser, $xml)) { - $error = new FileMakerException($this->_fm, sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_xmlParser)), xml_get_current_line_number($this->_xmlParser))); - if($this->_fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - xml_parser_free($this->_xmlParser); - if (!empty($this->_errorCode)) { - $error = new FileMakerException($this->_fm, null, $this->_errorCode); - if($this->_fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - if (version_compare($this->_serverVersion['version'], FileMaker::getMinServerVersion(), '<')) { - $error = new FileMakerException($this->_fm, 'This API requires at least version ' . FileMaker::getMinServerVersion() . ' of FileMaker Server to run (detected ' . $this->_serverVersion['version'] . ').'); - if($this->_fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - $this->_isParsed = true; - return true; - } - - /** - * Populate a result object with parsed datas - * - * @param \airmoi\FileMaker\Object\Result $result - * @param string $recordClass string representing the record class name to use - * @return FileMakerException|boolean - * @throws FileMakerException - */ - public function setResult(Result $result, $recordClass = 'airmoi\FileMaker\Object\Record') { - if (!$this->_isParsed) { - $error = new FileMakerException($this->_fm, 'Attempt to get a result object before parsing data.'); - if($this->_fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - if ($this->_result) { - $result = $this->_result; - return true; - } - $result->layout = new Layout($this->_fm); - $this->setLayout($result->layout); - $result->tableCount = $this->_parsedHead['total-count']; - $result->foundSetCount = $this->_parsedFoundSet['count']; - $result->fetchCount = $this->_parsedFoundSet['fetch-size']; - $records = array(); - foreach ($this->parsedResult as $recordData) { - $record = new $recordClass($result->layout); - $record->fields = $recordData['fields']; - $record->recordId = $recordData['record-id']; - $record->modificationId = $recordData['mod-id']; - if ($recordData['children']) { - foreach ($recordData['children'] as $relatedSetName => $relatedRecords) { - $record->relatedSets[$relatedSetName] = array(); - foreach ($relatedRecords as $relatedRecordData) { - $relatedRecord = new $recordClass($result->layout->getRelatedSet($relatedSetName)); - $relatedRecord->fields = $relatedRecordData['fields']; - $relatedRecord->recordId = $relatedRecordData['record-id']; - $relatedRecord->modificationId = $relatedRecordData['mod-id']; - $relatedRecord->parent = $record; - $relatedRecord->relatedSetName = $relatedSetName; - $record->relatedSets[$relatedSetName][] = $relatedRecord; - } - } - } - $records[] = $record; - } - $result->records = & $records; - $this->_result = & $result; - return true; - } - - /** - * Populate a layout object with parsed datas - * - * @param Layout $layout - * @return FileMakerException|boolean - * @throws FileMakerException - */ - public function setLayout(Layout $layout) { - if (!$this->_isParsed) { - $error = new FileMakerException($this->_fm, 'Attempt to get a layout object before parsing data.'); - if($this->_fm->getProperty('errorHandling') == 'default') { - return $error; - } - throw $error; - } - if ($this->_layout === $layout) { - return true; - } - $layout->name = $this->_parsedHead['layout']; - $layout->database = $this->_parsedHead['database']; - $layout->table = $this->_parsedHead['table']; - foreach ($this->_fieldList as $fieldInfos) { - $field = new Field($layout); - $field->name = $fieldInfos['name']; - $field->autoEntered = (bool) ($fieldInfos['auto-enter'] == 'yes'); - $field->global = (bool) ($fieldInfos['global'] == 'yes'); - $field->maxRepeat = (int) $fieldInfos['max-repeat']; - $field->result = $fieldInfos['result']; - $field->type = $fieldInfos['type']; - if ($fieldInfos['not-empty'] == 'yes') { - $field->validationRules[FileMaker::RULE_NOTEMPTY] = true; - $field->validationMask |= FileMaker::RULE_NOTEMPTY; - } - if ($fieldInfos['numeric-only'] == 'yes') { - $field->validationRules[FileMaker::RULE_NUMERICONLY] = true; - $field->validationMask |= FileMaker::RULE_NUMERICONLY; - } - if (array_key_exists('max-characters', $fieldInfos)) { - $field->maxCharacters = (int) $fieldInfos['max-characters']; - $field->validationRules[FileMaker::RULE_MAXCHARACTERS] = true; - $field->validationMask |= FileMaker::RULE_MAXCHARACTERS; - } - if ($fieldInfos['four-digit-year'] == 'yes') { - $field->validationRules[FileMaker::RULE_FOURDIGITYEAR] = true; - $field->validationMask |= FileMaker::RULE_FOURDIGITYEAR; - } - if ($fieldInfos['time-of-day'] == 'yes') { - $field->validationRules[FileMaker::RULE_TIMEOFDAY] = true; - $field->validationMask |= FileMaker::RULE_TIMEOFDAY; - } - if ($fieldInfos['four-digit-year'] == 'no' && $fieldInfos['result'] == 'timestamp') { - $field->validationRules[FileMaker::RULE_TIMESTAMP_FIELD] = true; - $field->validationMask |= FileMaker::RULE_TIMESTAMP_FIELD; - } - if ($fieldInfos['four-digit-year'] == 'no' && $fieldInfos['result'] == 'date') { - $field->validationRules[FileMaker::RULE_DATE_FIELD] = true; - $field->validationMask |= FileMaker::RULE_DATE_FIELD; - } - if ($fieldInfos['time-of-day'] == 'no' && $fieldInfos['result'] == 'time') { - $field->validationRules[FileMaker::RULE_TIME_FIELD] = true; - $field->validationMask |= FileMaker::RULE_TIME_FIELD; - } - $layout->fields[$field->getName()] = $field; - } - foreach ($this->_relatedSetNames as $relatedSetName => $fields) { - $relatedSet = new RelatedSet($layout); - $relatedSet->name = $relatedSetName; - foreach ($fields as $fieldInfos) { - $field = new Field($layout); - $field->name = $fieldInfos['name']; - $field->autoEntered = (bool) ($fieldInfos['auto-enter'] == 'yes'); - $field->global = (bool) ($fieldInfos['global'] == 'yes'); - $field->maxRepeat = (int) $fieldInfos['max-repeat']; - $field->result = $fieldInfos['result']; - $field->type = $fieldInfos['type']; - if ($fieldInfos['not-empty'] == 'yes') { - $field->validationRules[FileMaker::RULE_NOTEMPTY] = true; - $field->validationMask |= FileMaker::RULE_NOTEMPTY; - } - if ($fieldInfos['numeric-only'] == 'yes') { - $field->validationRules[FileMaker::RULE_NUMERICONLY] = true; - $field->validationMask |= FileMaker::RULE_NUMERICONLY; - } - if (array_key_exists('max-characters', $fieldInfos)) { - $field->maxCharacters = (int) $fieldInfos['max-characters']; - $field->validationRules[FileMaker::RULE_MAXCHARACTERS] = true; - $field->validationMask |= FileMaker::RULE_MAXCHARACTERS; - } - if ($fieldInfos['four-digit-year'] == 'yes') { - $field->validationRules[FileMaker::RULE_FOURDIGITYEAR] = true; - $field->validationMask |= FileMaker::RULE_FOURDIGITYEAR; - } - if ($fieldInfos['time-of-day'] == 'yes' || $fieldInfos['result'] == 'time') { - $field->validationRules[FileMaker::RULE_TIMEOFDAY] = true; - $field->validationMask |= FileMaker::RULE_TIMEOFDAY; - } - if ($fieldInfos['four-digit-year'] == 'no' && $fieldInfos['result'] == 'timestamp') { - $field->validationRules[FileMaker::RULE_TIMESTAMP_FIELD] = true; - $field->validationMask |= FileMaker::RULE_TIMESTAMP_FIELD; - } - if ($fieldInfos['four-digit-year'] == 'no' && $fieldInfos['result'] == 'date') { - $field->validationRules[FileMaker::RULE_DATE_FIELD] = true; - $field->validationMask |= FileMaker::RULE_DATE_FIELD; - } - if ($fieldInfos['time-of-day'] == 'no' && $fieldInfos['result'] == 'time') { - $field->validationRules[FileMaker::RULE_TIME_FIELD] = true; - $field->validationMask |= FileMaker::RULE_TIME_FIELD; - } - $relatedSet->fields[$field->getName()] = $field; - } - $layout->relatedSets[$relatedSet->getName()] = $relatedSet; - } - $this->_layout = $layout; - return true; - } - /** - * xml_parser start element handler - * - * @param resource $parser - * @param string $tag - * @param array $datas - */ - private function _start($parser, $tag, $datas) { - $datas = $this->_fm->toOutputCharset($datas); - switch ($tag) { - case 'error': - $this->_errorCode = $datas['code']; - break; - case 'product': - $this->_serverVersion = $datas; - break; - case 'datasource': - $this->_parsedHead = $datas; - break; - case 'relatedset-definition': - $this->_relatedSetNames[$datas['table']] = []; - $this->_currentRelatedSet = $datas['table']; - break; - case 'field-definition': - if ($this->_currentRelatedSet) { - $this->_relatedSetNames[$this->_currentRelatedSet][] = $datas; - } else { - $this->_fieldList[] = $datas; - } - break; - case 'resultset': - $this->_parsedFoundSet = $datas; - break; - case 'relatedset': - $this->_currentRelatedSet = $datas['table']; - $this->_parentRecord = $this->_currentRecord; - $this->_parentRecord['children'][$this->_currentRelatedSet] = array(); - $this->_currentRecord = null; - break; - case 'record': - $this->_currentRecord = array('record-id' => $datas['record-id'], - 'mod-id' => $datas['mod-id'], - 'fields' => array(), - 'children' => array()); - break; - case 'field': - $this->_currentField = $datas['name']; - $this->_currentRecord['fields'][$this->_currentField] = array(); - break; - case 'data': - $this->_cdata = ''; - break; - } - } - - /** - * xml_parser end element handler - * - * @param mixed $parser - * @param string $tag - */ - private function _end($parser, $tag) { - switch ($tag) { - case 'relatedset-definition': - $this->_currentRelatedSet = null; - break; - case 'relatedset': - $this->_currentRelatedSet = null; - $this->_currentRecord = $this->_parentRecord; - $this->_parentRecord = null; - break; - case 'record': - if ($this->_currentRelatedSet) { - $this->_parentRecord['children'][$this->_currentRelatedSet][] = $this->_currentRecord; - } else { - $this->parsedResult[] = $this->_currentRecord; - } - $this->_currentRecord = null; - break; - case 'field': - $this->_currentField = null; - break; - case 'data': - $this->_currentRecord['fields'][$this->_currentField][] = $this->_cdata; - $this->_cdata = null; - break; - } - } - - /** - * xml_parser character data handler (cdata) - * - * @param resource $parser - * @param string $data - */ - private function _cdata($parser, $data) { - $this->_cdata.= $this->_fm->toOutputCharset($data); - } - -} +_fm = $fm; + } + + /** + * Parse the provided xml + * + * @param string $xml + * @return FileMakerException|boolean + * @throws FileMakerException + */ + public function parse($xml) + { + if (empty($xml)) { + $error = new FileMakerException($this->_fm, 'Did not receive an XML document from the server.'); + if ($this->_fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + $this->_xmlParser = xml_parser_create('UTF-8'); + xml_set_object($this->_xmlParser, $this); + xml_parser_set_option($this->_xmlParser, XML_OPTION_CASE_FOLDING, false); + xml_parser_set_option($this->_xmlParser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); + xml_set_element_handler($this->_xmlParser, '_start', '_end'); + xml_set_character_data_handler($this->_xmlParser, '_cdata'); + if (!@xml_parse($this->_xmlParser, $xml)) { + $error = new FileMakerException( + $this->_fm, + sprintf( + 'XML error: %s at line %d', + xml_error_string(xml_get_error_code($this->_xmlParser)), + xml_get_current_line_number($this->_xmlParser) + ) + ); + if ($this->_fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + xml_parser_free($this->_xmlParser); + if (!empty($this->_errorCode)) { + $error = new FileMakerException($this->_fm, null, $this->_errorCode); + if ($this->_fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + if (version_compare($this->_serverVersion['version'], FileMaker::getMinServerVersion(), '<')) { + $error = new FileMakerException( + $this->_fm, + 'This API requires at least version ' . FileMaker::getMinServerVersion() + . ' of FileMaker Server to run (detected ' . $this->_serverVersion['version'] . ').' + ); + if ($this->_fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + $this->_isParsed = true; + return true; + } + + /** + * Populate a result object with parsed datas + * + * @param \airmoi\FileMaker\Object\Result $result + * @param string $recordClass string representing the record class name to use + * @return FileMakerException|boolean + * @throws FileMakerException + */ + public function setResult(Result $result, $recordClass = 'airmoi\FileMaker\Object\Record') + { + if (!$this->_isParsed) { + $error = new FileMakerException($this->_fm, 'Attempt to get a result object before parsing data.'); + if ($this->_fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + if ($this->_result) { + $result = $this->_result; + return true; + } + $result->layout = new Layout($this->_fm); + $this->setLayout($result->layout); + $result->tableCount = $this->_parsedHead['total-count']; + $result->foundSetCount = $this->_parsedFoundSet['count']; + $result->fetchCount = $this->_parsedFoundSet['fetch-size']; + $records = array(); + foreach ($this->parsedResult as $recordData) { + $record = new $recordClass($result->layout); + $record->fields = $recordData['fields']; + $record->recordId = $recordData['record-id']; + $record->modificationId = $recordData['mod-id']; + if ($recordData['children']) { + foreach ($recordData['children'] as $relatedSetName => $relatedRecords) { + $record->relatedSets[$relatedSetName] = array(); + foreach ($relatedRecords as $relatedRecordData) { + $relatedRecord = new $recordClass($result->layout->getRelatedSet($relatedSetName)); + $relatedRecord->fields = $relatedRecordData['fields']; + $relatedRecord->recordId = $relatedRecordData['record-id']; + $relatedRecord->modificationId = $relatedRecordData['mod-id']; + $relatedRecord->parent = $record; + $relatedRecord->relatedSetName = $relatedSetName; + $record->relatedSets[$relatedSetName][] = $relatedRecord; + } + } + } + $records[] = $record; + } + $result->records = & $records; + $this->_result = & $result; + return true; + } + + /** + * Populate a layout object with parsed datas + * + * @param Layout $layout + * @return FileMakerException|boolean + * @throws FileMakerException + */ + public function setLayout(Layout $layout) + { + if (!$this->_isParsed) { + $error = new FileMakerException($this->_fm, 'Attempt to get a layout object before parsing data.'); + if ($this->_fm->getProperty('errorHandling') === 'default') { + return $error; + } + throw $error; + } + if ($this->_layout === $layout) { + return true; + } + $layout->name = $this->_parsedHead['layout']; + $layout->database = $this->_parsedHead['database']; + $layout->table = $this->_parsedHead['table']; + foreach ($this->_fieldList as $fieldInfos) { + $field = new Field($layout); + $field->name = $fieldInfos['name']; + $field->autoEntered = (bool) ($fieldInfos['auto-enter'] === 'yes'); + $field->global = (bool) ($fieldInfos['global'] === 'yes'); + $field->maxRepeat = (int) $fieldInfos['max-repeat']; + $field->result = $fieldInfos['result']; + $field->type = $fieldInfos['type']; + if ($fieldInfos['not-empty'] === 'yes') { + $field->validationRules[FileMaker::RULE_NOTEMPTY] = true; + $field->validationMask |= FileMaker::RULE_NOTEMPTY; + } + if ($fieldInfos['numeric-only'] === 'yes') { + $field->validationRules[FileMaker::RULE_NUMERICONLY] = true; + $field->validationMask |= FileMaker::RULE_NUMERICONLY; + } + if (array_key_exists('max-characters', $fieldInfos)) { + $field->maxCharacters = (int) $fieldInfos['max-characters']; + $field->validationRules[FileMaker::RULE_MAXCHARACTERS] = true; + $field->validationMask |= FileMaker::RULE_MAXCHARACTERS; + } + if ($fieldInfos['four-digit-year'] === 'yes') { + $field->validationRules[FileMaker::RULE_FOURDIGITYEAR] = true; + $field->validationMask |= FileMaker::RULE_FOURDIGITYEAR; + } + if ($fieldInfos['time-of-day'] === 'yes') { + $field->validationRules[FileMaker::RULE_TIMEOFDAY] = true; + $field->validationMask |= FileMaker::RULE_TIMEOFDAY; + } + if ($fieldInfos['four-digit-year'] === 'no' && $fieldInfos['result'] === 'timestamp') { + $field->validationRules[FileMaker::RULE_TIMESTAMP_FIELD] = true; + $field->validationMask |= FileMaker::RULE_TIMESTAMP_FIELD; + } + if ($fieldInfos['four-digit-year'] === 'no' && $fieldInfos['result'] === 'date') { + $field->validationRules[FileMaker::RULE_DATE_FIELD] = true; + $field->validationMask |= FileMaker::RULE_DATE_FIELD; + } + if ($fieldInfos['time-of-day'] === 'no' && $fieldInfos['result'] === 'time') { + $field->validationRules[FileMaker::RULE_TIME_FIELD] = true; + $field->validationMask |= FileMaker::RULE_TIME_FIELD; + } + $layout->fields[$field->getName()] = $field; + } + foreach ($this->_relatedSetNames as $relatedSetName => $fields) { + $relatedSet = new RelatedSet($layout); + $relatedSet->name = $relatedSetName; + foreach ($fields as $fieldInfos) { + $field = new Field($layout); + $field->name = $fieldInfos['name']; + $field->autoEntered = (bool) ($fieldInfos['auto-enter'] === 'yes'); + $field->global = (bool) ($fieldInfos['global'] === 'yes'); + $field->maxRepeat = (int) $fieldInfos['max-repeat']; + $field->result = $fieldInfos['result']; + $field->type = $fieldInfos['type']; + if ($fieldInfos['not-empty'] === 'yes') { + $field->validationRules[FileMaker::RULE_NOTEMPTY] = true; + $field->validationMask |= FileMaker::RULE_NOTEMPTY; + } + if ($fieldInfos['numeric-only'] === 'yes') { + $field->validationRules[FileMaker::RULE_NUMERICONLY] = true; + $field->validationMask |= FileMaker::RULE_NUMERICONLY; + } + if (array_key_exists('max-characters', $fieldInfos)) { + $field->maxCharacters = (int) $fieldInfos['max-characters']; + $field->validationRules[FileMaker::RULE_MAXCHARACTERS] = true; + $field->validationMask |= FileMaker::RULE_MAXCHARACTERS; + } + if ($fieldInfos['four-digit-year'] === 'yes') { + $field->validationRules[FileMaker::RULE_FOURDIGITYEAR] = true; + $field->validationMask |= FileMaker::RULE_FOURDIGITYEAR; + } + if ($fieldInfos['time-of-day'] === 'yes' || $fieldInfos['result'] === 'time') { + $field->validationRules[FileMaker::RULE_TIMEOFDAY] = true; + $field->validationMask |= FileMaker::RULE_TIMEOFDAY; + } + if ($fieldInfos['four-digit-year'] === 'no' && $fieldInfos['result'] === 'timestamp') { + $field->validationRules[FileMaker::RULE_TIMESTAMP_FIELD] = true; + $field->validationMask |= FileMaker::RULE_TIMESTAMP_FIELD; + } + if ($fieldInfos['four-digit-year'] === 'no' && $fieldInfos['result'] === 'date') { + $field->validationRules[FileMaker::RULE_DATE_FIELD] = true; + $field->validationMask |= FileMaker::RULE_DATE_FIELD; + } + if ($fieldInfos['time-of-day'] === 'no' && $fieldInfos['result'] === 'time') { + $field->validationRules[FileMaker::RULE_TIME_FIELD] = true; + $field->validationMask |= FileMaker::RULE_TIME_FIELD; + } + $relatedSet->fields[$field->getName()] = $field; + } + $layout->relatedSets[$relatedSet->getName()] = $relatedSet; + } + $this->_layout = $layout; + return true; + } + /** + * xml_parser start element handler + * + * @param resource $parser + * @param string $tag + * @param array $datas + */ + private function _start($parser, $tag, $datas) + { + $datas = $this->_fm->toOutputCharset($datas); + switch ($tag) { + case 'error': + $this->_errorCode = $datas['code']; + break; + case 'product': + $this->_serverVersion = $datas; + break; + case 'datasource': + $this->_parsedHead = $datas; + break; + case 'relatedset-definition': + $this->_relatedSetNames[$datas['table']] = []; + $this->_currentRelatedSet = $datas['table']; + break; + case 'field-definition': + if ($this->_currentRelatedSet) { + $this->_relatedSetNames[$this->_currentRelatedSet][] = $datas; + } else { + $this->_fieldList[] = $datas; + } + break; + case 'resultset': + $this->_parsedFoundSet = $datas; + break; + case 'relatedset': + $this->_currentRelatedSet = $datas['table']; + $this->_parentRecord = $this->_currentRecord; + $this->_parentRecord['children'][$this->_currentRelatedSet] = array(); + $this->_currentRecord = null; + break; + case 'record': + $this->_currentRecord = array( + 'record-id' => $datas['record-id'], + 'mod-id' => $datas['mod-id'], + 'fields' => array(), + 'children' => array(), + ); + break; + case 'field': + $this->_currentField = $datas['name']; + $this->_currentRecord['fields'][$this->_currentField] = array(); + break; + case 'data': + $this->_cdata = ''; + break; + } + } + + /** + * xml_parser end element handler + * + * @param mixed $parser + * @param string $tag + */ + private function _end($parser, $tag) + { + switch ($tag) { + case 'relatedset-definition': + $this->_currentRelatedSet = null; + break; + case 'relatedset': + $this->_currentRelatedSet = null; + $this->_currentRecord = $this->_parentRecord; + $this->_parentRecord = null; + break; + case 'record': + if ($this->_currentRelatedSet) { + $this->_parentRecord['children'][$this->_currentRelatedSet][] = $this->_currentRecord; + } else { + $this->parsedResult[] = $this->_currentRecord; + } + $this->_currentRecord = null; + break; + case 'field': + $this->_currentField = null; + break; + case 'data': + $this->_currentRecord['fields'][$this->_currentField][] = $this->_cdata; + $this->_cdata = null; + break; + } + } + + /** + * xml_parser character data handler (cdata) + * + * @param resource $parser + * @param string $data + */ + private function _cdata($parser, $data) + { + $this->_cdata .= $this->_fm->toOutputCharset($data); + } +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 72117a9..cef7a7e 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,4 +1,4 @@ object = new Add; + protected function setUp() + { + $this->object = new Add(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\Add::execute + * @covers \airmoi\FileMaker\Command\Add::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Add::setField + * @covers \airmoi\FileMaker\Command\Add::setField * @todo Implement testSetField(). */ - public function testSetField() { + public function testSetField() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Add::setFieldFromTimestamp + * @covers \airmoi\FileMaker\Command\Add::setFieldFromTimestamp * @todo Implement testSetFieldFromTimestamp(). */ - public function testSetFieldFromTimestamp() { + public function testSetFieldFromTimestamp() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/CommandTest.php b/tests/src/Command/CommandTest.php index a7fe681..537a76e 100644 --- a/tests/src/Command/CommandTest.php +++ b/tests/src/Command/CommandTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:49. */ -class CommandTest extends \PHPUnit_Framework_TestCase { +class CommandTest extends \PHPUnit_Framework_TestCase +{ /** * @var Command @@ -16,7 +17,8 @@ class CommandTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new Command; } @@ -24,107 +26,115 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\Command::setResultLayout + * @covers \airmoi\FileMaker\Command\Command::setResultLayout * @todo Implement testSetResultLayout(). */ - public function testSetResultLayout() { + public function testSetResultLayout() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Command::setScript + * @covers \airmoi\FileMaker\Command\Command::setScript * @todo Implement testSetScript(). */ - public function testSetScript() { + public function testSetScript() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Command::setPreCommandScript + * @covers \airmoi\FileMaker\Command\Command::setPreCommandScript * @todo Implement testSetPreCommandScript(). */ - public function testSetPreCommandScript() { + public function testSetPreCommandScript() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Command::setPreSortScript + * @covers \airmoi\FileMaker\Command\Command::setPreSortScript * @todo Implement testSetPreSortScript(). */ - public function testSetPreSortScript() { + public function testSetPreSortScript() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Command::setRecordClass + * @covers \airmoi\FileMaker\Command\Command::setRecordClass * @todo Implement testSetRecordClass(). */ - public function testSetRecordClass() { + public function testSetRecordClass() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Command::validate + * @covers \airmoi\FileMaker\Command\Command::validate * @todo Implement testValidate(). */ - public function testValidate() { + public function testValidate() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Command::execute + * @covers \airmoi\FileMaker\Command\Command::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Command::setRecordId + * @covers \airmoi\FileMaker\Command\Command::setRecordId * @todo Implement testSetRecordId(). */ - public function testSetRecordId() { + public function testSetRecordId() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Command::setGlobal + * @covers \airmoi\FileMaker\Command\Command::setGlobal * @todo Implement testSetGlobal(). */ - public function testSetGlobal() { + public function testSetGlobal() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/CompoundFindTest.php b/tests/src/Command/CompoundFindTest.php index 8e3e5bb..8f78b06 100644 --- a/tests/src/Command/CompoundFindTest.php +++ b/tests/src/Command/CompoundFindTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 20:40:05. */ -class CompoundFindTest extends \PHPUnit_Framework_TestCase { +class CompoundFindTest extends \PHPUnit_Framework_TestCase +{ /** * @var CompoundFind @@ -16,7 +17,8 @@ class CompoundFindTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new CompoundFind; } @@ -24,129 +26,139 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\CompoundFind::add + * @covers \airmoi\FileMaker\Command\CompoundFind::add * @todo Implement testAdd(). */ - public function testAdd() { + public function testAdd() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::addSortRule + * @covers \airmoi\FileMaker\Command\CompoundFind::addSortRule * @todo Implement testAddSortRule(). */ - public function testAddSortRule() { + public function testAddSortRule() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::clearSortRules + * @covers \airmoi\FileMaker\Command\CompoundFind::clearSortRules * @todo Implement testClearSortRules(). */ - public function testClearSortRules() { + public function testClearSortRules() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::execute + * @covers \airmoi\FileMaker\Command\CompoundFind::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::setRange + * @covers \airmoi\FileMaker\Command\CompoundFind::setRange * @todo Implement testSetRange(). */ - public function testSetRange() { + public function testSetRange() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::getRange + * @covers \airmoi\FileMaker\Command\CompoundFind::getRange * @todo Implement testGetRange(). */ - public function testGetRange() { + public function testGetRange() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::setRelatedSetsFilters + * @covers \airmoi\FileMaker\Command\CompoundFind::setRelatedSetsFilters * @todo Implement testSetRelatedSetsFilters(). */ - public function testSetRelatedSetsFilters() { + public function testSetRelatedSetsFilters() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::getRelatedSetsFilters + * @covers \airmoi\FileMaker\Command\CompoundFind::getRelatedSetsFilters * @todo Implement testGetRelatedSetsFilters(). */ - public function testGetRelatedSetsFilters() { + public function testGetRelatedSetsFilters() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::_setRelatedSetsFilters + * @covers \airmoi\FileMaker\Command\CompoundFind::_setRelatedSetsFilters * @todo Implement test_setRelatedSetsFilters(). */ - public function test_setRelatedSetsFilters() { + public function test_setRelatedSetsFilters() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::_setSortParams + * @covers \airmoi\FileMaker\Command\CompoundFind::_setSortParams * @todo Implement test_setSortParams(). */ - public function test_setSortParams() { + public function test_setSortParams() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\CompoundFind::_setRangeParams + * @covers \airmoi\FileMaker\Command\CompoundFind::_setRangeParams * @todo Implement test_setRangeParams(). */ - public function test_setRangeParams() { + public function test_setRangeParams() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/DeleteTest.php b/tests/src/Command/DeleteTest.php index 5901e3d..7ce0de2 100644 --- a/tests/src/Command/DeleteTest.php +++ b/tests/src/Command/DeleteTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 20:40:05. */ -class DeleteTest extends \PHPUnit_Framework_TestCase { +class DeleteTest extends \PHPUnit_Framework_TestCase +{ /** * @var Delete @@ -16,7 +17,8 @@ class DeleteTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new Delete; } @@ -24,19 +26,19 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\Delete::execute + * @covers \airmoi\FileMaker\Command\Delete::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/DuplicateTest.php b/tests/src/Command/DuplicateTest.php index afc089d..5a09f3b 100644 --- a/tests/src/Command/DuplicateTest.php +++ b/tests/src/Command/DuplicateTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 20:40:05. */ -class DuplicateTest extends \PHPUnit_Framework_TestCase { +class DuplicateTest extends \PHPUnit_Framework_TestCase +{ /** * @var Duplicate @@ -16,7 +17,8 @@ class DuplicateTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new Duplicate; } @@ -24,19 +26,19 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\Duplicate::execute + * @covers \airmoi\FileMaker\Command\Duplicate::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/EditTest.php b/tests/src/Command/EditTest.php index ea76154..7b49059 100644 --- a/tests/src/Command/EditTest.php +++ b/tests/src/Command/EditTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 20:40:04. */ -class EditTest extends \PHPUnit_Framework_TestCase { +class EditTest extends \PHPUnit_Framework_TestCase +{ /** * @var Edit @@ -16,7 +17,8 @@ class EditTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new Edit; } @@ -24,63 +26,67 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\Edit::execute + * @covers \airmoi\FileMaker\Command\Edit::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Edit::setField + * @covers \airmoi\FileMaker\Command\Edit::setField * @todo Implement testSetField(). */ - public function testSetField() { + public function testSetField() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Edit::setFieldFromTimestamp + * @covers \airmoi\FileMaker\Command\Edit::setFieldFromTimestamp * @todo Implement testSetFieldFromTimestamp(). */ - public function testSetFieldFromTimestamp() { + public function testSetFieldFromTimestamp() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Edit::setModificationId + * @covers \airmoi\FileMaker\Command\Edit::setModificationId * @todo Implement testSetModificationId(). */ - public function testSetModificationId() { + public function testSetModificationId() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Edit::setDeleteRelated + * @covers \airmoi\FileMaker\Command\Edit::setDeleteRelated * @todo Implement testSetDeleteRelated(). */ - public function testSetDeleteRelated() { + public function testSetDeleteRelated() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/FindAllTest.php b/tests/src/Command/FindAllTest.php index 6d3c9bc..75cdf3c 100644 --- a/tests/src/Command/FindAllTest.php +++ b/tests/src/Command/FindAllTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 20:40:05. */ -class FindAllTest extends \PHPUnit_Framework_TestCase { +class FindAllTest extends \PHPUnit_Framework_TestCase +{ /** * @var FindAll @@ -16,7 +17,8 @@ class FindAllTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new FindAll; } @@ -24,19 +26,19 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\FindAll::execute + * @covers \airmoi\FileMaker\Command\FindAll::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/FindAnyTest.php b/tests/src/Command/FindAnyTest.php index 4e97274..2bccc19 100644 --- a/tests/src/Command/FindAnyTest.php +++ b/tests/src/Command/FindAnyTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 20:40:04. */ -class FindAnyTest extends \PHPUnit_Framework_TestCase { +class FindAnyTest extends \PHPUnit_Framework_TestCase +{ /** * @var FindAny @@ -16,7 +17,8 @@ class FindAnyTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new FindAny; } @@ -24,19 +26,19 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\FindAny::execute + * @covers \airmoi\FileMaker\Command\FindAny::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/FindRequestTest.php b/tests/src/Command/FindRequestTest.php index e1d8655..792a3c6 100644 --- a/tests/src/Command/FindRequestTest.php +++ b/tests/src/Command/FindRequestTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:49. */ -class FindRequestTest extends \PHPUnit_Framework_TestCase { +class FindRequestTest extends \PHPUnit_Framework_TestCase +{ /** * @var FindRequest @@ -16,7 +17,8 @@ class FindRequestTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new FindRequest; } @@ -24,52 +26,55 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\FindRequest::setOmit + * @covers \airmoi\FileMaker\Command\FindRequest::setOmit * @todo Implement testSetOmit(). */ - public function testSetOmit() { + public function testSetOmit() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\FindRequest::addFindCriterion + * @covers \airmoi\FileMaker\Command\FindRequest::addFindCriterion * @todo Implement testAddFindCriterion(). */ - public function testAddFindCriterion() { + public function testAddFindCriterion() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\FindRequest::clearFindCriteria + * @covers \airmoi\FileMaker\Command\FindRequest::clearFindCriteria * @todo Implement testClearFindCriteria(). */ - public function testClearFindCriteria() { + public function testClearFindCriteria() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\FindRequest::isEmpty + * @covers \airmoi\FileMaker\Command\FindRequest::isEmpty * @todo Implement testIsEmpty(). */ - public function testIsEmpty() { + public function testIsEmpty() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/FindTest.php b/tests/src/Command/FindTest.php index e030182..0d0471d 100644 --- a/tests/src/Command/FindTest.php +++ b/tests/src/Command/FindTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 20:40:05. */ -class FindTest extends \PHPUnit_Framework_TestCase { +class FindTest extends \PHPUnit_Framework_TestCase +{ /** * @var Find @@ -16,7 +17,8 @@ class FindTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new Find; } @@ -24,118 +26,127 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\Find::addFindCriterion + * @covers \airmoi\FileMaker\Command\Find::addFindCriterion * @todo Implement testAddFindCriterion(). */ - public function testAddFindCriterion() { + public function testAddFindCriterion() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Find::clearFindCriteria + * @covers \airmoi\FileMaker\Command\Find::clearFindCriteria * @todo Implement testClearFindCriteria(). */ - public function testClearFindCriteria() { + public function testClearFindCriteria() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Find::addSortRule + * @covers \airmoi\FileMaker\Command\Find::addSortRule * @todo Implement testAddSortRule(). */ - public function testAddSortRule() { + public function testAddSortRule() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Find::clearSortRules + * @covers \airmoi\FileMaker\Command\Find::clearSortRules * @todo Implement testClearSortRules(). */ - public function testClearSortRules() { + public function testClearSortRules() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Find::execute + * @covers \airmoi\FileMaker\Command\Find::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Find::setLogicalOperator + * @covers \airmoi\FileMaker\Command\Find::setLogicalOperator * @todo Implement testSetLogicalOperator(). */ - public function testSetLogicalOperator() { + public function testSetLogicalOperator() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Find::setRange + * @covers \airmoi\FileMaker\Command\Find::setRange * @todo Implement testSetRange(). */ - public function testSetRange() { + public function testSetRange() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Find::getRange + * @covers \airmoi\FileMaker\Command\Find::getRange * @todo Implement testGetRange(). */ - public function testGetRange() { + public function testGetRange() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Find::setRelatedSetsFilters + * @covers \airmoi\FileMaker\Command\Find::setRelatedSetsFilters * @todo Implement testSetRelatedSetsFilters(). */ - public function testSetRelatedSetsFilters() { + public function testSetRelatedSetsFilters() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\Find::getRelatedSetsFilters + * @covers \airmoi\FileMaker\Command\Find::getRelatedSetsFilters * @todo Implement testGetRelatedSetsFilters(). */ - public function testGetRelatedSetsFilters() { + public function testGetRelatedSetsFilters() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Command/PerformScriptTest.php b/tests/src/Command/PerformScriptTest.php index eb97cb8..6bccbc8 100644 --- a/tests/src/Command/PerformScriptTest.php +++ b/tests/src/Command/PerformScriptTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 20:40:06. */ -class PerformScriptTest extends \PHPUnit_Framework_TestCase { +class PerformScriptTest extends \PHPUnit_Framework_TestCase +{ /** * @var PerformScript @@ -16,7 +17,8 @@ class PerformScriptTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new PerformScript; } @@ -24,41 +26,43 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Command\PerformScript::setRange + * @covers \airmoi\FileMaker\Command\PerformScript::setRange * @todo Implement testSetRange(). */ - public function testSetRange() { + public function testSetRange() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\PerformScript::getRange + * @covers \airmoi\FileMaker\Command\PerformScript::getRange * @todo Implement testGetRange(). */ - public function testGetRange() { + public function testGetRange() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Command\PerformScript::execute + * @covers \airmoi\FileMaker\Command\PerformScript::execute * @todo Implement testExecute(). */ - public function testExecute() { + public function testExecute() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/FileMakerExceptionTest.php b/tests/src/FileMakerExceptionTest.php index 284b39e..d829923 100644 --- a/tests/src/FileMakerExceptionTest.php +++ b/tests/src/FileMakerExceptionTest.php @@ -7,16 +7,17 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:51. */ -class FileMakerExceptionTest extends \PHPUnit_Framework_TestCase { +class FileMakerExceptionTest extends \PHPUnit_Framework_TestCase +{ /** * @var FileMakerException */ protected $fm; - + /** * - * @var array + * @var array */ protected $locales; @@ -24,41 +25,43 @@ class FileMakerExceptionTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->fm = new FileMaker($GLOBALS['DB_FILE'], $GLOBALS['DB_HOST'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']); - $this->locales = require (dirname(__FILE__) . '/../../src/Error/en.php'); + $this->locales = require(dirname(__FILE__) . '/../../src/Error/en.php'); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\FileMakerException::getErrorString + * @covers \airmoi\FileMaker\FileMakerException::getErrorString */ - public function testGetErrorString() { - $exception = new FileMakerException($this->fm, null , 0); + public function testGetErrorString() + { + $exception = new FileMakerException($this->fm, null, 0); $this->assertEquals($this->locales[0], $exception->getErrorString(0)); - + $this->assertEquals($this->locales[15], $exception->getErrorString(15)); - + $this->assertEquals($this->locales[-1], $exception->getErrorString(-5)); - + $this->assertEquals($this->locales[-1], $exception->getErrorString(155555)); - + $this->assertEquals($this->locales[-1], $exception->getErrorString(null)); } /** - * @covers airmoi\FileMaker\FileMakerException::isValidationError + * @covers \airmoi\FileMaker\FileMakerException::isValidationError */ - public function testIsValidationError() { - $exception = new FileMakerException($this->fm, null , 0); + public function testIsValidationError() + { + $exception = new FileMakerException($this->fm, null, 0); $this->assertFalse($exception->isValidationError()); } - } diff --git a/tests/src/FileMakerTest.php b/tests/src/FileMakerTest.php index 71ac756..a1ab40a 100644 --- a/tests/src/FileMakerTest.php +++ b/tests/src/FileMakerTest.php @@ -7,20 +7,22 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:41:41. */ -class FileMakerTest extends \PHPUnit_Framework_TestCase { +class FileMakerTest extends \PHPUnit_Framework_TestCase +{ /** * @var FileMaker */ protected $fm; - + protected $_recid; /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->fm = new FileMaker($GLOBALS['DB_FILE'], $GLOBALS['DB_HOST'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']); } @@ -28,42 +30,46 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\FileMaker::listDatabases + * @covers \airmoi\FileMaker\FileMaker::listDatabases */ - public function testListDatabases() { + public function testListDatabases() + { $databases = $this->fm->listDatabases(); $this->assertTrue(is_array($databases)); - + $this->assertTrue(in_array($GLOBALS['DB_FILE'], $databases, 'Database ' . $GLOBALS['DB_FILE'] . ' is missing. Test can\'t run')); } /** - * @covers airmoi\FileMaker\FileMaker::listLayouts + * @covers \airmoi\FileMaker\FileMaker::listLayouts */ - public function testListLayouts() { + public function testListLayouts() + { $layouts = $this->fm->listLayouts(); $this->assertTrue(in_array('sample', $layouts)); } /** - * @covers airmoi\FileMaker\FileMaker::getLayout + * @covers \airmoi\FileMaker\FileMaker::getLayout */ - public function testGetLayout() { + public function testGetLayout() + { $layout = $this->fm->getLayout('sample'); $this->assertInstanceOf(\airmoi\FileMaker\Object\Layout::class, $layout); - + $this->assertEquals('sample', $layout->getName(), 'Layout name missmatch (' . $layout->table . ')'); } /** - * @covers airmoi\FileMaker\FileMaker::isError + * @covers \airmoi\FileMaker\FileMaker::isError */ - public function testIsError() { + public function testIsError() + { $error = new \airmoi\FileMaker\FileMakerException($this->fm, 'Test FileMaker exception'); $record = new \airmoi\FileMaker\Object\Record(new \airmoi\FileMaker\Object\Layout($this->fm)); @@ -72,17 +78,19 @@ public function testIsError() { } /** - * @covers airmoi\FileMaker\FileMaker::getMinServerVersion + * @covers \airmoi\FileMaker\FileMaker::getMinServerVersion */ - public function testGetMinServerVersion() { + public function testGetMinServerVersion() + { // Remove the following lines when you implement this test. $this->assertStringMatchesFormat('%d.%d.%d.%d', $this->fm->getMinServerVersion()); } /** - * @covers airmoi\FileMaker\FileMaker::setProperty + * @covers \airmoi\FileMaker\FileMaker::setProperty */ - public function testSetProperty() { + public function testSetProperty() + { $this->fm->setProperty('logLevel', FileMaker::LOG_INFO); //Test valid property @@ -93,252 +101,267 @@ public function testSetProperty() { } /** - * @covers airmoi\FileMaker\FileMaker::getProperty + * @covers \airmoi\FileMaker\FileMaker::getProperty */ - public function testGetProperty() { + public function testGetProperty() + { $this->assertEquals('en', $this->fm->getProperty('locale')); } /** - * @covers airmoi\FileMaker\FileMaker::getProperties + * @covers \airmoi\FileMaker\FileMaker::getProperties */ - public function testGetProperties() { + public function testGetProperties() + { $this->assertArrayHasKey('locale', $this->fm->getProperties()); } /** - * @covers airmoi\FileMaker\FileMaker::setLogger + * @covers \airmoi\FileMaker\FileMaker::setLogger * @todo Implement testSetLogger(). */ - public function testSetLogger() { + public function testSetLogger() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\FileMaker::newAddCommand + * @covers \airmoi\FileMaker\FileMaker::newAddCommand */ - public function testNewAddCommand() { + public function testNewAddCommand() + { $command = $this->fm->newAddCommand('sample', ['text_field' => 'Test 1']); $this->assertInstanceOf(\airmoi\FileMaker\Command\Add::class, $command); - + $command->setField('date_field', date('m/d/Y')); - + $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - + $record = $result->getFirstRecord(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Record::class, $record); - + $this->assertEquals('Test 1', $record->getField('text_field')); - + return ['recid' => $record->getRecordId(), 'tableCount' => $result->tableCount]; } /** - * @covers airmoi\FileMaker\FileMaker::newEditCommand + * @covers \airmoi\FileMaker\FileMaker::newEditCommand * @depends testNewAddCommand */ - public function testNewEditCommand($datas) { + public function testNewEditCommand($datas) + { $command = $this->fm->newEditCommand('sample', $datas['recid'], ['text_field' => 'Test 2']); $this->assertInstanceOf(\airmoi\FileMaker\Command\Edit::class, $command); - + $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - + $record = $result->getFirstRecord(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Record::class, $record); - + $this->assertEquals('Test 2', $record->getField('text_field')); } /** - * @covers airmoi\FileMaker\FileMaker::newDuplicateCommand + * @covers \airmoi\FileMaker\FileMaker::newDuplicateCommand * @depends testNewAddCommand */ - public function testNewDuplicateCommand($datas) { + public function testNewDuplicateCommand($datas) + { $command = $this->fm->newDuplicateCommand('sample', $datas['recid']); $this->assertInstanceOf(\airmoi\FileMaker\Command\Duplicate::class, $command); - + $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - + $record = $result->getFirstRecord(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Record::class, $record); - + $this->assertEquals('Test 2', $record->getField('text_field')); $this->assertNotEquals($datas['recid'], $record->getRecordId()); } /** - * @covers airmoi\FileMaker\FileMaker::newDeleteCommand + * @covers \airmoi\FileMaker\FileMaker::newDeleteCommand * @depends testNewAddCommand */ - public function testNewDeleteCommand($datas) { + public function testNewDeleteCommand($datas) + { $command = $this->fm->newDeleteCommand('sample', $datas['recid']); $this->assertInstanceOf(\airmoi\FileMaker\Command\Delete::class, $command); - + $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - - $this->assertEquals($datas['tableCount'] , (int)$result->tableCount); + + $this->assertEquals($datas['tableCount'], (int)$result->tableCount); } /** - * @covers airmoi\FileMaker\FileMaker::listScripts + * @covers \airmoi\FileMaker\FileMaker::listScripts */ - public function testListScripts() { + public function testListScripts() + { $scripts = $this->fm->listScripts(); - $this->assertTrue( in_array('cleanup db', $scripts ) ); + $this->assertTrue(in_array('cleanup db', $scripts)); } /** - * @covers airmoi\FileMaker\FileMaker::newPerformScriptCommand + * @covers \airmoi\FileMaker\FileMaker::newPerformScriptCommand * @depends testNewAddCommand */ - public function testNewPerformScriptCommand() { + public function testNewPerformScriptCommand() + { $command = $this->fm->newPerformScriptCommand('sample', 'cleanup db'); $this->assertInstanceOf(\airmoi\FileMaker\Command\PerformScript::class, $command); - + $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - - $this->assertEquals( 0 , (int)$result->tableCount); - - $command = $this->fm->newPerformScriptCommand('sample', 'create sample data', 50 ); + + $this->assertEquals(0, (int)$result->tableCount); + + $command = $this->fm->newPerformScriptCommand('sample', 'create sample data', 50); $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - $this->assertEquals( 50 , (int)$result->tableCount); - + $this->assertEquals(50, (int)$result->tableCount); + $this->assertRegExp('#(http:\/\/|https:\/\/)?[^:\/]*(:\d{2})?\/fmi\/xml\/fmresultset\.xml\?-db=[^\&]*\&-lay=[^\&]*\&-script=[^\&]*\&-script.param=[^\&]*\&-findany#', $this->fm->lastRequestedUrl); - } /** - * @covers airmoi\FileMaker\FileMaker::newFindAnyCommand + * @covers \airmoi\FileMaker\FileMaker::newFindAnyCommand * @todo Implement testNewFindAnyCommand(). */ - public function testNewFindAnyCommand() { + public function testNewFindAnyCommand() + { $command =$this->fm->newFindAnyCommand('sample'); $this->assertInstanceOf(\airmoi\FileMaker\Command\FindAny::class, $command); - + $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - + $this->assertEquals(1, $result->getFoundSetCount()); - } /** - * @covers airmoi\FileMaker\FileMaker::newFindCommand + * @covers \airmoi\FileMaker\FileMaker::newFindCommand */ - public function testNewFindCommand() { + public function testNewFindCommand() + { $command = $this->fm->newFindCommand('sample'); $this->assertInstanceOf(\airmoi\FileMaker\Command\Find::class, $command); - + $command->addFindCriterion('id', FileMaker::FIND_GT . '25'); $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - + $this->assertEquals(25, $result->getFoundSetCount()); - } /** - * @covers airmoi\FileMaker\FileMaker::newCompoundFindCommand + * @covers \airmoi\FileMaker\FileMaker::newCompoundFindCommand */ - public function testNewCompoundFindCommand() { + public function testNewCompoundFindCommand() + { $command = $this->fm->newCompoundFindCommand('sample'); $this->assertInstanceOf(\airmoi\FileMaker\Command\CompoundFind::class, $command); - + $request1 = $this->fm->newFindRequest('sample'); $this->assertInstanceOf(\airmoi\FileMaker\Command\FindRequest::class, $request1); - + $request1->addFindCriterion('id', "1...10"); $command->add(1, $request1); - + $request2 = $this->fm->newFindRequest('sample'); $this->assertInstanceOf(\airmoi\FileMaker\Command\FindRequest::class, $request2); - + $request2->addFindCriterion('id', "40...50"); $command->add(2, $request2); - + $request3 = $this->fm->newFindRequest('sample'); $this->assertInstanceOf(\airmoi\FileMaker\Command\FindRequest::class, $request3); - + $request3->addFindCriterion('id', "45"); $request3->setOmit(true); $command->add(3, $request3); - + $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - + $this->assertEquals(20, $result->getFoundSetCount()); } /** - * @covers airmoi\FileMaker\FileMaker::newFindAllCommand + * @covers \airmoi\FileMaker\FileMaker::newFindAllCommand */ - public function testNewFindAllCommand() { + public function testNewFindAllCommand() + { $command =$this->fm->newFindAllCommand('sample'); $this->assertInstanceOf(\airmoi\FileMaker\Command\FindAll::class, $command); - + $result = $command->execute(); $this->assertInstanceOf(\airmoi\FileMaker\Object\Result::class, $result); - + $this->assertEquals(50, $result->getFoundSetCount()); } /** - * @covers airmoi\FileMaker\FileMaker::createRecord + * @covers \airmoi\FileMaker\FileMaker::createRecord */ - public function testCreateRecord() { + public function testCreateRecord() + { $record = $this->fm->createRecord('sample', [ 'text_field' => __METHOD__]); $this->assertInstanceOf(\airmoi\FileMaker\Object\Record::class, $record); - + $result = $record->commit(); - + $this->assertTrue($result); return $record->getRecordId(); } /** - * @covers airmoi\FileMaker\FileMaker::getRecordById + * @covers \airmoi\FileMaker\FileMaker::getRecordById * @depends testCreateRecord */ - public function testGetRecordById($recId) { + public function testGetRecordById($recId) + { $record = $this->fm->getRecordById('sample', $recId); $this->assertInstanceOf(\airmoi\FileMaker\Object\Record::class, $record); - + $this->assertStringEndsWith('testCreateRecord', $record->getField('text_field')); $this->fm->newDeleteCommand('sample', $record->getRecordId())->execute(); } /** - * @covers airmoi\FileMaker\FileMaker::getContainerData + * @covers \airmoi\FileMaker\FileMaker::getContainerData */ - public function testGetContainerData() { + public function testGetContainerData() + { $record = $this->fm->newFindAnyCommand('sample')->execute()->getFirstRecord(); - + $datas = $this->fm->getContainerData($record->getField('container_field')); $this->assertEquals(18556, strlen($datas)); } /** - * @covers airmoi\FileMaker\FileMaker::getContainerDataURL + * @covers \airmoi\FileMaker\FileMaker::getContainerDataURL */ - public function testGetContainerDataURL() { + public function testGetContainerDataURL() + { $record = $this->fm->newFindAnyCommand('sample')->execute()->getFirstRecord(); - + $url = $this->fm->getContainerDataURL($record->getField('container_field')); $this->assertStringEndsWith('/fmi/xml/cnt/fms.png?-db=filemaker-test&-lay=sample&-recid='.$record->getRecordId().'&-field=container_field(1)', $url); } /** - * @covers airmoi\FileMaker\FileMaker::__set + * @covers \airmoi\FileMaker\FileMaker::__set */ - public function test__set() { + public function test__set() + { $this->fm->logLevel = 5; $this->assertEquals(5, $this->fm->getProperty('logLevel')); try { @@ -348,13 +371,14 @@ public function test__set() { } /** - * @covers airmoi\FileMaker\FileMaker::toOutputCharset + * @covers \airmoi\FileMaker\FileMaker::toOutputCharset * @todo Implement testToOutputCharset(). */ - public function testToOutputCharset() { + public function testToOutputCharset() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } } diff --git a/tests/src/FileMakerValidationExceptionTest.php b/tests/src/FileMakerValidationExceptionTest.php index c37bb77..dc40aa6 100644 --- a/tests/src/FileMakerValidationExceptionTest.php +++ b/tests/src/FileMakerValidationExceptionTest.php @@ -7,75 +7,80 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 20:40:06. */ -class FileMakerValidationExceptionTest extends \PHPUnit_Framework_TestCase { +class FileMakerValidationExceptionTest extends \PHPUnit_Framework_TestCase +{ /** * @var FileMakerValidationException */ protected $object; - + /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->fm = new FileMaker($GLOBALS['DB_FILE'], $GLOBALS['DB_HOST'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']); - $this->locales = require (dirname(__FILE__) . '/../../src/Error/en.php'); + $this->locales = require(dirname(__FILE__) . '/../../src/Error/en.php'); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\FileMakerValidationException::addError + * @covers \airmoi\FileMaker\FileMakerValidationException::addError */ - public function testAddError() { + public function testAddError() + { $exception = new FileMakerValidationException($this->fm); $field = new Object\Field(new Object\Layout($this->fm)); $field->name = "sample_field"; - + $exception->addError($field, FileMaker::RULE_DATE_FIELD, "Incorrect date value"); $this->assertEquals(1, $exception->numErrors()); - + $field2 = new Object\Field(new Object\Layout($this->fm)); $field2->name = "sample_field2"; - + $exception->addError($field2, FileMaker::RULE_NOTEMPTY, null); $this->assertEquals(2, $exception->numErrors()); - + return $exception; } /** - * @covers airmoi\FileMaker\FileMakerValidationException::isValidationError + * @covers \airmoi\FileMaker\FileMakerValidationException::isValidationError */ - public function testIsValidationError() { + public function testIsValidationError() + { $exception = new FileMakerValidationException($this->fm); $this->assertTrue($exception->isValidationError()); } /** - * @covers airmoi\FileMaker\FileMakerValidationException::getErrors + * @covers \airmoi\FileMaker\FileMakerValidationException::getErrors * @depends testAddError */ - public function testGetErrors(FileMakerValidationException $exception) { + public function testGetErrors(FileMakerValidationException $exception) + { $this->assertEquals(2, sizeof($exception->getErrors())); - + $this->assertEquals(FileMaker::RULE_DATE_FIELD, $exception->getErrors('sample_field')[0][1]); } /** - * @covers airmoi\FileMaker\FileMakerValidationException::getErrors + * @covers \airmoi\FileMaker\FileMakerValidationException::getErrors * @depends testAddError */ - public function testGetMessage(FileMakerValidationException $exception) { + public function testGetMessage(FileMakerValidationException $exception) + { $this->assertEquals(2, sizeof(explode("\n", $exception->getMessage()))); } - } diff --git a/tests/src/Object/FieldTest.php b/tests/src/Object/FieldTest.php index 8bf8216..955bebf 100644 --- a/tests/src/Object/FieldTest.php +++ b/tests/src/Object/FieldTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:51. */ -class FieldTest extends \PHPUnit_Framework_TestCase { +class FieldTest extends \PHPUnit_Framework_TestCase +{ /** * @var Field @@ -16,7 +17,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new Field; } @@ -24,283 +26,307 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Object\Field::getName + * @covers \airmoi\FileMaker\Object\Field::getName * @todo Implement testGetName(). */ - public function testGetName() { + public function testGetName() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getLayout + * @covers \airmoi\FileMaker\Object\Field::getLayout * @todo Implement testGetLayout(). */ - public function testGetLayout() { + public function testGetLayout() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::isAutoEntered + * @covers \airmoi\FileMaker\Object\Field::isAutoEntered * @todo Implement testIsAutoEntered(). */ - public function testIsAutoEntered() { + public function testIsAutoEntered() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::isGlobal + * @covers \airmoi\FileMaker\Object\Field::isGlobal * @todo Implement testIsGlobal(). */ - public function testIsGlobal() { + public function testIsGlobal() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getRepetitionCount + * @covers \airmoi\FileMaker\Object\Field::getRepetitionCount * @todo Implement testGetRepetitionCount(). */ - public function testGetRepetitionCount() { + public function testGetRepetitionCount() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::validate + * @covers \airmoi\FileMaker\Object\Field::validate * @todo Implement testValidate(). */ - public function testValidate() { + public function testValidate() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getLocalValidationRules + * @covers \airmoi\FileMaker\Object\Field::getLocalValidationRules * @todo Implement testGetLocalValidationRules(). */ - public function testGetLocalValidationRules() { + public function testGetLocalValidationRules() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getMaxCharacters + * @covers \airmoi\FileMaker\Object\Field::getMaxCharacters * @todo Implement testGetMaxCharacters(). */ - public function testGetMaxCharacters() { + public function testGetMaxCharacters() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getValidationRules + * @covers \airmoi\FileMaker\Object\Field::getValidationRules * @todo Implement testGetValidationRules(). */ - public function testGetValidationRules() { + public function testGetValidationRules() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getValidationMask + * @covers \airmoi\FileMaker\Object\Field::getValidationMask * @todo Implement testGetValidationMask(). */ - public function testGetValidationMask() { + public function testGetValidationMask() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::hasValidationRule + * @covers \airmoi\FileMaker\Object\Field::hasValidationRule * @todo Implement testHasValidationRule(). */ - public function testHasValidationRule() { + public function testHasValidationRule() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::describeValidationRule + * @covers \airmoi\FileMaker\Object\Field::describeValidationRule * @todo Implement testDescribeValidationRule(). */ - public function testDescribeValidationRule() { + public function testDescribeValidationRule() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::describeLocalValidationRules + * @covers \airmoi\FileMaker\Object\Field::describeLocalValidationRules * @todo Implement testDescribeLocalValidationRules(). */ - public function testDescribeLocalValidationRules() { + public function testDescribeLocalValidationRules() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::describeValidationRules + * @covers \airmoi\FileMaker\Object\Field::describeValidationRules * @todo Implement testDescribeValidationRules(). */ - public function testDescribeValidationRules() { + public function testDescribeValidationRules() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getResult + * @covers \airmoi\FileMaker\Object\Field::getResult * @todo Implement testGetResult(). */ - public function testGetResult() { + public function testGetResult() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getType + * @covers \airmoi\FileMaker\Object\Field::getType * @todo Implement testGetType(). */ - public function testGetType() { + public function testGetType() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getValueList + * @covers \airmoi\FileMaker\Object\Field::getValueList * @todo Implement testGetValueList(). */ - public function testGetValueList() { + public function testGetValueList() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::getStyleType + * @covers \airmoi\FileMaker\Object\Field::getStyleType * @todo Implement testGetStyleType(). */ - public function testGetStyleType() { + public function testGetStyleType() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::checkTimeStampFormatFourDigitYear + * @covers \airmoi\FileMaker\Object\Field::checkTimeStampFormatFourDigitYear * @todo Implement testCheckTimeStampFormatFourDigitYear(). */ - public function testCheckTimeStampFormatFourDigitYear() { + public function testCheckTimeStampFormatFourDigitYear() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::checkTimeStampFormat + * @covers \airmoi\FileMaker\Object\Field::checkTimeStampFormat * @todo Implement testCheckTimeStampFormat(). */ - public function testCheckTimeStampFormat() { + public function testCheckTimeStampFormat() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::checkDateFormat + * @covers \airmoi\FileMaker\Object\Field::checkDateFormat * @todo Implement testCheckDateFormat(). */ - public function testCheckDateFormat() { + public function testCheckDateFormat() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::checkTimeFormat + * @covers \airmoi\FileMaker\Object\Field::checkTimeFormat * @todo Implement testCheckTimeFormat(). */ - public function testCheckTimeFormat() { + public function testCheckTimeFormat() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::checkNumericOnly + * @covers \airmoi\FileMaker\Object\Field::checkNumericOnly * @todo Implement testCheckNumericOnly(). */ - public function testCheckNumericOnly() { + public function testCheckNumericOnly() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::checkDateValidity + * @covers \airmoi\FileMaker\Object\Field::checkDateValidity * @todo Implement testCheckDateValidity(). */ - public function testCheckDateValidity() { + public function testCheckDateValidity() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Field::checkTimeValidity + * @covers \airmoi\FileMaker\Object\Field::checkTimeValidity * @todo Implement testCheckTimeValidity(). */ - public function testCheckTimeValidity() { + public function testCheckTimeValidity() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Object/LayoutTest.php b/tests/src/Object/LayoutTest.php index e0e6e63..763dbbb 100644 --- a/tests/src/Object/LayoutTest.php +++ b/tests/src/Object/LayoutTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:51. */ -class LayoutTest extends \PHPUnit_Framework_TestCase { +class LayoutTest extends \PHPUnit_Framework_TestCase +{ /** * @var Layout @@ -16,7 +17,8 @@ class LayoutTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new Layout; } @@ -24,173 +26,187 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Object\Layout::getName + * @covers \airmoi\FileMaker\Object\Layout::getName * @todo Implement testGetName(). */ - public function testGetName() { + public function testGetName() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::getDatabase + * @covers \airmoi\FileMaker\Object\Layout::getDatabase * @todo Implement testGetDatabase(). */ - public function testGetDatabase() { + public function testGetDatabase() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::listFields + * @covers \airmoi\FileMaker\Object\Layout::listFields * @todo Implement testListFields(). */ - public function testListFields() { + public function testListFields() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::getField + * @covers \airmoi\FileMaker\Object\Layout::getField * @todo Implement testGetField(). */ - public function testGetField() { + public function testGetField() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::getFields + * @covers \airmoi\FileMaker\Object\Layout::getFields * @todo Implement testGetFields(). */ - public function testGetFields() { + public function testGetFields() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::listRelatedSets + * @covers \airmoi\FileMaker\Object\Layout::listRelatedSets * @todo Implement testListRelatedSets(). */ - public function testListRelatedSets() { + public function testListRelatedSets() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::getRelatedSet + * @covers \airmoi\FileMaker\Object\Layout::getRelatedSet * @todo Implement testGetRelatedSet(). */ - public function testGetRelatedSet() { + public function testGetRelatedSet() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::hasRelatedSet + * @covers \airmoi\FileMaker\Object\Layout::hasRelatedSet * @todo Implement testHasRelatedSet(). */ - public function testHasRelatedSet() { + public function testHasRelatedSet() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::getRelatedSets + * @covers \airmoi\FileMaker\Object\Layout::getRelatedSets * @todo Implement testGetRelatedSets(). */ - public function testGetRelatedSets() { + public function testGetRelatedSets() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::listValueLists + * @covers \airmoi\FileMaker\Object\Layout::listValueLists * @todo Implement testListValueLists(). */ - public function testListValueLists() { + public function testListValueLists() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::getValueList + * @covers \airmoi\FileMaker\Object\Layout::getValueList * @todo Implement testGetValueList(). */ - public function testGetValueList() { + public function testGetValueList() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::getValueListTwoFields + * @covers \airmoi\FileMaker\Object\Layout::getValueListTwoFields * @todo Implement testGetValueListTwoFields(). */ - public function testGetValueListTwoFields() { + public function testGetValueListTwoFields() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::getValueLists + * @covers \airmoi\FileMaker\Object\Layout::getValueLists * @todo Implement testGetValueLists(). */ - public function testGetValueLists() { + public function testGetValueLists() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::getValueListsTwoFields + * @covers \airmoi\FileMaker\Object\Layout::getValueListsTwoFields * @todo Implement testGetValueListsTwoFields(). */ - public function testGetValueListsTwoFields() { + public function testGetValueListsTwoFields() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Layout::loadExtendedInfo + * @covers \airmoi\FileMaker\Object\Layout::loadExtendedInfo * @todo Implement testLoadExtendedInfo(). */ - public function testLoadExtendedInfo() { + public function testLoadExtendedInfo() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Object/RecordTest.php b/tests/src/Object/RecordTest.php index baeabd6..52ad6f7 100644 --- a/tests/src/Object/RecordTest.php +++ b/tests/src/Object/RecordTest.php @@ -3,17 +3,20 @@ namespace airmoi\FileMaker\Object; use airmoi\FileMaker\FileMaker; +use airmoi\FileMaker\FileMakerException; +use airmoi\FileMaker\FileMakerValidationException; /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:51. */ -class RecordTest extends \PHPUnit_Framework_TestCase { +class RecordTest extends \PHPUnit_Framework_TestCase +{ /** * @var FileMaker */ protected $fm; - + /** * * @var Record @@ -24,15 +27,17 @@ class RecordTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->fm = new FileMaker($GLOBALS['DB_FILE'], $GLOBALS['DB_HOST'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']); //$this->fm->newPerformScriptCommand('sample', "create sample data", 50)->execute(); $this->record = $this->fm->newFindAnyCommand('sample')->execute()->getFirstRecord(); } - - public static function setUpBeforeClass(){ + + public static function setUpBeforeClass() + { $fm = new FileMaker($GLOBALS['DB_FILE'], $GLOBALS['DB_HOST'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD']); - $fm->newPerformScriptCommand('sample', "create sample data", 50)->execute(); + $fm->newPerformScriptCommand('sample', 'create sample data', 50)->execute(); //$this->record = $this->fm->newFindAnyCommand('sample')->execute()->getFirstRecord(); } @@ -40,279 +45,293 @@ public static function setUpBeforeClass(){ * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Object\Record::getLayout + * @covers \airmoi\FileMaker\Object\Record::getLayout */ - public function testGetLayout() { + public function testGetLayout() + { $this->assertInstanceOf(Layout::class, $this->record->getLayout()); } /** - * @covers airmoi\FileMaker\Object\Record::getFields + * @covers \airmoi\FileMaker\Object\Record::getFields */ - public function testGetFields() { - $this->assertTrue(in_array('text_field', $this->record->getFields())); + public function testGetFields() + { + $this->assertTrue(in_array('text_field', $this->record->getFields(), true)); } /** - * @covers airmoi\FileMaker\Object\Record::getField + * @covers \airmoi\FileMaker\Object\Record::getField */ - public function testGetField() { - $this->assertStringStartsWith("record #", $this->record->getField('text_field')); - $this->assertStringEndsWith("repeat 2", $this->record->getField('text_field', 1)); - $this->assertStringStartsWith("

", $this->record->getField('text_field', 2, true)); - $this->assertStringStartsWith("<", $this->record->getField('text_field', 2)); + public function testGetField() + { + $this->assertStringStartsWith('record #', $this->record->getField('text_field')); + $this->assertStringEndsWith('repeat 2', $this->record->getField('text_field', 1)); + $this->assertStringStartsWith('

', $this->record->getField('text_field', 2, true)); + $this->assertStringStartsWith('<', $this->record->getField('text_field', 2)); $this->assertEmpty($this->record->getField('text_field', 4)); } /** - * @covers airmoi\FileMaker\Object\Record::getFieldValueListTwoFields + * @covers \airmoi\FileMaker\Object\Record::getFieldValueListTwoFields */ - public function testGetFieldValueListTwoFields() { + public function testGetFieldValueListTwoFields() + { $valueList = $this->record->getFieldValueListTwoFields('id_sample'); - $this->assertEquals(50, sizeof($valueList)); - - $rnd = rand(1,50); + $this->assertEquals(50, count($valueList)); + + $rnd = rand(1, 50); $this->assertEquals($rnd, $valueList[$rnd . ' record #'.$rnd]); } /** - * @covers airmoi\FileMaker\Object\Record::getFieldAsTimestamp + * @covers \airmoi\FileMaker\Object\Record::getFieldAsTimestamp */ - public function testGetFieldAsTimestamp() { + public function testGetFieldAsTimestamp() + { $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); - /*$ts = $this->record->getFieldAsTimestamp("date_field"); - $dt = \DateTime::createFromFormat('U',$this->record->getFieldAsTimestamp("date_field").'.'); - $this->assertEquals( $this->record->getField("date_field") , $dt->format("m/d/Y") ); - $this->assertInstanceOf(\DateTime::class, $this->record->getFieldAsTimestamp("time_field")); - $this->assertInstanceOf(\DateTime::class, $this->record->getFieldAsTimestamp("timestamp_field"));*/ + /*$ts = $this->record->getFieldAsTimestamp('date_field'); + $dt = \DateTime::createFromFormat('U',$this->record->getFieldAsTimestamp('date_field').'.'); + $this->assertEquals( $this->record->getField('date_field') , $dt->format('m/d/Y') ); + $this->assertInstanceOf(\DateTime::class, $this->record->getFieldAsTimestamp('time_field')); + $this->assertInstanceOf(\DateTime::class, $this->record->getFieldAsTimestamp('timestamp_field'));*/ } /** - * @covers airmoi\FileMaker\Object\Record::setField + * @covers \airmoi\FileMaker\Object\Record::setField */ - public function testSetField() { + public function testSetField() + { $this->record->setField('text_field', __METHOD__); $this->assertEquals(__METHOD__, $this->record->getField('text_field')); - - $this->record->setField('text_field', __METHOD__ . " repeat 1", 1); - $this->assertEquals( __METHOD__ . " repeat 1", $this->record->getField('text_field', 1)); - + + $this->record->setField('text_field', __METHOD__ . ' repeat 1', 1); + $this->assertEquals(__METHOD__ . ' repeat 1', $this->record->getField('text_field', 1)); + $this->record->setField('related_sample::text_field', __METHOD__ . 'related[1]'); $this->assertEquals(__METHOD__ . 'related[1]', $this->record->getField('related_sample::text_field')); - - $this->record->setField('related_sample::text_field', __METHOD__ . "related[2]", 1); - $this->assertEquals( __METHOD__ . "related[2]", $this->record->getField('related_sample::text_field', 1)); - + + $this->record->setField('related_sample::text_field', __METHOD__ . 'related[2]', 1); + $this->assertEquals(__METHOD__ . 'related[2]', $this->record->getField('related_sample::text_field', 1)); + $this->record->setField('date_field', date('Y-m-d')); - $this->assertEquals( date('Y-m-d'), $this->record->getField('date_field')); - - $this->assertInstanceOf(\airmoi\FileMaker\FileMakerException::class, $this->record->setField('missing_field', __METHOD__)); - + $this->assertEquals(date('Y-m-d'), $this->record->getField('date_field')); + + $this->assertInstanceOf(FileMakerException::class, $this->record->setField('missing_field', __METHOD__)); + /** * Date autoformat */ $this->fm->setProperty('dateFormat', 'd/m/Y'); - + $this->record->setField('date_field', '16/06/2016'); - $this->assertEquals( '06/16/2016', $this->record->fields['date_field'][0]); - + $this->assertEquals('06/16/2016', $this->record->fields['date_field'][0]); + $this->record->setField('date_field', '01/02/0001'); - $this->assertEquals( '02/01/0001', $this->record->fields['date_field'][0]); - + $this->assertEquals('02/01/0001', $this->record->fields['date_field'][0]); + $this->record->setField('date_field', '31/12/4000'); - $this->assertEquals( '12/31/4000', $this->record->fields['date_field'][0]); - - $this->assertInstanceOf(\airmoi\FileMaker\FileMakerException::class, $this->record->setField('date_field', '2016-08-19')); - + $this->assertEquals('12/31/4000', $this->record->fields['date_field'][0]); + + $this->assertInstanceOf(FileMakerException::class, $this->record->setField('date_field', '2016-08-19')); + $this->record->setField('timestamp_field', '08/01/1942 00:00:00'); - $this->assertEquals( '01/08/1942 00:00:00', $this->record->fields['timestamp_field'][0]); - - $this->assertInstanceOf(\airmoi\FileMaker\FileMakerException::class, $this->record->setField('timestamp_field', '2016-08-19')); - + $this->assertEquals('01/08/1942 00:00:00', $this->record->fields['timestamp_field'][0]); + + $this->assertInstanceOf(FileMakerException::class, $this->record->setField('timestamp_field', '2016-08-19')); } /** - * @covers airmoi\FileMaker\Object\Record::setFieldFromTimestamp + * @covers \airmoi\FileMaker\Object\Record::setFieldFromTimestamp */ - public function testSetFieldFromTimestamp() { - + public function testSetFieldFromTimestamp() + { + /* * Date fields */ $dt = new \DateTime(); - $this->record->setFieldFromTimestamp('date_field', $dt->format('U') ); + $this->record->setFieldFromTimestamp('date_field', $dt->format('U')); $this->assertEquals(date('m/d/Y'), $this->record->getField('date_field')); - + $time = time()+3600; - $this->record->setFieldFromTimestamp('date_field', $time ); + $this->record->setFieldFromTimestamp('date_field', $time); $this->assertEquals(date('m/d/Y', time()+3600), $this->record->getField('date_field')); - + /* * To be activated when setFieldFromTimestamp will implement DateTime */ //$dt = new \DateTime('0001-01-01T00:00:00'); //$this->record->setFieldFromTimestamp('date_field', $dt->format('U') ); //$this->assertEquals('01/01/0001', $this->record->getField('date_field')); - + //$dt = new \DateTime('4000-12-31T23:59:59'); //$this->record->setFieldFromTimestamp('date_field', $dt->format('U') ); //$this->assertEquals('12/31/4000', $this->record->getField('date_field')); - + /* * timestamp fields */ $dt = new \DateTime(); - $this->record->setFieldFromTimestamp('timestamp_field', $dt->format('U') ); + $this->record->setFieldFromTimestamp('timestamp_field', $dt->format('U')); $this->assertEquals($dt->format('m/d/Y H:i:s'), $this->record->getField('timestamp_field')); - + $time = time()+3600; - $this->record->setFieldFromTimestamp('timestamp_field', $time ); - $this->assertEquals(date('m/d/Y H:i:s', $time ), $this->record->getField('timestamp_field')); - + $this->record->setFieldFromTimestamp('timestamp_field', $time); + $this->assertEquals(date('m/d/Y H:i:s', $time), $this->record->getField('timestamp_field')); + /* * To be activated when setFieldFromTimestamp will implement DateTime */ //$dt = new \DateTime('0001-01-01T00:00:00'); //$this->record->setFieldFromTimestamp('timestamp_field', $dt->format('U') ); //$this->assertEquals('01/01/0001 00:00:00', $this->record->getField('timestamp_field')); - + //$dt = new \DateTime('4000-12-31T23:59:59'); //$this->record->setFieldFromTimestamp('timestamp_field', $dt->format('U') ); //$this->assertEquals('12/31/4000 23:59:59', $this->record->getField('timestamp_field')); - + /* * time field */ $dt = new \DateTime(); - $this->record->setFieldFromTimestamp('time_field', $dt->format('U') ); + $this->record->setFieldFromTimestamp('time_field', $dt->format('U')); $this->assertEquals($dt->format('H:i:s'), $this->record->getField('time_field')); - + $time = time()+3600; - $this->record->setFieldFromTimestamp('time_field', $time ); - $this->assertEquals(date('H:i:s', $time ), $this->record->getField('time_field')); - + $this->record->setFieldFromTimestamp('time_field', $time); + $this->assertEquals(date('H:i:s', $time), $this->record->getField('time_field')); + /* * To be activated when setFieldFromTimestamp will implement DateTime */ //$dt = new \DateTime('0001-01-01T00:00:00'); //$this->record->setFieldFromTimestamp('time_field', $dt->format('U') ); //$this->assertEquals('00:00:00', $this->record->getField('time_field')); - + //$dt = new \DateTime('4000-12-31T23:59:59'); //$this->record->setFieldFromTimestamp('time_field', $dt->format('U') ); //$this->assertEquals('23:59:59', $this->record->getField('time_field')); } /** - * @covers airmoi\FileMaker\Object\Record::getRecordId + * @covers \airmoi\FileMaker\Object\Record::getRecordId */ - public function testGetRecordId() { + public function testGetRecordId() + { $this->assertNotNull($this->record->getRecordId()); } /** - * @covers airmoi\FileMaker\Object\Record::getModificationId + * @covers \airmoi\FileMaker\Object\Record::getModificationId */ - public function testGetModificationId() { + public function testGetModificationId() + { $this->assertNotNull($this->record->getModificationId()); } /** - * @covers airmoi\FileMaker\Object\Record::getRelatedSet + * @covers \airmoi\FileMaker\Object\Record::getRelatedSet */ - public function testGetRelatedSet() { + public function testGetRelatedSet() + { $this->assertContainsOnlyInstancesOf(Record::class, $this->record->getRelatedSet('related_sample')); } /** - * @covers airmoi\FileMaker\Object\Record::newRelatedRecord + * @covers \airmoi\FileMaker\Object\Record::newRelatedRecord */ - public function testNewRelatedRecord() { + public function testNewRelatedRecord() + { $relatedRecord = $this->record->newRelatedRecord('related_sample'); - + $this->assertEquals($this->record, $relatedRecord->getParent()); $this->assertEquals('related_sample', $relatedRecord->relatedSetName); } /** - * @covers airmoi\FileMaker\Object\Record::setParent + * @covers \airmoi\FileMaker\Object\Record::setParent * @todo Implement testSetParent(). */ - public function testSetParent() { + public function testSetParent() + { $record = new Record($this->record->getLayout()); $record->setParent($this->record); $this->assertEquals($this->record, $record->getParent()); } /** - * @covers airmoi\FileMaker\Object\Record::validate + * @covers \airmoi\FileMaker\Object\Record::validate * @todo Complete testValidate() for Four-Digit validation Rule. */ - public function testValidate() { + public function testValidate() + { $this->record->setField('date_field', 'incorrect Date'); - $this->assertInstanceOf(\airmoi\FileMaker\FileMakerValidationException::class, $this->record->validate('date_field')); - + $this->assertInstanceOf(FileMakerValidationException::class, $this->record->validate('date_field')); + $e = $this->record->validate(); - $this->assertInstanceOf(\airmoi\FileMaker\FileMakerValidationException::class, $this->record->validate()); + $this->assertInstanceOf(FileMakerValidationException::class, $this->record->validate()); $this->assertEquals(1, $this->record->validate()->numErrors()); - + $this->record->setField('text_field', str_repeat('0', 51)); $this->assertEquals(2, $this->record->validate()->numErrors()); - - $this->record->setField('text_field', "", 1); + + $this->record->setField('text_field', '', 1); $this->assertEquals(3, $this->record->validate()->numErrors()); - + $this->record->setField('timestamp_field', 'incorrect timestamp', 1); $this->assertEquals(4, $this->record->validate()->numErrors()); - + $this->record->setField('time_field', 'incorrect time', 1); $this->assertEquals(5, $this->record->validate()->numErrors()); - + $this->record->setField('number_field', 'incorrect number', 1); $this->assertEquals(6, $this->record->validate()->numErrors()); - + //$this->record->setField('date_field', '06/16/16', 1); //$this->assertEquals(7, $this->record->validate()->numErrors()); } /** - * @covers airmoi\FileMaker\Object\Record::commit + * @covers \airmoi\FileMaker\Object\Record::commit * @todo Implement testCommit(). */ - public function testCommit() { + public function testCommit() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Record::delete + * @covers \airmoi\FileMaker\Object\Record::delete * @todo Implement testDelete(). */ - public function testDelete() { + public function testDelete() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Record::getRelatedRecordById + * @covers \airmoi\FileMaker\Object\Record::getRelatedRecordById * @todo Implement testGetRelatedRecordById(). */ - public function testGetRelatedRecordById() { + public function testGetRelatedRecordById() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Object/RelatedSetTest.php b/tests/src/Object/RelatedSetTest.php index 337a1be..0010ed5 100644 --- a/tests/src/Object/RelatedSetTest.php +++ b/tests/src/Object/RelatedSetTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:50. */ -class RelatedSetTest extends \PHPUnit_Framework_TestCase { +class RelatedSetTest extends \PHPUnit_Framework_TestCase +{ /** * @var RelatedSet @@ -16,7 +17,8 @@ class RelatedSetTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new RelatedSet; } @@ -24,63 +26,67 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Object\RelatedSet::getName + * @covers \airmoi\FileMaker\Object\RelatedSet::getName * @todo Implement testGetName(). */ - public function testGetName() { + public function testGetName() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\RelatedSet::listFields + * @covers \airmoi\FileMaker\Object\RelatedSet::listFields * @todo Implement testListFields(). */ - public function testListFields() { + public function testListFields() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\RelatedSet::getField + * @covers \airmoi\FileMaker\Object\RelatedSet::getField * @todo Implement testGetField(). */ - public function testGetField() { + public function testGetField() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\RelatedSet::getFields + * @covers \airmoi\FileMaker\Object\RelatedSet::getFields * @todo Implement testGetFields(). */ - public function testGetFields() { + public function testGetFields() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\RelatedSet::loadExtendedInfo + * @covers \airmoi\FileMaker\Object\RelatedSet::loadExtendedInfo * @todo Implement testLoadExtendedInfo(). */ - public function testLoadExtendedInfo() { + public function testLoadExtendedInfo() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Object/ResultTest.php b/tests/src/Object/ResultTest.php index 2af20f8..0ce7702 100644 --- a/tests/src/Object/ResultTest.php +++ b/tests/src/Object/ResultTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:50. */ -class ResultTest extends \PHPUnit_Framework_TestCase { +class ResultTest extends \PHPUnit_Framework_TestCase +{ /** * @var Result @@ -16,7 +17,8 @@ class ResultTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new Result; } @@ -24,107 +26,115 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Object\Result::getLayout + * @covers \airmoi\FileMaker\Object\Result::getLayout * @todo Implement testGetLayout(). */ - public function testGetLayout() { + public function testGetLayout() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Result::getRecords + * @covers \airmoi\FileMaker\Object\Result::getRecords * @todo Implement testGetRecords(). */ - public function testGetRecords() { + public function testGetRecords() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Result::getFields + * @covers \airmoi\FileMaker\Object\Result::getFields * @todo Implement testGetFields(). */ - public function testGetFields() { + public function testGetFields() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Result::getRelatedSets + * @covers \airmoi\FileMaker\Object\Result::getRelatedSets * @todo Implement testGetRelatedSets(). */ - public function testGetRelatedSets() { + public function testGetRelatedSets() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Result::getTableRecordCount + * @covers \airmoi\FileMaker\Object\Result::getTableRecordCount * @todo Implement testGetTableRecordCount(). */ - public function testGetTableRecordCount() { + public function testGetTableRecordCount() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Result::getFoundSetCount + * @covers \airmoi\FileMaker\Object\Result::getFoundSetCount * @todo Implement testGetFoundSetCount(). */ - public function testGetFoundSetCount() { + public function testGetFoundSetCount() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Result::getFetchCount + * @covers \airmoi\FileMaker\Object\Result::getFetchCount * @todo Implement testGetFetchCount(). */ - public function testGetFetchCount() { + public function testGetFetchCount() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Result::getFirstRecord + * @covers \airmoi\FileMaker\Object\Result::getFirstRecord * @todo Implement testGetFirstRecord(). */ - public function testGetFirstRecord() { + public function testGetFirstRecord() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Object\Result::getLastRecord + * @covers \airmoi\FileMaker\Object\Result::getLastRecord * @todo Implement testGetLastRecord(). */ - public function testGetLastRecord() { + public function testGetLastRecord() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Parser/FMPXMLLAYOUTTest.php b/tests/src/Parser/FMPXMLLAYOUTTest.php index 7cf06c1..eed868b 100644 --- a/tests/src/Parser/FMPXMLLAYOUTTest.php +++ b/tests/src/Parser/FMPXMLLAYOUTTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:51. */ -class FMPXMLLAYOUTTest extends \PHPUnit_Framework_TestCase { +class FMPXMLLAYOUTTest extends \PHPUnit_Framework_TestCase +{ /** * @var FMPXMLLAYOUT @@ -16,7 +17,8 @@ class FMPXMLLAYOUTTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new FMPXMLLAYOUT; } @@ -24,52 +26,55 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Parser\FMPXMLLAYOUT::parse + * @covers \airmoi\FileMaker\Parser\FMPXMLLAYOUT::parse * @todo Implement testParse(). */ - public function testParse() { + public function testParse() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Parser\FMPXMLLAYOUT::setExtendedInfo + * @covers \airmoi\FileMaker\Parser\FMPXMLLAYOUT::setExtendedInfo * @todo Implement testSetExtendedInfo(). */ - public function testSetExtendedInfo() { + public function testSetExtendedInfo() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Parser\FMPXMLLAYOUT::_cdata + * @covers \airmoi\FileMaker\Parser\FMPXMLLAYOUT::_cdata * @todo Implement test_cdata(). */ - public function test_cdata() { + public function test_cdata() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Parser\FMPXMLLAYOUT::associative_array_push + * @covers \airmoi\FileMaker\Parser\FMPXMLLAYOUT::associative_array_push * @todo Implement testAssociative_array_push(). */ - public function testAssociative_array_push() { + public function testAssociative_array_push() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - } diff --git a/tests/src/Parser/FMResultSetTest.php b/tests/src/Parser/FMResultSetTest.php index 8ccb7a3..c03263c 100644 --- a/tests/src/Parser/FMResultSetTest.php +++ b/tests/src/Parser/FMResultSetTest.php @@ -5,7 +5,8 @@ /** * Generated by PHPUnit_SkeletonGenerator on 2016-09-09 at 19:46:51. */ -class FMResultSetTest extends \PHPUnit_Framework_TestCase { +class FMResultSetTest extends \PHPUnit_Framework_TestCase +{ /** * @var FMResultSet @@ -16,7 +17,8 @@ class FMResultSetTest extends \PHPUnit_Framework_TestCase { * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ - protected function setUp() { + protected function setUp() + { $this->object = new FMResultSet; } @@ -24,41 +26,43 @@ protected function setUp() { * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ - protected function tearDown() { - + protected function tearDown() + { } /** - * @covers airmoi\FileMaker\Parser\FMResultSet::parse + * @covers \airmoi\FileMaker\Parser\FMResultSet::parse * @todo Implement testParse(). */ - public function testParse() { + public function testParse() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Parser\FMResultSet::setResult + * @covers \airmoi\FileMaker\Parser\FMResultSet::setResult * @todo Implement testSetResult(). */ - public function testSetResult() { + public function testSetResult() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } /** - * @covers airmoi\FileMaker\Parser\FMResultSet::setLayout + * @covers \airmoi\FileMaker\Parser\FMResultSet::setLayout * @todo Implement testSetLayout(). */ - public function testSetLayout() { + public function testSetLayout() + { // Remove the following lines when you implement this test. $this->markTestIncomplete( - 'This test has not been implemented yet.' + 'This test has not been implemented yet.' ); } - }