Download the PHP package modulusphp/hibernate without Composer
On this page you can find all versions of the php package modulusphp/hibernate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download modulusphp/hibernate
More information about modulusphp/hibernate
Files in modulusphp/hibernate
Informations about the package hibernate
Modulus Hibernate Component
This component is responsible for Modulus' caching, handling Queues and also extends Eloquent Models.
Install
This package is automatically installed with the Modulus Framework.
Getting Started
Session (alpha)
A more secure session handler. Hibernate's session handler is more secure and supports more Store Driver's than Modulus's default Blulight Session handler.
To switch to Hibernate's session handler, go to the index.php file in the public directory, and remove Blulight.
Then register the following middleware's in the HttpFoundation class:
Once that has been done, head over to the VerifyCsrfToken class and extend Hibernate's VerifyCsrfToken class:
Note, this may not work
Now, update the session.php config file with the following content:
And you're done!
Note, this is still a work in progress, so do not use it in production
Logging
Hibernate's logger, is meant to be a replacement of @atlantisphp's telemonlog package. Built on top Monolog, you get a more stable and widely supported logging library.
See the config
logging.phpfor more information
Queue Worker (alpha)
The Queue Worker allows you to easily execute tasks in the background. This is done by using Supervisor.
Before you can start creating or executing queues, you need to create a new table that will hold your queues.
Create a migration:
If you are using sqlite as your default Database driver for Queues (which you should be), you will need to create a new .queues file:
See config/queue.php and .env for more information.
Don't worry about having your queues stored in a
sqlitefile, all queues are encrypted using theAPP_KEY.
Run the migration:
To create a new Job, simply run the following command:
To execute the newely created job:
You can also delay a Job by minutes, hours, days, months or even years. This means, you can execute a job that will only run when you want it to run
This Job will run after 10 minutes.
Note: your supervisor worker must call
craftsman queue:work --process=1
Hibernate Cache
Hibernate Cache is a simple caching system that allows you to store objects, collections, arrays, and other object types. The Hibernate Cache allows you cache forever or specify when a cache should be removed or when it should expire.
The code above will keep the user array until we decide to remove it.
If we wanted to wanted to keep the user array for a month, all we would need to do, is simply add a Carbon instance as a 3rd argument:
Now, the user array will be automatically removed from the cache after a month.
Note: you must add a cron that executes
craftsman schedule:runevery minute (* * * * *)
Configuration
Out of the box, Hibernate Cache can use both redis and/or file based caching. file based caching is used as the default caching driver.
You can easily use redis as the default caching driver by simply setting HIBERNATE_CACHE to redis in the .env.
Methods
Here are some methods to help you get started.
| Name | Helper Method | Arguments | Return | Description |
|---|---|---|---|---|
Cache::set() |
cache($key, $value, $expiration) |
string $key, mixed $value, ?Carbon $expiration |
bool |
Set or overwrite cache |
Cache::forever() |
cache($key, $value) |
string $key, mixed $value |
bool |
Cache forever |
Cache::get() |
cache($key) |
string $key |
mixed |
Get cached key |
Cache::has() |
string $key |
bool |
Check if item is cached | |
Cache::forget() |
string $key |
bool |
Remove cached item | |
Cache::pull() |
string $key |
mixed |
Remove cached item |
Hibernate Mail
Sending emails has never been this easy. Hibernate Mail is a Mailer package built on top of PHPMailer. Creating layouts and sending emails is a lot easier and smoother.
The code above, will send a welcome email to "[email protected]" in the background.
Getting Started with Hibernate Mailer
You can create a new Email Class Template by running the following command:
Your Email Class Template should look like:
Before you can do anything else, you will need to create a new Email View Template in your views:
After that, we can start designing our Email View Template. Here is a quick example:
The {% email_layout %} directive will add all the necessary css styling and html code to make your view look decent.
The {% email_layout %} directive includes the main and footer section.
The {% email_footer %} directive will add a copyright text at the bottom of all the emails sent from your application. The env('APP_NAME') (name of your application) will be used here.
You can also include action buttons in your Email View Templates. The {% email_action("title", "url", "alginment") %} helps you add a button in your views:
You can set the alginment to "right", "left" or "center".
To make your Email Class Template load the Email View Template you just created, you just need to specify the view from the build method:
You can also pass variables from your Email Class Template to your Email View Template using the with method:
Then you can access the variables like:
Testing Email Templates
You can easily test your Email Templates by returning an instance of a Email Class Template from a route:
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
All versions of hibernate with dependencies
modulusphp/support Version 1.9.*
monolog/monolog Version ^2.0
phpmailer/phpmailer Version ^6.0
predis/predis Version ^1.1