Skip to content

Commit

Permalink
Merge branch 'MatthiasKuehneEllerhold-psr-2' into develop
Browse files Browse the repository at this point in the history
Merged MatthiasKuehneEllerhold-psr-2 into develop
  • Loading branch information
airmoi committed Nov 10, 2016
2 parents f37b4d3 + 9e24c7b commit 416cfa7
Show file tree
Hide file tree
Showing 47 changed files with 3,175 additions and 2,817 deletions.
15 changes: 9 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
/phpunit.xml
File renamed without changes.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 :
Expand All @@ -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

Expand Down Expand Up @@ -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*

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -13,5 +13,8 @@
"psr-4": {
"airmoi\\FileMaker\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^5.6"
}
}
50 changes: 30 additions & 20 deletions src/Command/Add.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2016 by 1-more-thing (http://1-more-thing.com) All rights reserved.
* @licence BSD
* @license BSD
*/
namespace airmoi\FileMaker\Command;

Expand All @@ -14,8 +14,8 @@
*
* @package FileMaker
*/
class Add extends Command {

class Add extends Command
{
/**
* Add command constructor.
*
Expand All @@ -26,14 +26,14 @@ class Add extends Command {
* 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, $values = array()) {
public function __construct(FileMaker $fm, $layout, $values = array())
{
parent::__construct($fm, $layout);
foreach ($values as $fieldname => $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) ;
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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');
}
}

Expand All @@ -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()) {
Expand All @@ -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;
}

}
Loading

0 comments on commit 416cfa7

Please sign in to comment.