thipages / pca-helper
Helper for PHP-CRUD-API configuration
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/thipages/pca-helper
Requires (Dev)
README
PCA-HELPER tries to help to setup the configuration file used in PHP-CRUD-API
- simplifying the database configuration
- simplifying the dbAuth configuration
- providing some middlewares tools (
upload,autoFK), - writing automatically
middlewaresconfiguration 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 - or the library with
autoload.phpandcomposer 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)
[
'debug'=>true,
'authorization.tableHandler' => function ($operation, $tableName) {
return $tableName != 'user';
}
]
- or static methods of predefined class (returning an associative array...)
Base::setup_connection( $database, $username, $password, $driver = 'mysql',$address='localhost', $port = null )
Base::setup_SQLite($filePath)
Base::setup_cache($cacheType = 'NoCache', $cacheTime = 10, $cachePath = null)
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)
[
'multiTenancy.handler'=>AutoFK::multiTenancy_handler(
$relations,
$user=['user','id','user_id']
)
]
[
'customzation.beforeHandler'=>Upload::customzation_beforeHandler (
$table, $field, $filesPath
)
]
Example
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 ] ]);