https://github.com/thipages/pca-helper
Helper for PHP-CRUD-API configuration
https://github.com/thipages/pca-helper
configuration database helper middleware php-crud-api
Last synced: about 2 months ago
JSON representation
Helper for PHP-CRUD-API configuration
- Host: GitHub
- URL: https://github.com/thipages/pca-helper
- Owner: thipages
- License: mit
- Created: 2021-03-17T20:35:27.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-06-20T10:45:10.000Z (almost 4 years ago)
- Last Synced: 2025-02-08T10:20:14.110Z (3 months ago)
- Topics: configuration, database, helper, middleware, php-crud-api
- Language: PHP
- Homepage:
- Size: 95.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PCA-HELPER
PCA-HELPER tries to help to setup the configuration file used in [PHP-CRUD-API](https://github.com/mevdschee/php-crud-api)
- simplifying the database configuration
- simplifying the dbAuth configuration
- providing some middlewares tools (`upload`, `autoFK`),
- writing automatically `middlewares` configuration property> **Drawback** : it adds some workload on the server compared to the native/original single file `api.php`. May be a cli tool may be a good comprise one day...
## Installation
_composer require thipages/pca-helper_add an `api.php` file referencing
- either `require('./api.include.php');`for a single file usage from [PHP-CRUD-API](https://github.com/mevdschee/php-crud-api)
- or the library with `autoload.php` and `composer require mevdschee/php-crud-api`## Usage
**Simple static call**
`Helper::echo(...$config);``$config` being a list of
- either regular associative arrays (as defined in PHP-CRUD-API)
```php
[
'debug'=>true,
'authorization.tableHandler' => function ($operation, $tableName) {
return $tableName != 'user';
}
]
```
- or static methods of predefined class (returning an associative array...)
```php
Base::setup_connection(
$database, $username, $password,
$driver = 'mysql',$address='localhost',
$port = null
)
```
```php
Base::setup_SQLite($filePath)
```
```php
Base::setup_cache($cacheType = 'NoCache', $cacheTime = 10, $cachePath = null)
```
```php
BdAuth::setup(
$sessionName,
$passwordLength=12, $mode='required',
$usersTable='user',$usernameColumn='username',$passwordColumn='password',
$registerUser='1')
// Note that dbAuth has a strong default setup
```
- or static handlers whose name method match the configuration key (by convention)
```php
[
'multiTenancy.handler'=>AutoFK::multiTenancy_handler(
$relations,
$user=['user','id','user_id']
)
]
```
```php
[
'customzation.beforeHandler'=>Upload::customzation_beforeHandler (
$table, $field, $filesPath
)
]
```## Example
```php
Helper::echo(
[
Base::setup_SQLite($dbPath),
Base::setup_cache(),
DbAuth::setup('pca_helper',8),
[
'authorization.tableHandler' => function ($operation, $tableName) {
return $tableName != 'user';
},
'multiTenancy.handler' => AutoFK::multiTenancy_handler(['note'=>'user_id']),
'customzation.beforeHandler'=>function($operation, $tableName, $request, $environment) {
$request= Upload::customzation_beforeHandler ($table, $field, $filesPath)(func_get_args());
// ...
return $request;
},
Base::debug=>true
]
]);
```