GithubHelp home page GithubHelp logo

crafty's Issues

[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

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

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...

A helper method for deriving the class manually in a package

// TODO abstract
$namespace = $serviceProvider->getPackageNamespace();
$className = str($path)->after('seeders/')->before('.php')->value();
$className = "{$namespace}\\Database\\Seeders\\$className";

And maybe adding the requiring logic too? on CraftyPackage facade perhaps

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

Skipping chunked insertions for existing records

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\QueryException;

public function chunkedDatabaseInsertion(string $tableName, array $dataArrays, ?Closure $callback = null): void
{
    $callback ??= fn ($dataArray) => $dataArray;
    $chunksCount = CraftyPackage::getConfiguration('crafty.databasing_chunks_count');
    $defaultProperties = CraftyPackage::getConfiguration('crafty.insertion_default_properties');
    $columnNames = Schema::getColumnListing($tableName);

    DB::beginTransaction();
    try {
        $chunks = array_chunk($dataArrays, $chunksCount);

        foreach ($chunks as $chunk) {
            // Retrieve existing records to skip duplicates
            $existingRecords = DB::table($tableName)
                ->whereIn('email', array_column($chunk, 'email'))
                ->pluck('email')
                ->toArray();

            $data = array_map(function ($dataArray) use ($tableName, $callback, $columnNames, $defaultProperties, $existingRecords) {
                $callbackData = $callback($dataArray);

                if (!is_array($callbackData)) {
                    throw new CraftyDatabaseException(
                        'The callback must return an array for each data arrays item.'
                    );
                }

                // Skip duplicates
                if (in_array($callbackData['email'], $existingRecords)) {
                    return null;
                }

                $validatedData = array_filter($callbackData, function ($key) use ($columnNames) {
                    return in_array($key, $columnNames);
                }, ARRAY_FILTER_USE_KEY);

                if (empty($validatedData)) {
                    throw new CraftyDatabaseException(
                        "The callback array item does not return valid keys for the '$tableName' table."
                    );
                }

                return array_merge(
                    $validatedData,
                    $defaultProperties,
                );
            }, $chunk);

            // Filter out null values which are duplicates
            $data = array_filter($data);

            // Insert data if there are valid records
            if (!empty($data)) {
                DB::table($tableName)->insert($data);
            }
        }

        DB::commit();
    } catch (Exception $e) {
        DB::rollBack();

        throw $e;
    }
}

Abstract all the private laravel-package-tools stuff somehow, like getNamespace()

Currently, there is a lot of helper methods that are private when working with Spatie's Laravel package tools, such as getting the package name using $this->package->shortName(); where package itself is protected anyway... Having public methods that internally call these on the service provi- oh wait! We actually have those in HasInstallationCommand!

So all we need is a new trait that contains them and that is pulled by that other trait anyway. -oh and adding its methods to the installable interface for clarity..

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.