Download the PHP package michalsn/codeigniter4-uuid without Composer

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

CodeIgniter 4 UUID PHP Tests

This package make it easy to work with UUIDs in Codeigniter 4. It provide four classes to make that possible: Uuid, UuidModel, UuidEntity and UuidCast. This implementation is tighly coupled with Ramsey\Uuid.

Installation via composer

composer require michalsn/codeigniter4-uuid

Manual installation

Download this repo and then enable it by editing app/Config/Autoload.php and adding the Michalsn\UuidModel namespace to the $psr4 array. For example, if you copied it into app/ThirdParty:

Versions

CodeIgniter version This package version
>= 4.5 >= 1.1
< 4.5 < 1.1

How to use it

In general, using UuidModel and UuidEntity is no much different than using the original classes provided with CodeIgniter 4 framework. We just have some additional config options. There is a good chance that you will not need to use Uuid class at all, because most of the things that happens are already automated.

Uuid

Working with Uuid class is really simple:

If you have any additional configuration options to set to a specific UUID version then you can do it via config file.

UuidModel

UUID fields are always returned as a string even if we store them in byte format in the database. This decision was made because of the convenience of use. We don't have to worry about field type or conversion of the data.

Parameter Default value Description
$uuidVersion uuid4 Defines the UUID version to use.
$uuidUseBytes true Defines if the UUID should be stored in byte format in the database. This is recommended since will allow us to save over half the space. Also, it's quite easy to use, because we always translate UUID to a string form when retrieving the data or to a byte form when we are saving it.
$uuidFields ['id'] Defines the fields that will be treated as UUID. By default we assume it will be a primary key, but it can be any field or fields you want.

Now, let's see a simple example, how to use UuidModel in your code. In example below, there are no additional changes except that our model extends UuidModel. The primary key will be stored as UUID4 in the byte format in the database.

Now, here is an example where we will use the UUID but not as a primary key.

UuidEntity

Using the UuidEntity is only required if we store UUID fields in the byte format. In other case there are no benefits over original Entity class. The same as in the UuidModel, by default we assume that only primary key will have the UUID type.

Parameter Default value Description
$uuids ['id'] Defines the fields that will be treated as UUID. By default we assume it will be a primary key, but it can be any field or fields you want.

Now let's see a two examples which will match those for models that were previously shown.

And that pretty much it. No more changes are needed.

UuidCast

NOTE: Don't use this casting class if you intend to use the UuidModel class.

Since CodeIgniter now allows the use of custom cast classes in Entities, we've also added our own casting class. This casting class enables the UUID to be converted from byte to string during data retrieval and reverse on data setting. Normally you will not use the cast function as the transition from strings to bytes is done in the UuidModel class. With that in mind, you should only use this cast feature when you want to work with the Entity without using UuidModel class later.

This is a simple example of how we would use our casting class with Entity.

Limitations

For now this class doesn't support SQLite3 database when you want to strore UUIDs in a byte format.

Supported UUID versions

License

The MIT License (MIT). Please see License File for more information.


All versions of codeigniter4-uuid with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ramsey/uuid Version ^4.7
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 michalsn/codeigniter4-uuid contains the following files

Loading the files please wait ....