Download the PHP package crimanne/abstract-repo without Composer

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

AbstractRepo

About

This project is a small, lightweight library for abstracting repositories and avoiding writing a lot of repository logic. It uses Reflection and PHP 8 Attributes on the abstract class (AbstractRepository) that provides basic CRUD methods.

Methods available:

Installation

You can install this library using composer with the following command:

Usage

Basically, you need to define the Entity and the repository that will use it.

Entity

You need to define a class which is the entity already created in the database and give it the Entity attribute. The Entity attributes requires the name of the database table as parameter. The model must implement the IModel interface, as shown below:

E.g.

Then you need to define the fields that must match the ones in the database.

Primary Key

To define a primary key, you have to use the PrimaryKey attribute on the field. The attribute accepts a boolean in the constructor indicating whether the primary key is auto increment.

E.g.

Foreign Key (ManyToOne, OneToOne, OneToMany)

When working with a foreign key in an entity, you can specify one of the following attributes:

Both ManyToOne and OneToOne attributes require the columnName parameter to be provided in the constructor. This parameter is used to map the foreign key with the column name in the database.

E.g.

To have a OneToMany relation you need to declare a nullable array, this will contain all the related ids. The attribute requires two params:

In the example you can see a OneToMany relationship between Author and Book. In the table book there must be the column author_id in order to complete the relationship.

Searchable

The repository offers an utility method called findByQuery that will accept a query search term, and it will retrieve all the records that match (even partially) that query. In order to do that you need to specify in the model which fields can be included in the research by using the attribute Searchable. If the attribute is put on a OneToOne or ManyToOne relationship property, the method will also look for all the searchable fields in the related model. Please note that this process will get only the searchable fields of the direct related entity, and it will not go further than one level of nesting.

E.g.

Repository

After defining the entity, you have to create the repository that must extends the AbstractRepository class. Then you need to define the getModel method to return the classname of the entity that you want to handle in that repository.

E.g.

The repository needs a PDO instance in construction, this can also be done with Dependency Injection.

Demo

A small demo project can be found in the demo/ folder

#

Copyright 2024 by Cristian Mannella

AbstractRepo by Cristian Mannella is licensed under Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International

CC BY NC ND


All versions of abstract-repo with dependencies

PHP Build Version
Package Version
Requires php Version ^8.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 crimanne/abstract-repo contains the following files

Loading the files please wait ....