Download the PHP package sevval42/spade without Composer

On this page you can find all versions of the php package sevval42/spade. 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 spade

Spade

A lightweight PHP framework for learning purposes and small personal projects.

This framework provides dependency injection, request and response classes and a router, a simple ORM and very simple templating. Examples can be seen in this projects src directory.

Note: Spade is intended for educational use and small projects, it therefore is not optimized or secure in any way.

Installation

Install will be available via composer

If you want to try this example repository out, clone it and run docker:

The routes in routes/web.php can be tried out at http://localhost

Basic usage

This section will describe the base functionality provided by this framework, as well as give some short examples and restrictions.

Router.php

A route can be added to the Router by specifying the method, route and a callable, for example like this:

The route parameter uses {variableName:regex} for specifying attributes. The handle method of the given Controller can then use the attributes like this:

You can dispatch a request like this:

All this is actually handled by the App class, which can be called to initialize and dispatch routes with the router, by calling its initRoutes(array $routes) and handle(Request $request) methods.

Responses

There are a few basic Response classes, this framework provides. Simple message Responses can use the base Responseclass, while the frameworks templating uses the ViewResponse which will be further discussed in that section.

Dependency Injection

The dependency injection is handled by the Container.php class. You can set the necessary base dependencies with the set(YourClass::class, fn() => $yourClass) method, and then get(YourClass::class) objects of the given class.

This should be setup in the entry point of your program, an example can be seen in public/index.php.

Database layer

Spade has made a few abstractions, although it does not have a query builder yet.

Connection.php

This is the base class, that abstracts the PDO class given by PHP. It gives the user multiple methods to do simple queries, like:

Queries
Updates
Deletes

This layer should not be used for entity handling though, as this is handled by the BaseRepository and EntityManager classes:

BaseRepository.php and BaseEntity.php

This frameworks ORM maps database tables to Classes which extend from the abstract BaseEntity class, thus Entity has the $id identifier. Furthermore, each entity class needs to implement the getTableName(): string method, which returns the database table name.

Class Attributes need to be snake_case in the database and camelCase in the Entity. For example,

maps to

The abstract BaseRepository.php class gives functionality for reading data and implements find(int $id) and fetchAll() methods. Classes that extend from this BaseRepository need to implement the getEntity() method, which returns the Entity class-string, this repository watches.

A UserRepository could look like this:

EntityManager.php

To persist changes in the database, the EntityManager is used. It automatically tracks objects which extend from the BaseEntity class and that are fetched from the database using the Hydrator.php class.

New entities can be persisted with the persist($entity) method and removed with the remove($entity).

Any changes will be written to the database, when calling the flush method: $entityManager->flush().

Templating

Spade provides very simple templating with pages and partials. It does not have any logic yet. The TemplateService.php class needs to be initialized with the paths to the pages and partials like this (example):

These templates can than be returned by the ViewResponse class like this:

where the info.php template is in src/Templates/Pages/user/info.php.

A simple page might look like this (info.php):

where variables with three curly braces (like {{{ user.firstName }}}) are not escaped.

The given data array might look like this for the given example:

If a variable is not filled in the $data array, the template leaves the variable empty.

License

This project is licensed under the MIT License. See the LICENSE file for details.


All versions of spade with dependencies

PHP Build Version
Package Version
Requires symfony/var-dumper Version ^7.3
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 sevval42/spade contains the following files

Loading the files please wait ...