Skip to content

Commit 7c04401

Browse files
authored
Merge pull request #36 from tattersoftware/v3
Version 3
2 parents 309a0b1 + 351c0c4 commit 7c04401

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+936
-1108
lines changed

.github/workflows/unused.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ jobs:
5757
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
5858

5959
- name: Detect unused packages
60-
run: composer-unused -vvv --profile --ansi --no-interaction --no-progress --excludePackage=php --excludePackage=tatter/alerts --excludePackage=tatter/assets --excludePackage=tatter/audits
60+
run: composer-unused -vvv --profile --ansi --no-interaction --no-progress --excludePackage=php --excludePackage=tatter/alerts --excludePackage=tatter/assets --excludePackage=tatter/audits --excludePackage=tatter/preferences --excludePackage=tatter/thumbnails

UPGRADING.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Upgrade Guide
2+
3+
## Version 2 to 3
4+
***
5+
6+
* Switches to `Tatter\Preferences` for managing persistent settings; read more below
7+
* Drops `Tatter\Audits` as a dependency and adds it as a suggestion; read more below
8+
9+
### `Settings` Migration
10+
11+
`Preferences` relies on `CodeIgniter\Settings` instead of the abandoned `Tatter\Settings`, but
12+
both packages had migrations for a `settings` database table and the schemas are not compatible.
13+
You should archive any global and user-specific settings you would like to keep, then drop
14+
or rename the old table. You may also need to update your `migrations` table in case your
15+
project complains about a "gap in the migrations". Read more on the migration process at the
16+
[Tatter\Settings](https://github.com/tattersoftware/codeigniter4-settings) repo.
17+
18+
### Audits
19+
20+
In order to simplify this library `Tatter\Audits` is no longer included by default. If you
21+
want that level of user-specific logging to database changes then you may install the package
22+
and provide a model extension with the events to reenable. You may also need to update your
23+
`migrations` table in case your project complains about a "gap in the migrations".
24+
25+
Installation:
26+
```bash
27+
composer require tatter/audits
28+
php spark migrate --all
29+
```
30+
31+
Example model file in **app/Models/FileModel.php**:
32+
```
33+
<?php
34+
35+
namespace App\Models;
36+
37+
use Tatter\Audits\Traits\AuditsTrait;
38+
use Tatter\Files\Models\FileModel as BaseModel;
39+
40+
class FileModel extends BaseModel
41+
{
42+
use AuditsTrait;
43+
44+
// Audits
45+
protected $afterInsert = ['auditInsert'];
46+
protected $afterUpdate = ['auditUpdate'];
47+
protected $afterDelete = ['auditDelete'];
48+
}
49+
```

composer.json

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,19 @@
2121
],
2222
"require": {
2323
"php": "^7.3 || ^8.0",
24-
"components/jquery": "^3.3",
25-
"enyo/dropzone": "^5.7",
26-
"fortawesome/font-awesome": "^5.8",
24+
"codeigniter4/authentication-implementation": "^1.0",
25+
"enyo/dropzone": "^6.0",
2726
"tatter/alerts": "^2.0",
28-
"tatter/assets": "^2.2",
29-
"tatter/audits": "^1.0",
3027
"tatter/exports": "^2.0",
28+
"tatter/frontend": "^1.0",
3129
"tatter/permits": "^2.0",
32-
"tatter/settings": "^1.0 || ^2.0",
33-
"tatter/thumbnails": "^1.2",
34-
"twbs/bootstrap": "^4.5"
30+
"tatter/preferences": "^1.0",
31+
"tatter/thumbnails": "^1.2"
3532
},
3633
"require-dev": {
3734
"antecedent/patchwork": "^2.1",
3835
"codeigniter4/codeigniter4": "dev-develop",
39-
"myth/auth": "dev-develop",
36+
"tatter/imposter": "^1.0",
4037
"tatter/tools": "^1.15"
4138
},
4239
"autoload": {
@@ -55,19 +52,16 @@
5552
"repositories": [
5653
{
5754
"type": "vcs",
58-
"url": "https://github.com/codeigniter4/CodeIgniter4",
59-
"no-api": true
60-
},
61-
{
62-
"type": "vcs",
63-
"url": "https://github.com/lonnieezell/myth-auth",
64-
"no-api": true
55+
"url": "https://github.com/codeigniter4/CodeIgniter4.git"
6556
},
6657
{
6758
"type": "composer",
6859
"url": "https://asset-packagist.org"
6960
}
7061
],
62+
"suggest": {
63+
"tatter/audits": "Adds logging for user changes to Files database rows."
64+
},
7165
"minimum-stability": "dev",
7266
"prefer-stable": true,
7367
"scripts": {

phpstan.neon.dist

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ parameters:
1515
- '#Cannot access property \$[a-z]+ on array\|object#'
1616
- '#Cannot call method [A-Za-z]+\(\) on array\|object#'
1717
- '#Unsafe usage of new static\(\)*#'
18-
- '#Call to an undefined static method Config\\Services::authentication\(\)#'
19-
- '#Function Patchwork\\redefine not found#'
2018
universalObjectCratesClasses:
2119
- CodeIgniter\Entity
2220
- Faker\Generator
2321
scanDirectories:
2422
- vendor/codeigniter4/codeigniter4/system/Helpers
25-
- vendor/myth/auth/src/Helpers
2623
- vendor/tatter/alerts/src/Helpers
2724
- vendor/tatter/handlers/src/Helpers
25+
- vendor/tatter/imposter/src/Helpers
26+
- vendor/tatter/preferences/src/Helpers
2827
dynamicConstantNames:
2928
- APP_NAMESPACE
3029
- CI_DEBUG

src/Bundles/DropzoneBundle.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Tatter\Files\Bundles;
4+
5+
use Tatter\Frontend\FrontendBundle;
6+
7+
class DropzoneBundle extends FrontendBundle
8+
{
9+
/**
10+
* Applies any initial inputs after the constructor.
11+
*/
12+
protected function define(): void
13+
{
14+
$this
15+
->addPath('dropzone/dropzone.css')
16+
->addPath('dropzone/dropzone-min.js');
17+
}
18+
}

src/Bundles/FilesBundle.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Tatter\Files\Bundles;
4+
5+
use Tatter\Assets\Bundle;
6+
use Tatter\Frontend\Bundles\BootstrapBundle;
7+
use Tatter\Frontend\Bundles\FontAwesomeBundle;
8+
9+
class FilesBundle extends Bundle
10+
{
11+
/**
12+
* Applies any initial inputs after the constructor.
13+
*/
14+
protected function define(): void
15+
{
16+
$this
17+
->merge(new BootstrapBundle())
18+
->merge(new DropzoneBundle())
19+
->merge(new FontAwesomeBundle());
20+
}
21+
}

src/Config/Files.php

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,17 @@
33
namespace Tatter\Files\Config;
44

55
use CodeIgniter\Config\BaseConfig;
6+
use Tatter\Files\Exceptions\FilesException;
67

78
class Files extends BaseConfig
89
{
9-
/**
10-
* Directory to store files (with trailing slash)
11-
*
12-
* @var string
13-
*/
14-
public $storagePath = WRITEPATH . 'files/';
15-
1610
/**
1711
* Whether to include routes to the Files Controller.
1812
*
1913
* @var bool
2014
*/
2115
public $routeFiles = true;
2216

23-
/**
24-
* Layouts to use for general access and for administration
25-
*
26-
* @var array<string, string>
27-
*/
28-
public $layouts = [
29-
'public' => 'Tatter\Files\Views\layout',
30-
'manage' => 'Tatter\Files\Views\layout',
31-
];
32-
3317
/**
3418
* View file aliases
3519
*
@@ -40,16 +24,84 @@ class Files extends BaseConfig
4024
];
4125

4226
/**
43-
* Default display format; built in are 'cards', 'list', 'select'
27+
* Path to the default thumbnail file
4428
*
4529
* @var string
4630
*/
47-
public $defaultFormat = 'cards';
31+
public $defaultThumbnail = 'Tatter\Files\Assets\Unavailable.jpg';
32+
33+
//--------------------------------------------------------------------
34+
// Display Preferences
35+
//--------------------------------------------------------------------
4836

4937
/**
50-
* Path to the default thumbnail file
38+
* Display format for listing files.
39+
* Included options are 'cards', 'list', 'select'
5140
*
5241
* @var string
5342
*/
54-
public $defaultThumbnail = 'Tatter\Files\Assets\Unavailable.jpg';
43+
public $format = 'cards';
44+
45+
/**
46+
* Default sort column.
47+
* See FileModel::$allowedFields for options.
48+
*
49+
* @var string
50+
*/
51+
public $sort = 'filename';
52+
53+
/**
54+
* Default sort ordering. "asc" or "desc"
55+
*
56+
* @var string
57+
*/
58+
public $order = 'asc';
59+
60+
//--------------------------------------------------------------------
61+
// Storage Options
62+
//--------------------------------------------------------------------
63+
64+
/**
65+
* Directory to store files (with trailing slash).
66+
* Usually best to use getPath()
67+
*
68+
* @var string
69+
*/
70+
protected $path = WRITEPATH . 'files' . DIRECTORY_SEPARATOR;
71+
72+
/**
73+
* Normalizes and creates (if necessary) the storage and thumbnail paths,
74+
* returning the normalized storage path.
75+
*
76+
* @throws FilesException
77+
*/
78+
public function getPath(): string
79+
{
80+
$storage = $this->path;
81+
82+
// Verify the storage directory
83+
if (! is_dir($storage) && ! @mkdir($storage, 0775, true)) {
84+
throw FilesException::forDirFail($storage);
85+
}
86+
87+
// Normalize the storage path
88+
$this->path = realpath($storage) ?: $storage;
89+
$this->path = rtrim($storage, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
90+
91+
// Check or create the thumbnails subdirectory
92+
$thumbnails = $storage . 'thumbnails';
93+
if (! is_dir($thumbnails) && ! @mkdir($thumbnails, 0775, true)) {
94+
throw FilesException::forDirFail($thumbnails); // @codeCoverageIgnore
95+
}
96+
97+
return $storage;
98+
}
99+
100+
/**
101+
* Changes the storage path value. Mostly just for testing.
102+
*/
103+
public function setPath(string $path)
104+
{
105+
$this->path = $path;
106+
}
55107
}

src/Config/Registrar.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22

33
namespace Tatter\Files\Config;
44

5-
/**
6-
* Class Registrar
7-
*
8-
* Provides a basic registrar class for testing BaseConfig registration functions.
9-
*/
105
class Registrar
116
{
127
/**
13-
* Override database config
8+
* Adds the Files option to available Pager templates.
149
*
15-
* @return array
10+
* @return array<string,mixed>
1611
*/
1712
public static function Pager()
1813
{

src/Config/Routes.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
return;
55
}
66

7+
$options = [
8+
'filter' => 'assets:\Tatter\Files\Bundles\FilesBundle',
9+
'namespace' => '\Tatter\Files\Controllers',
10+
];
11+
712
// Routes to Files controller
8-
$routes->group('files', ['namespace' => '\Tatter\Files\Controllers'], static function ($routes) {
13+
$routes->group('files', $options, static function ($routes) {
914
$routes->get('/', 'Files::index');
1015
$routes->get('user', 'Files::user');
1116
$routes->get('user/(:any)', 'Files::user/$1');

0 commit comments

Comments
 (0)