Download the PHP package guilhermecostam/lamiaphp without Composer

On this page you can find all versions of the php package guilhermecostam/lamiaphp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package lamiaphp

LamiaPHP

:izakaya_lantern: A minimalist MVC framework for PHP

License MIT

Content

After you have all the dependencies installed, just follow these commands:


Running Lamia

Installation done, now we will run the application. Initially we will create the .env file and fill in the blank information in it.

Note that the database host is already defined.

This is because the database is being run in docker, so the database host is the docker's IP address, which is usually 127.0.0.1.

If your machine is not 127.0.0.1, just run ifconfig (linux) or ipconfig (windows) to find out which IP your docker is running on.

Now we will install the composer dependencies and run the containers.

Finally, if all the steps have been followed correctly, the application is already running on localhost and ready to receive the database migrations.


Models, controllers and views

Model

The models must be in the app/Models/ directory and extend the Model abstract class:

The models in the application serve to communicate the PDO section.

Controller

The controllers must be in the app/Controllers/ directory and extend the Controller abstract class:

The controllers in the application serve to intermediate the requests sent by the Models. This is also where the validations of the data provided on the forms are made.

View

The views must be in the app/Views/ directory and is the layer where the visual information of the application should be contained. Only templates should come here, CSS styles and JavaScript files that can be accessed publicly should go in the public/ directory.

To render the views you need to import the view class where you want to call it and call the render method with the specified directory:

Note that here you only need to specify the folder created for the view and the file name without the .php, because the render function already accesses the app/Views/ directory directly, along with the extension.

If you want to send information to the View scope, just create an array containing it. To access it in the view, just call the variable $args specifying the key sent:

Finally, views also render http errors. Just create the view with the error you want in the app/Views/error/ directory and call the errorCode function passing the error as an integer. It also has a redirect method which redirects to the url passed as a parameter:

It is worth noting that the errorCode function also takes arguments like render.


Routes

Introducing routes

The application routes must be in the routes/ directory. The correct way to write them is to separate them into files that have nomenclatures related to the grouped routes. For example, the routes responsible for a coffee CRUD should be contained in the coffee.php file, and those for a beer CRUD should be contained in beer.php.

However, nothing stops you from putting all of the application's routes into a single file.

To create routes is simple. Just include the Router classes and the controllers that have the functions to be used:

After that, simply create an array $routes and structure it as follows, calling the Router's createRoute function:

In case of fetching an undefined route, the application is already prepared to return a 404 error view.

Merging routes

For the system to recognize the routes created, it is necessary to merge the files created in the web.php file:


Database

PDO

For the database MySQL is being used. We will use PDO to communicate with the database and create queries.

In the abstract class Model the connection to the database is already made with the instance of the Connection class. Just call the db attribute in the class that extends model and call the following methods:

It is worth pointing out that it is also possible to bind values with the mentioned methods. Just create the following query, passing also an array with parameter that are the values to be replaced:

Migrations

In Lamia you can use migrations via Phinx. The migrations automatically go into the database/migrations/ directory by creating them with the following command:

For more details on writing migrations and the rest of Phinx's functionality, see its documentation.


Validating

Introducing validations

If you want to validate the data in a form, Lamia has a native functionality for this. Just create files to write the rules to in the app/Requests/ directory. In each file you must extend the abstract class Request:

To perform validations, you must create a public method validations. This will return an array_merge with the return of each validated field.

The validate method called in the merge must receive two parameters. These are the name of the field to be validated and an array of validations that should be applied to the value assigned to the field.

Observations:

  • The array that 'validate' receives must have items where the key is the name of the validation predefined in the application and the value is the message to be displayed if the validation fails.
  • Note that each call of the extended validate method of Request is for one field of the form.

Now just include the request where you want to perform the validations and call the validations method:

Validation list

Here is a list of all the validations available in the application:

Name Description
required Validate if value is empty
isArray Validate if value is an array
isString Validate if value is an string
isInteger Validate if value is an integer
isFloat Validate if value is an float
isBoolean Validate if value is an boolean
isEmail Validate if value is an boolean
isUrl Validate if value is an url
isValidDate Validate if value is a valid date

Testing

For the unit tests PHPUnit is being used. The tests should be written in the tests/ directory and to run them just run the following command:

For more details on writing tests, assertion lists, and the rest of PHPUnit's functionality, see its documentation.


How to contribute

Do you want to contribute to the Lamia? Just follow these instructions:

  1. Fork this repository.
  2. Clone your repository.
  3. Create a branch with your feature: git checkout -b my-feature
  4. Commit your changes: git commit -m 'feat: My new feature'
  5. Push to your branch: git push origin my-feature
  6. Come in Pull Requests from the original project and create a pull request with your changes for dev branch.

After the merge of your pull request is done, you can delete your branch and wait for the feedback.


License

This project is licensed under the MIT License - see the LICENSE page for details.


All versions of lamiaphp with dependencies

PHP Build Version
Package Version
Requires robmorgan/phinx Version ^0.12.10
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package guilhermecostam/lamiaphp contains the following files

Loading the files please wait ....