Welcome Guest, Not a member yet? Register   Sign In
Helper_array to class
#1

First of all, i ask the team for feedback.
I want to move the function code into a separate class/classes and place them in the \CodeIgniter\Features namespace. The helper itself will use the class methods.

Example
PHP Code:
if (! function_exists('dot_array_search')) {
    /**
    * Searches an array through dot syntax. Supports
    * wildcard searches, like foo.*.bar
    *
    * @return mixed
    */
    function dot_array_search(string $index, array $array)
    {
        return \CodeIgniter\Features\Array\DotArr::search($index$array)
    }

This will make it possible to use the functions of working with arrays in other classes directly, without unnecessary loading of the helper.
It will also be possible to hide internal functions that should not be called directly. For example as _array_search_dot.

While i plan to create two classes:
  1. \CodeIgniter\Features\Array\DotArr::class
  2. \CodeIgniter\Features\Array\Arr::class
Reply
#2

Why "Features" namespace?
I don't understand the meaning.

Personally I don't like global functions, so I agree with moving the function code into classes.
Reply
#3

I wanted to separate the core of the framework from the elements that extend the functionality. In order not to put everything in one directory.
How about the "Support" namespace?
Reply
#4

I could go either way with this one.

I don't feel that converting from plain functions to a class with static functions actually gains anything, except maybe some syntactical sugar, and not having to explicitly load the helper, which, true is a minor benefit. There isn't a performance benefit as I believe using static functions it comes very close speed wise, depending on the speed of the class autoloader vs the file locator to load the helper. And I'm not too concerned with polluting the global namespace on this since a) PHP is a plain function language at it's core and b) the framework encourages OOP behavior so I don't see clashing with user apps too frequent. I do think there's a tiny amount of added mental overhead since you have to remember to include the full namespace, so it basically becomes a wash in my book.

I do think there are some very minor gains if we make this change, but mostly it becomes a preference. I'm willing to go with whatever the majority opinion on this is.

However - if we decide to go this route we need to convert all helpers to classes for consistency sake. And for at least 1 major release the existing helper functions should be marked as deprecated.

In this case, the classes could stay within the Helpers directories they currently live in, alongside the existing procedural files until they're removed.
Reply
#5

(01-01-2022, 12:27 AM)iRedds Wrote: First of all, i ask the team for feedback.
I want to move the function code into a separate class/classes and place them in the \CodeIgniter\Features namespace. The helper itself will use the class methods.

Example
PHP Code:
if (! function_exists('dot_array_search')) {
    /**
    * Searches an array through dot syntax. Supports
    * wildcard searches, like foo.*.bar
    *
    * @return mixed
    */
    function dot_array_search(string $index, array $array)
    {
        return \CodeIgniter\Features\Array\DotArr::search($index$array)
    }

This will make it possible to use the functions of working with arrays in other classes directly, without unnecessary loading of the helper.
It will also be possible to hide internal functions that should not be called directly. For example as _array_search_dot.

While i plan to create two classes:
  1. \CodeIgniter\Features\Array\DotArr::class
  2. \CodeIgniter\Features\Array\Arr::class






Why are you creating multiple array class files while not make it single file just as laravel did for simplicity
Reply
#6

@Chivinsdev
I was thinking about working separately with just arrays and dot arrays.
I could be wrong.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB