GithubHelp home page GithubHelp logo

crafty's Introduction

بسم الله الرحمن الرحيم

Crafty

Some essential helpers to rely on during TALL stack development.

Latest Version on Packagist GitHub Tests Action Status Codecov Total Downloads

Description

Contains some helper service classes (that you can use as Laravel facades). And it has some global helper functions for quick actions as well... Pretty much the things we found ourselves needing and without having a "strong" reason to PR Laravel about.

Installation

  1. Install the package via composer:

    composer require VPremiss/Crafty
  2. Publish the config file using this Artisan command:

    php artisan vendor:publish --tag="crafty-config"

Upgrading

  1. Backup your current config.

  2. Republish the package stuff using this Artisan command:

    php artisan vendor:publish --tag="crafty-config" --force

Usage

  • Enumerified

    • Can be applied to enums to extend their TALL abilities.
  • Installable

    • Used along HasInstallationCommand trait on the package service provider, in order to implement an installation command.
    • Needs the installationCommand() method applied within the laravel-package-tools service provider's bootingPackage() method.
  • Configurated

    • Ensures, as a package service provider's interface, that package configurations are validated and handled gracefully.
    • During packageRegistered(), you have to call registerConfigurations() method that's available in ManagesConfigurations trait.
    • It's used along CraftyPackage::getConfiguration() method.

API

Below are the tables of all the Crafty package helpers:


Interface Description
Configurated Ensures that the package service provider has what's needed to deal with configurations internally. It Makes them compatible to be used in other packages and tests! Check out ManagesConfigurations trait.
Installable Ensures that the package service provider has what's needed for its installation command. Check out HasInstallationCommand trait.

Trait Description
Enumerified Extends enum functionality to retrieve counts, random instances, and enum collections.
HasInstallationCommand Makes installationCommand() method available to be used in bootingPackage() method in order to set up an installation command.
ManagesConfigurations Registers configurations and their validations for CraftyPackage to be able to handle them whenever they're needed.

Laravel Rule Description
EnumsArray A validation rule that ensures an attribute is a filled array of valid enum values from a specified class.

Crafty Facade Method Description
chunkedDatabaseInsertion(string $tableName, array $dataArrays, ?Closure $callback = null): void Handles database insertions in chunks with configurable chunk size and default properties.
uniquelyMetaHashSuffixed(string $string): string Appends a unique hash suffix to a string. Utilizes the global helper function unique_meta_hashing_number of this same package.
reverseString(string $string, EncodingType $encoding = EncodingType::UTF8): string Reverses a string according to the specified encoding type.

CraftyPackage Facade Method Description
getConfiguration(string $key, $default = null): mixed Returns the package configuration value gracefully after validation. Still, you must implement Configurated interface and ManagesConfigurations methods for it to work.
setConfiguration(string $key, mixed $value): void Sets a configuration value for a specified key. This method does not validate the value itself; use setConfigurationValidation to establish value constraints. Requires Configurated interface too.
setConfigurationValidation(string $key, callable $closure): void Registers a validation function for a specific configuration key. The function is called to validate the value each time it is set using setConfiguration. Requires Configurated interface too.

Global Function Description
is_enum(mixed $enum): bool Checks if the provided value is an instance of an enum.
unique_meta_hashing_number(string $string, ?int $digits = null): string Generates a unique hash number based on the input string and optional digit limit. Not for security purposes, merely for general meta information tagging.

Package Development

To integrate this package into the development of another package, ensure you load it first within your TestCase file:

class TestCase extends Orchestra
{
    // ...
    public function ignorePackageDiscoveriesFrom()
    {
        return [
            'vpremiss/arabicable', // the other package
            'vpremiss/crafty',
        ];
    }
    
    protected function getPackageProviders($_)
    {
        return [
            \VPremiss\Crafty\CraftyServiceProvider::class,
            \VPremiss\Arabicable\ArabicableServiceProvider::class, // the other package
        ];
    }
    // ...
}

Changelogs

You can check out the package's changelogs online via WTD.

Progress

You can also checkout the project's roadmap among others in the organization's dedicated section for projects.

Support

Support ongoing package maintenance as well as the development of other projects through sponsorship or one-time donations if you prefer.

And may Allah accept your strive; aameen.

License

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

Credits


والحمد لله رب العالمين

crafty's People

Contributors

dependabot[bot] avatar goodm4ven avatar

Stargazers

 avatar

crafty's Issues

Sophisticated arrays and associative arrays validator for both keys and values

I noticed that we're often doing many chains of validations for arrays and their values, and even more when it's a associative array and where keys are now crucial; let alone indenting (recursion) of that. Therefore, I think it would be extremely valuable to create a custom Laravel Validation Rule to help with this.

And then apply the rule everywhere in other packages and projects.

Integrate Arabicable's seeder management logic to CraftyPackage

I'm working currently on cleaning the mess in Arabicable's default installation command that's provided by Spatie's package tools package by moving it to a custom command.

Dealing with seeding is a mess - ensuring that it works in all environments, so I'm working a managing logic of sort. And I need you to integrate it please.

Keep your eyes peeled, over! @Haaabeeel

Standardize configuration to work anywhere!

We have a problem!

Currently, relying on configurations internally cause not only issues with testing environments (where the app structure is like Orchestra's or something), but also we also face abstraction issue where we do validations right after every call for config() to ensure working with a sane value!

The solution I'm working on is to implement configuration defaults and validations on the package service provider (any other package's really, since we're a helper package, yet including ourselves too), and then globalizing a validated_config() helper function to do exactly that.

What do you think? @GoodM4ven

Way better documentation for Configurated utility

This feature became very helpful and essential for Laravel package development; explain this!

We need better documentation for CraftyPackage methods that are related to handling configruations...

[Bug]: Unresolvable binding exception for service providers!

What happened?

What now!? lol

How to reproduce the bug

Pretty much in any other package that has validated_config() used and therefore trying to app() out of the container!

Package Version

2.0.0

PHP Version

8.2

Laravel Version

11

Which operating systems does with happen on?

No response

Notes

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.