Download the PHP package nassiry/laravel-encoder without Composer

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

Tests Packagist Downloads Packagist Version Laravel PHP License

Laravel Encoder Package

The Laravel Encoder package provides a robust and secure way to encode and decode IDs & Strings using customizable Base encoding mechanisms (Base62). With support for variable-length encoding, mappers for added security, and seamless integration with Laravel, this package is ideal for obfuscating sensitive data or creating URL-safe identifiers.

Why I Created This Package

In one of my Laravel projects, I needed a way to encode & decode some strings. Initially, I tried using Laravel's built-in encrypt and decrypt functions, but they returned very long strings, which were not ideal for my use case. Next, I turned to Base64 encoding, but I still needed to make it URL-safe, which added complexity. After looking around, I realized that there wasn't a straightforward package that supported encoding both IDs and strings while providing a customizable approach and URL-safe encoding. So, I decided to create this package. It started as a solution for my Laravel project, but I quickly realized its usefulness beyond that and made it a standalone package that can be used in any PHP project. With this package, I aimed to provide a simple, secure, and customizable encoding/decoding mechanism with support for Base62 encoding (which is URL-safe), and the ability to easily add more bases like Base58, Base64, or even your own custom encoding schemes.

Warning: This package is designed for encoding and obfuscation, not for encryption. It does not provide strong cryptographic security. Use it for non-sensitive data or as a lightweight obfuscation method.

Features

  • Base Encoding: Supports customizable bases, including Base62 and others.
  • Variable-Length Encoding: Allows encoding with custom lengths for obfuscation.
  • Mapper-Based Obfuscation: Adds an extra layer of security by using configurable prime numbers and mappers.
  • Customizable Configuration: Publish the configuration file to override default mappers.
  • Exception Handling: Provides detailed exceptions for invalid inputs.
  • Laravel Integration: Works seamlessly with Laravel’s service container and configuration system.
  • Security: Protects sensitive IDs by ensuring encoded values are not easily reversible without the correct configuration.

Requirements

Installation

Step 1: Install via Composer

Laravel Integration

This package integrates seamlessly with Laravel, making it easy to encode or decode IDs and strings using the service container, dependency injection, or facades.

Using the Service Container

Using Dependency Injection

For better maintainability and testability, inject the encoder into your controllers or services:

Using the Facade

The package provides a facade for quick access to encoder methods:

Standalone Usage

To use the package in a non-Laravel PHP project, follow these steps:

  1. Usage Example

  2. Custom Configuration

    When using a custom configuration, ensure that the $length parameter in the encodeId function is an index within the configuration array. It must be smaller than the last index of the configuration array.

Important Notes:

  1. The $length parameter represents the index in the configuration array, not the key value.
  2. It must always be smaller than the highest index of the configuration array.
  3. For example, in the above $config, the valid values for $length are 0, 1, 2, 3, or 4 (total of 5 elements, indices 0–4).

    Encoder Configuration File

    Note: This configuration file is applicable only when using the package with a Laravel application. For standalone usage, you need to provide configuration directly while initializing the Encoder class. This file allows you to set up the default base encoder and customize its behavior within Laravel. By default, the package uses the base62 encoder, but you can define additional configurations for Base62 or other custom Base classes that you may add via the Factory.

    Default Base62 Configuration

    If you are using the default Base62 implementation, you can override its default mappers by specifying custom mappings in the config array below. These mappers are used to obfuscate the encoding process by applying prime numbers for variable-length encoding. Example for overriding Base62 mappers:

Usage in Laravel

To publish this configuration file, run the following command:

After publishing, you can modify the configuration to suit your application's needs.

Custom Bases: Add Your Own Encoding Scheme

Register the new base in the BaseFactory - create method:

Use your custom base like this:

Handling Exceptions

The package throws meaningful exceptions for invalid input and other runtime issues, making it easier to debug and handle errors gracefully. The EncoderException class extends PHP's RuntimeException and provides static methods for creating specific exceptions.

Common Exceptions

Example: Catching Exceptions

You can wrap your encoding/decoding logic in a try-catch block to handle exceptions gracefully:

Testing

To ensure the package functions as expected and meets all requirements, you can run the included tests. Follow the steps below to execute the test suite:

Prerequisites

  1. Ensure you have all dependencies installed by running:

  2. Verify that the required PHP extensions (bcmath and mbstring) are enabled.

    Running Tests

    Execute the following command to run the test suite:

Test Coverage

The package comes with extensive test coverage for encoding and decoding methods, exception handling, and configuration. This ensures robust behavior across various use cases.

Contributing to Tests

If you encounter a bug or add a new feature, consider writing or updating the tests. Use the following guidelines:

  1. Add your test cases to the appropriate files in the tests directory.
  2. Follow the PSR-12 coding standards for consistency.
  3. Run composer test again to verify that all tests pass before submitting a pull request.

    Why Base62?

    Why Base62?

    Conclusion: Why Choose This Package?

    Conclusion

    Contributing

    Feel free to submit issues or pull requests to improve the package. Contributions are welcome!

License

This package is open-source software licensed under the MIT license.


All versions of laravel-encoder with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-mbstring Version *
ext-bcmath Version *
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 nassiry/laravel-encoder contains the following files

Loading the files please wait ....