yknsilva / phractico
A PHP micro-project for APIs
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 1
Open Issues: 1
Type:project
Requires
- php: ^8.2
- guzzlehttp/guzzle: ^7.8
- symfony/http-foundation: ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.42
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.5
README
🚀 Go fast with phractico, a PHP micro-project designed to accelerate your API projects with simplicity.
composer create-project yknsilva/phractico
Summary
Usage
phractico was designed with your precious resource in mind: time! ⌚
The phractico ideology involves fewer configuration files to get your PHP API working. The Bootstrap file concentrates the entire application configuration for controllers, routing, etc.
To introduce new endpoints in your API, you simply need to create a controller class by
implementing the Controller
interface and its routes
method.
Then, describe routing resources to their actions. Finally,
map the new controller in ApplicationControllerProvider.php.
Voilà ! 🎉
For examples, see ExampleController.
Database
Your database connection must be mapped inside ApplicationDatabaseProvider.php class, which is consumed by bootstrap file when application is initialized.
By default, phractico comes with a SQLite database adapter
assuming database file is located at path /path/to/phractico/database/database.sqlite
.
If you want to have others adapters, you just need to implement Connection
and then mapping your new adapter in ApplicationDatabaseProvider
file.
Container DI
phractico uses a dependency container to manage dependencies throughout the application. The container and its corresponding dependency mapping are declared in ApplicationContainer. During the application's runtime, the dependency container is injected into the application instance and then used in application bootstrap phase.
While phractico includes a simple container, it is designed to support any other dependency injection container that implements the PSR-11, such as PHP-DI.
Installation
Go fast with phractico and phpctl:
- Run
composer
phpctl composer install
- Run a local server
phpctl server 8000 public/
- Perform an HTTP request to ensure everything works fine!
curl -X GET 'http://localhost:8000/example'
- Perform an HTTP request to ensure database connection works fine!
- Note:
sqlite3
PHP extension is required forSQLiteAdapter
- Note:
curl -X POST 'http://localhost:8000/exampleDatabase' \ --header 'Content-Type: application/json' \ --data '{ "test": "database" }'
Tests and Quality Tools
To execute all PHPUnit test suites, run:
phpctl composer test
To execute quality tools, run:
phpctl composer quality
Contributing
Feel free to explore the project and turn phractico more practical!