Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2023-12-02 (11 months ago) | Not enough user ratings | Total: 79 | All time: 10,124 This week: 51 |
Version | License | PHP version | Categories | |||
ala-microframework-p 7.0.1 | Custom (specified... | 7.1 | Libraries, Web services, Code Generation, D..., T..., P... |
<?php |
API Rest based in lumen using query builder that auto generate base code for simple crud (with automatic generated 100% unit and feature tests).
Release 7.0.0 Requires PHP 8.3
Release 6.0.0 Requires PHP 8.2
Release 5.0.0 Requires PHP 8.1
Release 4.0.0 Requires PHP 7.4
Release 3.0.0 Requires PHP 7.3
Release 2.0.0 Requires PHP 7.2
Release 1.0.0 Requires PHP 7.1
composer create-project and enter in the created folder (you can fork or clone the repository if you want to)
composer create-project not-empty/ala-microframework-php your_project_name
(optional) Stop all other containers to avoid conflict.
docker stop $(docker ps -q)
Start project with Docker using compose tool.
docker-compose up -d
Access the container
docker exec -it ala-php bash
Run Composer to install all dependencies.
composer install --prefer-dist
Ensure the composer install create the cache folders and give then permissions in ./storage, if don't you'll have to create and give permitions yourself:
mkdir storage/framework \
&& mkdir storage/framework/cache \
&& mkdir storage/framework/cache/data \
&& mkdir storage/framework/sessions \
&& mkdir storage/framework/views \
&& chmod -R 777 ./storage
To check the build for this project look at ./ops/docker/dev folder.
Copy and modify the .env file
cp .env.example .env
Include values for APP_KEY
and JWT_APP_SECRET
, we strongly recommend a 26 to 32 length random string (can be a ulid)
You can use /health/key
uri to generate this keys.
Now you can access the health-check http://localhost:8101 and get a json response like this:
{
"status": "online",
"version": "0.0.1"
}
You can find a sample of requests you can do in the file requests.http
(for the REST Client extension on VSCode) or using curl commands listed in the file requests.curl
.
Not all requests are documented yet (Work in progress)
For create your brand new domain with a complete crud use the command:
php artisan create:domain {your_domain}
This command will create a folder in app/Domains
, new files in routes
, database/migrations
and database/seeds
folder with all base code including all the units and feature tests.
If your domain name has 2 words use underline (_) to separate.
php artisan migration
For primary key value, this project using Ulid value, but you can pass other pattern in insert route if you prefer.
In auth route this projet use JWT lib. This token will be generate if your secret, token and context is correct. This configuration is the token.php
file in app/config/
folder.
We strongly advise you to change these values, they can be either random strings, ulids or any string that you like.
We use to generate then by encrypting an ulid v4 with SHA512/256.
We recommend creating diferents tokens from diferents sources.
return [
'data' => [
'32c5a206ee876f4c6e1c483457561dbed02a531a89b380c3298bb131a844ac3c' => [ // default token
'name' => 'app-test', // default context
'secret' => 'a1c5930d778e632c6684945ca15bcf3c752d17502d4cfbd1184024be6de14540', // default secret
],
],
];
To make request between two or more services, this project use Request Service lib.
The pattern used to return all request is json and the layout is configure in your Response lib.
I you want to implement custom validators you can use the regex function and add you regex to the patterns file /app/Constants/PatternsConstants.php
and then just use anywhere but dont forget to declare the class for use:
use App\Constants\PatternsConstants;
Follow this steps to configure a new field to accepted a filter in list route
For example, to add a filter to age
field just include a new entry like that
/
* get rules for this request
* @return array
*/
public function getRules() : array
{
return [
'class' => 'string|in:"asc","desc"',
'fields' => 'string',
'order' => 'string',
'page' => 'integer|min:1',
'filter_name' => [
'string',
'regex:'.PatternsConstants::FILTER,
],
// here your new filter
'filter_age' => [
'string',
'regex:'.PatternsConstants::FILTER,
],
];
}
After that, you need to configure your filters in app/Domains/{your_domain}/Filters
.
you can user various patterns like FILTER_EQUAL
, FILTER_NOT_EQUAL
, etc.
Check all types look at FiltersTypesConstants
class in app/Constants
.
/
* set filter rules for this domain
*/
public $filter = [
'age' => [
'validate' => 'integer|min:18|max:99',
'permissions' => [
FiltersTypesConstants::FILTER_EQUAL,
FiltersTypesConstants::FILTER_NOT_EQUAL,
],
],
'created' => [
'validate' => 'date',
'permissions' => [
FiltersTypesConstants::FILTER_LESS_THAN,
FiltersTypesConstants::FILTER_GREATER_THAN,
FiltersTypesConstants::FILTER_GREATER_THAN_OR_EQUAL,
FiltersTypesConstants::FILTER_LESS_THAN_OR_EQUAL,
],
],
'modified' => [
'validate' => 'date',
'permissions' => [
FiltersTypesConstants::FILTER_LESS_THAN,
FiltersTypesConstants::FILTER_GREATER_THAN,
FiltersTypesConstants::FILTER_GREATER_THAN_OR_EQUAL,
FiltersTypesConstants::FILTER_LESS_THAN_OR_EQUAL,
],
],
];
After that you can send this param in url query, for example:
/{your_domain}/list?filter_name=lik,vitor
OR /{your_domain}/list?filter_name=eql,vitor
.
Use this project with MySql with no relationship keys and NOT use JOIN.
Don't forget to change APP_ENV
to production
value. This enable the op_cache PHP extension, so dont use in development environment.
The production docker is located in ops/docker/prod
and you can change the Nginx config or PHP all the way you want.
Want to contribute? Great!
Make a change and be careful with your updates! Any new code will only be accepted with all validations.
To ensure that the entire project is fine:
First install the dependences (with development ones)
composer install --dev --prefer-dist
Second run all validations
composer checkall
You can run all validations plus test coverage metrics
composer checkallcover
We create this project under stricts good pratices rules. Bellow you can see some composer commands to validate the framework code and your code as well.
We recommend you aways run the composer checkallcover
command to validate all your code, tests and coverage.
lint - check for sintax errors on PHP (PHP Lint)
composer lint
cs - check for smells in general (Code Snifer)
composer cs
mess - check for smells in a more deep way (Mess Detector)
composer mess
test - run all tests (Unit and Feature)
composer test
test-cover - run all tests with code coverage (Unit and Feature)
composer test-cover
test-unit - run all unit tests
composer test-unit
test-unit-cover - run all unit tests with code coverage
composer test-unit-cover
test-feat - run all feature tests
composer test-feat
test-feat-cover - run all feature tests with code coverage
composer test-feat-cover
ccu - check unit coverage level (100% is required)
composer ccu
ccf - check feature coverage level (100% is required)
composer ccf
check - execute lint, cs, mess and unit tests
composer check
checkcover - execute lint, cs, mess and unit tests with coverage
composer check
checkall - execute lint, cs, mess, unit and feature tests
composer check
checkall - execute lint, cs, mess, unit and feature tests with coverage
composer check
This project is also validated with Sonarqube, has a sonar-project.properties
file to support sonarqube execution.
To do that, edit the sonar-project.properties
with your sonar url (maybe something like http://192.168.0.2:9900 if you running sonar in your machine), and then execute sonar scan.
If you want to force the checkallcover
in your project before commit, you can just copy the file ops/contrib/pre-commit
to your .git/hook
. Be aware your development environment will need to have PHP with xdebug installed in order to commit.
cp ops/contrib/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
You can create an automatic seeder to generate data using you add endpoint to tests purposes (or any other purpose you like).
To do that you must create a random seeder with the command:
php artisan random:create {domain_name}
It will create a file inside app/Seeds/
with your domain name with all possibilities.
You may change to fullfill your needs (and your domain validations)
Now you may configure on .env
the SEED_URL
and SEED_PORT
environments. (if you want to run inside docker don't change at all).
And run your seed with the domain name and the amount to records to generate.
php artisan random:seed {domain_name} {number_of_records}
Then use the list endpoint, or make a select in database to see the results.
Not Empty Foundation - Free codes, full minds
Files (150) |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
app (9 directories) | ||||
bootstrap (3 files) | ||||
config (6 files) | ||||
ops (2 files, 3 directories) | ||||
public (1 file) | ||||
resources (1 directory) | ||||
routes (2 files) | ||||
tests (3 directories) | ||||
.dockerignore | Data | Auxiliary data | ||
.env.example | Data | Auxiliary data | ||
artisan | Example | Example script | ||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
docker-compose.yml | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpcs.xml | Data | Auxiliary data | ||
phpmd.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
requests.curl | Data | Auxiliary data | ||
requests.http | Data | Auxiliary data | ||
sonar-project.properties | Data | Auxiliary data |
Files (150) | / | app |
File | Role | Description | ||
---|---|---|---|---|
Businesses (1 file) | ||||
Console (1 file, 2 directories) | ||||
Constants (2 files) | ||||
Domains (2 directories) | ||||
Exceptions (1 file, 1 directory) | ||||
Http (5 directories) | ||||
Providers (2 files) | ||||
Repositories (1 file) | ||||
Utils (1 file) |
Files (150) | / | app | / | Console |
File | Role | Description | ||
---|---|---|---|---|
Commands (5 files) | ||||
Stubs (11 directories) | ||||
Kernel.php | Class | Class source |
Files (150) | / | app | / | Console | / | Commands |
File | Role | Description |
---|---|---|
BaseCommand.php | Class | Class source |
CreateDomainCommand.php | Class | Class source |
MigrateTemplateCommand.php | Class | Class source |
RandomSeedCreateCommand.php | Class | Class source |
RandomSeedIndexCommand.php | Class | Class source |
Files (150) | / | app | / | Console | / | Stubs |
File | Role | Description | ||
---|---|---|---|---|
Businesses (8 files) | ||||
Controllers (8 files) | ||||
Filters (1 file) | ||||
Migrations (1 file) | ||||
Parameters (1 file) | ||||
Repositories (8 files) | ||||
Routes (1 file) | ||||
Seeds (1 file) | ||||
TestFeatureControllers (8 files) | ||||
TestUnitBusinesses (8 files) | ||||
Validators (5 files) |
Files (150) | / | app | / | Console | / | Stubs | / | Businesses |
File | Role | Description |
---|---|---|
business.add.stub | Class | Class source |
business.bulk.stub | Class | Class source |
business.dead_detail.stub | Class | Class source |
business.dead_list.stub | Class | Class source |
business.delete.stub | Class | Class source |
business.detail.stub | Class | Class source |
business.edit.stub | Class | Class source |
business.list.stub | Class | Class source |
Files (150) | / | app | / | Console | / | Stubs | / | Controllers |
File | Role | Description |
---|---|---|
controller.add.stub | Class | Class source |
controller.bulk.stub | Class | Class source |
controller.dead_detail.stub | Class | Class source |
controller.dead_list.stub | Class | Class source |
controller.delete.stub | Class | Class source |
controller.detail.stub | Class | Class source |
controller.edit.stub | Class | Class source |
controller.list.stub | Class | Class source |
Files (150) | / | app | / | Console | / | Stubs | / | Migrations |
File | Role | Description |
---|---|---|
table.create.stub | Class | Class source |
Files (150) | / | app | / | Console | / | Stubs | / | Parameters |
File | Role | Description |
---|---|---|
parameters.stub | Class | Class source |
Files (150) | / | app | / | Console | / | Stubs | / | Repositories |
File | Role | Description |
---|---|---|
repository.add.stub | Class | Class source |
repository.bulk.stub | Class | Class source |
repository.dead_detail.stub | Class | Class source |
repository.dead_list.stub | Class | Class source |
repository.delete.stub | Class | Class source |
repository.detail.stub | Class | Class source |
repository.edit.stub | Class | Class source |
repository.list.stub | Class | Class source |
Files (150) | / | app | / | Console | / | Stubs | / | Routes |
File | Role | Description |
---|---|---|
route.stub | Example | Example script |
Files (150) | / | app | / | Console | / | Stubs | / | Seeds |
File | Role | Description |
---|---|---|
seed.create.stub | Class | Class source |
Files (150) | / | app | / | Console | / | Stubs | / | TestFeatureControllers |
File | Role | Description |
---|---|---|
test.controller.add.stub | Class | Class source |
test.controller.bulk.stub | Class | Class source |
test.controller.dead_detail.stub | Class | Class source |
test.controller.dead_list.stub | Class | Class source |
test.controller.delete.stub | Class | Class source |
test.controller.detail.stub | Class | Class source |
test.controller.edit.stub | Class | Class source |
test.controller.list.stub | Class | Class source |
Files (150) | / | app | / | Console | / | Stubs | / | TestUnitBusinesses |
File | Role | Description |
---|---|---|
test.unit.business.add.stub | Class | Class source |
test.unit.business.bulk.stub | Class | Class source |
test.unit.business.dead_detail.stub | Class | Class source |
test.unit.business.dead_list.stub | Class | Class source |
test.unit.business.delete.stub | Class | Class source |
test.unit.business.detail.stub | Class | Class source |
test.unit.business.edit.stub | Class | Class source |
test.unit.business.list.stub | Class | Class source |
Files (150) | / | app | / | Console | / | Stubs | / | Validators |
File | Role | Description |
---|---|---|
validator.add.stub | Class | Class source |
validator.bulk.stub | Class | Class source |
validator.dead_list.stub | Class | Class source |
validator.edit.stub | Class | Class source |
validator.list.stub | Class | Class source |
Files (150) | / | app | / | Constants |
File | Role | Description |
---|---|---|
FiltersTypesConstants.php | Class | Class source |
PatternsConstants.php | Class | Class source |
Files (150) | / | app | / | Domains | / | Auth | / | Businesses |
File | Role | Description |
---|---|---|
AuthGenerateBusiness.php | Class | Class source |
Files (150) | / | app | / | Domains | / | Auth | / | Http |
File | Role | Description | ||
---|---|---|---|---|
Controllers (1 file) | ||||
Validators (1 file) |
Files (150) | / | app | / | Domains | / | Auth | / | Http | / | Controllers |
File | Role | Description |
---|---|---|
AuthGenerateController.php | Class | Class source |
Files (150) | / | app | / | Domains | / | Auth | / | Http | / | Validators |
File | Role | Description |
---|---|---|
AuthGenerateValidator.php | Class | Class source |
Files (150) | / | app | / | Domains | / | Health | / | Http | / | Controllers |
File | Role | Description |
---|---|---|
HealthApiController.php | Class | Class source |
Files (150) | / | app | / | Exceptions |
File | Role | Description | ||
---|---|---|---|---|
Custom (7 files) | ||||
Handler.php | Class | Class source |
Files (150) | / | app | / | Exceptions | / | Custom |
File | Role | Description |
---|---|---|
DataNotFoundException.php | Class | Class source |
FilterException.php | Class | Class source |
InvalidCredentialsException.php | Class | Class source |
NotAuthorizedException.php | Class | Class source |
RouteNotFoundException.php | Class | Class source |
SuffixRequiredException.php | Class | Class source |
ValidationException.php | Class | Class source |
Files (150) | / | app | / | Http |
File | Role | Description | ||
---|---|---|---|---|
Controllers (1 file) | ||||
Filters (1 file) | ||||
Middlewares (9 files) | ||||
Parameters (1 file) | ||||
Validators (1 file) |
Files (150) | / | app | / | Http | / | Middlewares |
File | Role | Description |
---|---|---|
AuthenticateJwt.php | Class | Class source |
BaseRequest.php | Class | Class source |
Cors.php | Class | Class source |
NewRelicLumen.php | Class | Class source |
RequestFilters.php | Class | Class source |
RequestParameters.php | Class | Class source |
RequestStart.php | Class | Class source |
RequestValidator.php | Class | Class source |
SuffixTable.php | Class | Class source |
Files (150) | / | app | / | Providers |
File | Role | Description |
---|---|---|
AppServiceProvider.php | Class | Class source |
NewRelicServiceProvider.php | Class | Class source |
Files (150) | / | bootstrap |
File | Role | Description |
---|---|---|
app.php | Class | Class source |
list_config.php | Aux. | Auxiliary script |
list_routes.php | Aux. | Auxiliary script |
Files (150) | / | config |
File | Role | Description |
---|---|---|
app.php | Aux. | Auxiliary script |
newRelic.php | Aux. | Auxiliary script |
seed.php | Aux. | Auxiliary script |
suffix.php | Aux. | Auxiliary script |
token.php | Aux. | Auxiliary script |
version.php | Aux. | Auxiliary script |
Files (150) | / | ops |
File | Role | Description | ||
---|---|---|---|---|
contrib (3 files) | ||||
docker (2 directories) | ||||
mysql-db (1 file) | ||||
folders.sh | Data | Auxiliary data | ||
sonar.png | Data | Auxiliary data |
Files (150) | / | ops | / | contrib |
File | Role | Description |
---|---|---|
coverage-checker.php | Example | Example script |
pre-commit | Data | Auxiliary data |
setup.sh | Data | Auxiliary data |
Files (150) | / | ops | / | docker | / | dev | / | nginx |
File | Role | Description |
---|---|---|
default.conf | Data | Auxiliary data |
Dockerfile | Data | Auxiliary data |
Files (150) | / | ops | / | docker | / | prod | / | nginx |
File | Role | Description |
---|---|---|
default.conf | Data | Auxiliary data |
Dockerfile | Data | Auxiliary data |
Files (150) | / | routes |
File | Role | Description |
---|---|---|
auth_routes.php | Example | Example script |
health_routes.php | Example | Example script |
Files (150) | / | tests |
Files (150) | / | tests | / | config |
File | Role | Description |
---|---|---|
phpunit-feat-cover.xml | Data | Auxiliary data |
phpunit-feat.xml | Data | Auxiliary data |
phpunit-unit-cover.xml | Data | Auxiliary data |
phpunit-unit.xml | Data | Auxiliary data |
Files (150) | / | tests | / | Feature |
File | Role | Description | ||
---|---|---|---|---|
Domains (2 directories) | ||||
TestCaseFeature.php | Class | Class source |
Files (150) | / | tests | / | Feature | / | Domains | / | Auth | / | Controllers |
File | Role | Description |
---|---|---|
AuthGenerateControllerTest.php | Class | Class source |
Files (150) | / | tests | / | Feature | / | Domains | / | Health |
File | Role | Description |
---|---|---|
HealthApiControllerTest.php | Class | Class source |
Files (150) | / | tests | / | Unit |
File | Role | Description | ||
---|---|---|---|---|
Businesses (1 file) | ||||
Domains (1 directory) | ||||
Filters (1 file) | ||||
Middleware (9 files) | ||||
Parameters (1 file) | ||||
Repositories (1 file) | ||||
Utils (1 file) | ||||
Validators (1 file) |
Files (150) | / | tests | / | Unit | / | Businesses |
File | Role | Description |
---|---|---|
BaseBusinessTest.php | Class | Class source |
Files (150) | / | tests | / | Unit | / | Domains | / | Auth | / | Businesses |
File | Role | Description |
---|---|---|
AuthGenerateBusinessTest.php | Class | Class source |
Files (150) | / | tests | / | Unit | / | Middleware |
File | Role | Description |
---|---|---|
AuthenticateJwtTest.php | Class | Class source |
BaseRequestTest.php | Class | Class source |
CorsMiddlewareTest.php | Class | Class source |
NewRelicLumenTest.php | Class | Class source |
RequestFiltersTest.php | Class | Class source |
RequestParametersTest.php | Class | Class source |
RequestStartTest.php | Class | Class source |
RequestValidatorTest.php | Class | Class source |
SuffixTableTest.php | Class | Class source |
Files (150) | / | tests | / | Unit | / | Parameters |
File | Role | Description |
---|---|---|
BaseParametersTest.php | Class | Class source |
Files (150) | / | tests | / | Unit | / | Repositories |
File | Role | Description |
---|---|---|
BaseRepositoryTest.php | Class | Class source |
Files (150) | / | tests | / | Unit | / | Validators |
File | Role | Description |
---|---|---|
BaseValidatorTest.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
ala-microframework-p-2023-12-02.zip 164KB | |
ala-microframework-p-2023-12-02.tar.gz 113KB | |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.