Download the PHP package smhdhsn/zed without Composer
On this page you can find all versions of the php package smhdhsn/zed. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package zed
Short Description ZED is an API-Based Micro-Framework powered by PHP.
License MIT
Informations about the package zed
About
ZED is an API-Based Micro-Framework powered by PHP.
Features
- ORM.
- Routing.
- Migration.
- Command.
- Request Validation.
Getting started
Make sure you have composer
installed in your machine and then create a new ZED project using composer:
After the application has been created, you may start ZED's local development server using command line:
You can provide a custom port to serve on like the following:
Documentation
Routing
Defining routes
You can choose between three options for defining a route for your application.
Via closure
Via string
Via array
Middleware
You can implement a middleware to a route like the following.
:information_source: You need to list the method name that is responsible for your middleware inside the array.
Protecting routes
As I mentioned before, you can provide middleware within an array as the third parameter to the route.
:information_source: The auth middleware is powered by JWT and is responsible for protecting routes from unauthenticated requests.
Route params
You may wish to pass your route parameters to your application. You may do so like the following.
:information_source: In your controller or closure you'll receive Request object as your first parameter.
Request
Request object contains every parameter passed to the application, whether it's from request body or query string, you can access request params like following:
Request validation
You can validate your request and in case of any errors show a proper error message.
Available validation rules
Required
The field under this rule is required and must be provided to the application.
String
The field under this rule must be a valid string.
Numeric
The field under this rule must be a valid numeric string.
The field under this rule must be a valid email.
Maximum
The field under this rule must contain less characters than given value.
Minimum
The field under this rule must contain more characters than given value.
Unique
The field under this rule must be unique in the database, you have to provide the column you wish to check for uniqueness of the request attribute after table name.
In this case, application will look through users table on database and checks if column email exists with the same value or not.
Response
The only available response type is JSON, for the sake of consistency of response properties you may use Controller's response() method. This method accepts 3 parameters: Response word, Response data, Response HTTP-code.
You may want to check out Response class, there's plenty of response words and codes there that you can use.
Error
In case of possible errors you can also use Controller's error() method:
ORM
ZED Provides some functionalities to interact with the database and perform simple CRUD operations.
Creating
Finding
You have 2 choices, whether you can find a record with where clause or you can find the record by their unique id.
Where clause
Returns a collection of objects, returns an empty collection if there's no matching record.
Find method
Returns an object of type model, throws a NotFoundException
if there's no matching record.
Updating
Deleting
Command
ZED also provides a way to interact with the application via the command line. You can create your own command with the command below:
This command will create your command in path App/Commands
.
After creating the command you need to address it to the application inside Routes/command
file like the following:
You can also provide a closure as the second parameter to the define method to handle your command's action:
:information_source: Every parameter after the command name can be accessed within the command's class or closure.
Inside command.php file:
Also, the class CommandLineInterface includes massive command-line options for you to take advantage of like cli color, background, font, etc...
Predefined commands
Migrate
This command handles migration operations
Running migrations:
Rolling back migration:
Resetting all migrations:
Resetting and then running all migrations again:
Make
This command is responsible for creating classes within the application to save time.
Creating a new controller:
Creating a new model:
Creating a new repository:
Creating a new service:
Creating new migration:
Creating new command:
License
The ZED micro-framework is open-sourced software licensed under the MIT license.