jmrg / chip-modules
Components to build a PHP Micro-Framework.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=5.6.4
- hoa/session: ~0.0
- illuminate/database: 5.4.*
- klein/klein: 2.1.*
- philo/laravel-blade: 3.*
- phpmailer/phpmailer: ~6.0
- symfony/config: 3.4.*
Requires (Dev)
- guzzlehttp/guzzle: 6.3.*
- kint-php/kint: 2.2.*
- phpunit/phpunit: ~5.0
- symfony/process: 3.4.*
This package is not auto-updated.
Last update: 2025-03-19 06:20:04 UTC
README
Chip-modules is a set libraries that encapsulate their implementations to way easy and faster and provides the methods to access in an only step.
Components
This includes handlers for:
- Klein - Router, controllers, and endpoints.
- Symfony Config - Configuration from environment file.
- Eloquent - Database and models.
- Hoa Session - Session handler.
- Blade - Template manager and views.
- PHPMailer - Full manager to send emails.
Installing Chip-modules Composer
You can install Chip-modules into your project using Composer. For existing applications you can run the following:
$ composer require jmrg/chip-modules:"~0"
Usage Instructions
Environment Config
To configure the params of the environment to create a file YAML like this with the database connection and parameters of SMTP:
# There are file for example named example.environment.yaml databases: prod: driver: mysql host: localhost database: database username: root password: secret charset: utf8 collation: utf8_unicode_ci mail: # 0 = off | 1 = Client messages | 2 = Client and server messages debug: 2 # Basics driver: smtp host: smtp.mailtrap.io port: 2525 username: null password: null # Encryption system: tls, ssl (deprecated) encryption: null
After that, we shoulder load the file.
// Load file... ConfigModule::init('path/to/file/config.yaml'); // Getting config... $c = config(); // Return the config as array.
Router Config
To configure the router we make the following:
// Creates a new object to the configuration. $config = new \Chip\Modules\Router\RouterConfig(); $config->setBaseNamespace("\\Namespace\\to\\controllers") // Namespace source path. ->attachRouterFiles('path/to/endpoints/router.php'); // Location for the file router. // Dispatch resquest. $r = \Chip\Modules\Router\Router::up($config); $r->dispatch();
Example using router:
// File router.php // Methods availables according to HTTP verbs: get(), post(), put(), pat(), delete(), options(). $router->get('/hellow-world', function () { return 'Hellow World!!'; }); // To response multiple HTTP verbs: $router->match(['get', 'post'], '/hellow-world', function () { return 'Hellow World!!'; });
Databases and Model Config
To configure databases we make the following:
// In the file configuration environment, we have a sections with the // connections to the different databases, we only must send // a connections name to configure de database. \Chip\Modules\Model\Manager::db('nameDatabase'); // In the case of models, these must extend from \Chip\Modules\Model\Model class User extend \Chip\Modules\Model\Model { // Something code.. }
Session Config
To configure session we make the following:
// Recomended to use name "guest" for the session. \Chip\Modules\Session\Session::of('Guest'); // To get the session to use a guest() method. // This returns an instance of Hoa Session. Check out the documentation // of lirary for any information https://github.com/hoaproject/Session $session = guest();
Views and Blade Config
To configure the blade manager template we make the following:
// Define path to views and cache. ViewComponent::config( '/path/to/source/views', '/path/to/cache' ); // Load the view... view( 'name-view', ['param1' => 'Hello', 'param2' => 'World!!'] ); // To build views check out the documentation https://laravel.com/docs/5.1/blade
Email Config
To configure the first that we make is fill the environment file with the params require:
# There are file for example named example.environment.yaml mail: # 0 = off | 1 = Client messages | 2 = Client and server messages debug: 2 # Basics driver: smtp host: smtp.mailtrap.io port: 2525 username: null password: null # Encryption system: tls, ssl (deprecated) encryption: null
To get a instance the handler email we make follow:
// Create a new isntance Mailer class. $mailer = \Chip\Modules\Mailer\Mailer::create(); // To send emails or making config aditionals check out the documentation https://github.com/PHPMailer/PHPMailer
Test
This project use PHPUnit to make test. To execute the test run the follow command:
$ vendor/bin/phpunit