Download the PHP package n0nag0n/super-model without Composer

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

Dependencies Build Status codecov contributions welcome HitCount

Update

It is highly recommended that you use flightphp/active-record instead of this library. No further development will be done with this library, but it does work as it is right now.

Super Model

Super model is a very simple ORM type php class to easily interact with tables in a database without writing a ton of SQL code all over the place.

To prove it, here are the lines of code...

This is written with performance in mind. So while it will not satisfy every single requirement in every project that's ever been built, it will work in the majority of cases, and do a kick butt job at it too!

Basic Usage

Getting started with Super Model is easy, simply extend the super model class and define a table name. That's about it.

Now what about some simple examples of how she works?

First, lets assume the following table:

Easy peasy, lemon squeezy right?

Docs

getBy*(mixed $value): array [result]

This is a method that returns one row back from the value specified. The * part of the method refers to a field in the database. The field name is case-sensitive to whatever your field name is on your database table.

getAllBy*(mixed $value): array [ [result], [result] ]

This is a shortcut filter to return all rows by a given value. The * part of the method refers to a field in the database. The field name is case-sensitive to whatever your field name is on your database table.

getAll(array $filters, bool $return_one_row = false): array [ [result], [result] ] or [result]

This is the filter where you can add a bunch of customization to filter the data from your table. There are a few unique keys to be aware of and some operators to help you pull your specific data.

There are also some basic config options with the model properties.

$disallow_wide_open_queries

If you have a model that you know will always return a small result set and want to be able to query the entire table, set this property. Otherwise it is a protection so that if no sql params were supplied, you wouldn't retrieve back the entire result set (which could crash and burn many things).

create(array $data): int [insert id]

This will create a single row on the table, but if you supply a multi-dimensional array, it will insert multiple rows. A primary key of id is assumed.

update(array $data, string $update_field = 'id'): int (number of rows updated)

This will create a single row on the table, but if you supply a multi-dimensional array, it will insert multiple rows. A primary key of id is assumed.

FAQ (Advanced Usage)

What if you want an automated way to alter your result if a specific flag is fired? Easy peasy. There is a method called processResult() that will run through every result you pull back. You inject special filters for this method in the $filters['processResults'] key.

What if you need to do a crazy complex SQL query that doesn't fall in the realm of this class or the getAll() filters?

Remember the point of this class is NOT to satisfy every requirement from every project that ever has or will exist, but it will get you 90% the way there. In light of that, there is a simple way to execute the above question. Just use RAW SQL for your one off.

Testing

Simply run composer test to run phpunit and phpstan. Currently at 100% coverage and that's where I'd like to keep it.

A note about 100% coverage: While the code may have 100% coverage, actual coverage is different. The goal is to test many different scenarios against the code to think through the code and anticipate unexpected results. I code to "real" coverage, not "did the code run" coverage.


All versions of super-model with dependencies

PHP Build Version
Package Version
No informations.
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 n0nag0n/super-model contains the following files

Loading the files please wait ....