Skip to content

Commit a4b77fb

Browse files
Merge branch 'release/1.0.6' into main
2 parents 9daa1de + b75b54d commit a4b77fb

23 files changed

+267
-285
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.gitignore export-ignore
2+
/pint.json export-ignore
3+
/tests export-ignore
4+
/phpunit.xml.dist export-ignore
5+
/.gitattributes export-ignore
6+
/.github

.github/ISSUE_TEMPLATE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### Dependencies
2+
- FileMaker Version: #.#.#
3+
- PHP Version: #.#.#
4+
- Laravel Version: #.#.#
5+
- Eloquent FileMaker Version: #.#.#
6+
7+
### Description of the issue:
8+
9+
### Expected Behavior:
10+
11+
### Steps to reproduce:

.github/workflows/code-style.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "Code Style"
2+
on: [pull_request]
3+
4+
jobs:
5+
code_style:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
10+
- name: Validate composer.json and composer.lock
11+
run: composer validate --strict
12+
13+
- name: "Laravel Pint"
14+
uses: aglipanci/laravel-pint-action@2.0.0
15+
with:
16+
verboseMode: true
17+
testMode: true
18+
configPath: "./pint.json"

README.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ composer require gearbox-solutions/eloquent-filemaker
4141
With the package installed you can now have access to all the features of this package. There are a few different areas to configure.
4242

4343
## Database configuration
44-
The first thing to do is to add a new data connection in your ```database.php``` config file. The connections you specify here will be used in your FMModel classes to configure which databases each model will connect to.
44+
The first thing to do is to add a new data connection in your `database.php` config file. The connections you specify here will be used in your FMModel classes to configure which databases each model will connect to.
4545

4646
You may use the following code block below as a template.
47-
48-
'filemaker' => [
49-
'driver' => 'filemaker',
50-
'host' => env('DB_HOST', 'fms.mycompany.com'),
51-
'database' => env('DB_DATABASE', 'MyFileName'),
52-
'username' => env('DB_USERNAME', 'myusername'),
53-
'password' => env('DB_PASSWORD', ''),
54-
'prefix' => env('DB_PREFIX', ''),
55-
'version' => env('DB_VERSION', 'vLatest'),
56-
'protocol' => env('DB_PROTOCOL', 'https'),
57-
]
58-
47+
```php
48+
'filemaker' => [
49+
'driver' => 'filemaker',
50+
'host' => env('DB_HOST', 'fms.mycompany.com'),
51+
'database' => env('DB_DATABASE', 'MyFileName'),
52+
'username' => env('DB_USERNAME', 'myusername'),
53+
'password' => env('DB_PASSWORD', ''),
54+
'prefix' => env('DB_PREFIX', ''),
55+
'version' => env('DB_VERSION', 'vLatest'),
56+
'protocol' => env('DB_PROTOCOL', 'https'),
57+
]
58+
```
5959
You should add one database connection configuration for each FileMaker database you will be connecting to. Each file can have completely different configurations, and can even be on different servers.
6060

6161
Sessions will be maintained on a per-connection basis and tokens will automatically be cached using whatever cache configuration you have set up for your Laravel app.
@@ -100,17 +100,17 @@ This package supports both reading and writing container field data. Container f
100100
#### Writing to container fields
101101
When setting a container field you should set the value to be an `Illuminate/HTTP/File` or `Illuminate/HTTP/UploadedFile` object. These attributes will be written back to your container fields along with any other model updates when the `save()` method is called on your model object.
102102
```php
103-
$file = new File(storage_path('app/public/gator.jpg'));
104-
$newPet->photo = $file;
105-
$newPet->save();
103+
$file = new File(storage_path('app/public/gator.jpg'));
104+
$newPet->photo = $file;
105+
$newPet->save();
106106
```
107107

108108
#### Custom filenames when inserting files into containers
109109
By default, files are inserted into containers using the filename of the file you are inserting. If you wish to set a new filename when the file is inserted into the container you can do so by passing the file and filename together in an array when setting your container.
110110
```php
111-
$file = new File(storage_path('app/public/gator.jpg'));
112-
$newPet->photo = [$file, 'fluffy.jpg'];
113-
$newPet->save();
111+
$file = new File(storage_path('app/public/gator.jpg'));
112+
$newPet->photo = [$file, 'fluffy.jpg'];
113+
$newPet->save();
114114
```
115115

116116
### Renaming and Mapping FileMaker Fields
@@ -125,7 +125,7 @@ protected $fieldMapping = [
125125
and then you can get/set the attributes via....
126126

127127
```php
128-
$myModel->a_much_better_name = 'my new value';
128+
$myModel->a_much_better_name = 'my new value';
129129
```
130130

131131
### Fields from related records
@@ -169,23 +169,25 @@ $person->person_pet_portal[1]['person_PET::type'] = 'cat';
169169
This package has special handling for casting FileMaker Timestamp and Date fields to Carbon instances for you. To take advantage of this, you must map the fields as you would with a native Laravel Model class. You can use the `$casts` property as you normally would for these attributes.
170170

171171
```php
172-
protected $casts = [
173-
'nextAppointment' => 'datetime',
174-
'birthday' => 'date',
175-
];
172+
protected $casts = [
173+
'nextAppointment' => 'datetime',
174+
'birthday' => 'date',
175+
];
176176
```
177177

178178
The format Date and Timestamp fields written to FileMaker can be changed via the `$dateFormat` property of your model. This value must be compatible with the format output from the FileMaker Data API for Timestamp values and will be the format written back into your database. One important requirement is that this must be a full timestamp format, not just a date format.
179179

180180
Here are some example formats:
181181
```php
182-
protected $dateFormat = 'n/j/Y g:i:s A'; // 7/1/1920 4:01:01 PM
183-
protected $dateFormat = 'n/j/Y G:i:s'; // 7/1/1920 16:01:01
182+
protected $dateFormat = 'n/j/Y g:i:s A'; // 7/1/1920 4:01:01 PM
183+
protected $dateFormat = 'n/j/Y G:i:s'; // 7/1/1920 16:01:01
184184
```
185185

186186

187187
## Example FMModel Class
188188
```php
189+
// Person.php
190+
189191
class Person extends FMModel
190192
{
191193

@@ -206,7 +208,6 @@ class Person extends FMModel
206208
}
207209

208210
}
209-
210211
```
211212

212213
# The Base Query Builder and the FM Facade
@@ -301,9 +302,9 @@ $result = FM::layout('MyLayoutName')->performScript('MyScriptName');
301302
Run a script with JSON data as a parameter
302303
```php
303304
$json = json_encode ([
304-
'name' => 'Joe Smith',
305-
'birthday' => '1/1/1970'
306-
'favorite_color' => 'blue'
305+
'name' => 'Joe Smith',
306+
'birthday' => '1/1/1970'
307+
'favorite_color' => 'blue'
307308
]);
308309

309310
$result = FM::layout('globals')->performScript('New Contact Request'; $json);
@@ -317,7 +318,6 @@ $result = FM::connection('MyOtherDatabaseConnectionName')->layout('MyLayoutName'
317318
Create a record with an array of field data and then perform a script after record creation, within the same request
318319
```php
319320
FM::layout('MyLayoutName')->script('ScriptName')->fieldData($data)->createRecord();
320-
321321
```
322322

323323
## Logging out, disconnecting, and ending your Data API session
@@ -347,6 +347,8 @@ Once they're set correctly, you can create relationships, such as a belongsTo, b
347347
Here is an example of setting a native Laravel User Model to belong to a FileMaker-based Company FMModel class.
348348

349349
```php
350+
// User.php
351+
350352
class User extends Model
351353
{
352354
public function company()

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
},
3333
"require-dev": {
3434
"orchestra/testbench": "^7.0",
35-
"mockery/mockery": "^1.5.1"
35+
"mockery/mockery": "^1.5.1",
36+
"laravel/pint": "^1.1"
3637
},
3738
"extra": {
3839
"laravel": {

pint.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": "laravel",
3+
"rules": {
4+
"concat_space": {
5+
"spacing": "one"
6+
}
7+
}
8+
}

src/Database/Eloquent/Concerns/FMGuardsAttributes.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66

77
trait FMGuardsAttributes
88
{
9-
109
/**
1110
* Determine if the given key is guarded.
1211
*
13-
* @param string $key
12+
* @param string $key
1413
* @return bool
1514
*/
1615
public function isGuarded($key)
@@ -20,21 +19,21 @@ public function isGuarded($key)
2019
}
2120

2221
return $this->getGuarded() == ['*'] ||
23-
!empty(preg_grep('/^' . preg_quote($key) . '$/i', $this->getGuarded())) ||
24-
!$this->isGuardableColumn($key);
22+
! empty(preg_grep('/^' . preg_quote($key) . '$/i', $this->getGuarded())) ||
23+
! $this->isGuardableColumn($key);
2524
}
2625

2726
/**
2827
* Determine if the given column is a valid, guardable column.
2928
*
30-
* @param string $key
29+
* @param string $key
3130
* @return bool
3231
*/
3332
protected function isGuardableColumn($key)
3433
{
3534
$this->primeGuardableColumns();
3635

37-
if(in_array($key, static::$guardableColumns[get_class($this)])) {
36+
if (in_array($key, static::$guardableColumns[get_class($this)])) {
3837
return true;
3938
}
4039

@@ -45,7 +44,7 @@ protected function isGuardableColumn($key)
4544

4645
protected function primeGuardableColumns($forceRefresh = false)
4746
{
48-
if (!isset(static::$guardableColumns[get_class($this)])) {
47+
if (! isset(static::$guardableColumns[get_class($this)])) {
4948
$columns = $this->getColumns($forceRefresh);
5049

5150
if (empty($columns)) {
@@ -55,23 +54,21 @@ protected function primeGuardableColumns($forceRefresh = false)
5554
}
5655
}
5756

58-
5957
protected function getColumns($forceRefresh = false): array
6058
{
6159
$cacheKey = "eloquent-filemaker-{$this->table}-columns";
62-
$refreshCallback = function() {
60+
$refreshCallback = function () {
6361
$layoutMetaData = $this->getConnection()->getLayoutMetadata($this->table);
6462

6563
return array_column($layoutMetaData['fieldMetaData'], 'name');
6664
};
6765

68-
if($forceRefresh) {
66+
if ($forceRefresh) {
6967
Cache::forever($cacheKey, $columns = $refreshCallback());
7068

7169
return $columns;
7270
}
7371

7472
return Cache::rememberForever($cacheKey, $refreshCallback);
7573
}
76-
7774
}

src/Database/Eloquent/Concerns/FMHasAttributes.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@
33
namespace GearboxSolutions\EloquentFileMaker\Database\Eloquent\Concerns;
44

55
use DateTime;
6-
use Illuminate\Database\Eloquent\Concerns\HasAttributes;
76
use Illuminate\Support\Arr;
87

98
trait FMHasAttributes
109
{
11-
1210
/**
1311
* Set a given attribute on the model.
1412
*
15-
* @param string $key
16-
* @param mixed $value
13+
* @param string $key
14+
* @param mixed $value
1715
* @return mixed
1816
*/
1917
public function setAttribute($key, $value)
@@ -36,7 +34,7 @@ public function setAttribute($key, $value)
3634
// When writing dates the regular datetime format won't work, so we have to get JUST the date value
3735
// check the key's cast to see if it is cast to a date or custom date:format
3836
$castType = $this->getCasts()[$key] ?? '';
39-
$isDate = $castType == "date" || str_starts_with($castType, 'date:');
37+
$isDate = $castType == 'date' || str_starts_with($castType, 'date:');
4038
if ($isDate) {
4139
$value = Arr::first(explode(' ', $value));
4240
}
@@ -55,5 +53,4 @@ public function setAttribute($key, $value)
5553

5654
return $this;
5755
}
58-
5956
}

src/Database/Eloquent/Concerns/FMHasRelationships.php

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
22

3-
43
namespace GearboxSolutions\EloquentFileMaker\Database\Eloquent\Concerns;
54

65
use GearboxSolutions\EloquentFileMaker\Database\Eloquent\Relations\BelongsTo;
@@ -11,13 +10,12 @@
1110

1211
trait FMHasRelationships
1312
{
14-
1513
/**
1614
* Define a one-to-one relationship.
1715
*
18-
* @param string $related
19-
* @param string|null $foreignKey
20-
* @param string|null $localKey
16+
* @param string $related
17+
* @param string|null $foreignKey
18+
* @param string|null $localKey
2119
*/
2220
public function hasOne($related, $foreignKey = null, $localKey = null)
2321
{
@@ -30,13 +28,12 @@ public function hasOne($related, $foreignKey = null, $localKey = null)
3028
return $this->newHasOne($instance->newQuery(), $this, $foreignKey, $localKey);
3129
}
3230

33-
3431
/**
3532
* Define a one-to-many relationship.
3633
*
37-
* @param string $related
38-
* @param string|null $foreignKey
39-
* @param string|null $localKey
34+
* @param string $related
35+
* @param string|null $foreignKey
36+
* @param string|null $localKey
4037
* @return \Illuminate\Database\Eloquent\Relations\HasMany
4138
*/
4239
public function hasMany($related, $foreignKey = null, $localKey = null)
@@ -55,11 +52,9 @@ public function hasMany($related, $foreignKey = null, $localKey = null)
5552
/**
5653
* Instantiate a new BelongsTo relationship.
5754
*
58-
* @param \Illuminate\Database\Eloquent\Builder $query
59-
* @param \Illuminate\Database\Eloquent\Model $child
60-
* @param string $foreignKey
61-
* @param string $ownerKey
62-
* @param string $relation
55+
* @param string $foreignKey
56+
* @param string $ownerKey
57+
* @param string $relation
6358
* @return BelongsTo
6459
*/
6560
protected function newBelongsTo(Builder $query, Model $child, $foreignKey, $ownerKey, $relation)
@@ -71,10 +66,8 @@ protected function newBelongsTo(Builder $query, Model $child, $foreignKey, $owne
7166
/**
7267
* Instantiate a new HasMany relationship.
7368
*
74-
* @param \Illuminate\Database\Eloquent\Builder $query
75-
* @param \Illuminate\Database\Eloquent\Model $parent
76-
* @param string $foreignKey
77-
* @param string $localKey
69+
* @param string $foreignKey
70+
* @param string $localKey
7871
* @return HasMany
7972
*/
8073
protected function newHasMany(Builder $query, Model $parent, $foreignKey, $localKey)
@@ -112,17 +105,13 @@ public function morphMany($related, $name, $type = null, $id = null, $localKey =
112105
/**
113106
* Instantiate a new HasOne relationship.
114107
*
115-
* @param \Illuminate\Database\Eloquent\Builder $query
116-
* @param \Illuminate\Database\Eloquent\Model $parent
117-
* @param string $foreignKey
118-
* @param string $localKey
108+
* @param string $foreignKey
109+
* @param string $localKey
119110
* @return HasOne
120111
*/
121112
protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey)
122113
{
123114
// custom version of this so we can return our own BelongsTo class with a custom constraint for FM
124115
return new HasOne($query, $parent, $foreignKey, $localKey);
125116
}
126-
127-
128117
}

0 commit comments

Comments
 (0)