public static function modelize($key, $value)
    {
        switch (gettype($value)) {
            case 'object':

                $namespaces = ['\Connect\\', '\Connect\Usage\\'];

                /**
                 * if the item is an object search if there are any model that match with it:
                 *
                 *  foreach tracked namespace do:
                 *
                 *  1. fqcn = base namespace + capitalized property name.
                 *
                 *  2. fqcn = base namespace + capitalized + singularized property name.
                 *
                 *  3. if '_' is found in name then
                 *      fqcn = base namespace + split property name by '_', for each section
                 *             capitalize, singularize and merge sections.
                 *
                 *  4. fqcn = base namespace + capitalized + singularized property name with trimmed nums.
                 *
                 *  if any of the user cases from above match, create a single Connect\Model object.
                 */
                foreach ($namespaces as $namespace) {
                    $fqcn = $namespace . ucfirst($key);
                    if (class_exists($fqcn, true)) {
                        return new $fqcn($value);
                    }

                    $fqcn = $namespace . ucfirst(Inflector::singularize($key));
                    if (strpos($key, '_') !== false) {
                        $fqcn = $namespace . implode('', array_map(function ($word) {
                            return ucfirst(Inflector::singularize($word));
                        }, explode('_', $key)));
                    }
                    if (class_exists($fqcn, true)) {
                        return new $fqcn($value);
                    }

                    $fqcn = trim($fqcn, '0123456789');
                    if (class_exists($fqcn, true)) {
                        return new $fqcn($value);
                    }
                }

                return new Model($value);

            case 'array':

                $array = [];

                /**
                 * if the item is an array, call again the modelize method for each item
                 * of the array using the key as seed of the model and  keeping the index
                 * of original array.
                 */
                foreach ($value as $index => $item) {
                    $array[$index] = self::modelize(is_int($index) ? $key : $index, $item);
                }

                return $array;

                break;
            default:

                /**
                 * if the data is an scalar directly assign it. the data type
                 * should be correctly from the source: int as int instead
                 * of string etc...
                 */
                return $value;
        }
    }
public static function modelize($key, $value)
    {
        switch (gettype($value)) {
            case 'object':

                $namespaces = ['\Connect\\', '\Connect\Usage\\'];

                /**
                 * if the item is an object search if there are any model that match with it:
                 *
                 *  foreach tracked namespace do:
                 *
                 *  1. fqcn = base namespace + capitalized property name.
                 *
                 *  2. fqcn = base namespace + capitalized + singularized property name.
                 *
                 *  3. if '_' is found in name then
                 *      fqcn = base namespace + split property name by '_', for each section
                 *             capitalize, singularize and merge sections.
                 *
                 *  4. fqcn = base namespace + capitalized + singularized property name with trimmed nums.
                 *
                 *  if any of the user cases from above match, create a single Connect\Model object.
                 */
                foreach ($namespaces as $namespace) {
                    $fqcn = $namespace . ucfirst($key);
                    if (class_exists($fqcn, true)) {
                        return new $fqcn($value);
                    }

                    $fqcn = $namespace . ucfirst(Inflector::singularize($key));
                    if (strpos($key, '_') !== false) {
                        $fqcn = $namespace . implode('', array_map(function ($word) {
                            return ucfirst(Inflector::singularize($word));
                        }, explode('_', $key)));
                    }
                    if (class_exists($fqcn, true)) {
                        return new $fqcn($value);
                    }

                    $fqcn = trim($fqcn, '0123456789');
                    if (class_exists($fqcn, true)) {
                        return new $fqcn($value);
                    }
                }

                return new Model($value);

            case 'array':

                $array = [];

                /**
                 * if the item is an array, call again the modelize method for each item
                 * of the array using the key as seed of the model and  keeping the index
                 * of original array.
                 */
                foreach ($value as $index => $item) {
                    $array[$index] = self::modelize(is_int($index) ? $key : $index, $item);
                }

                return $array;

                break;
            default:

                /**
                 * if the data is an scalar directly assign it. the data type
                 * should be correctly from the source: int as int instead
                 * of string etc...
                 */
                return $value;
        }
    }
public static function modelize ( $ key , $ value ) { switch ( gettype ( $ value ) ) { case 'object' : $ namespaces = [ '\Connect\\' , '\Connect\Usage\\' ] ; /**
                 * if the item is an object search if there are any model that match with it:
                 *
                 *  foreach tracked namespace do:
                 *
                 *  1. fqcn = base namespace + capitalized property name.
                 *
                 *  2. fqcn = base namespace + capitalized + singularized property name.
                 *
                 *  3. if '_' is found in name then
                 *      fqcn = base namespace + split property name by '_', for each section
                 *             capitalize, singularize and merge sections.
                 *
                 *  4. fqcn = base namespace + capitalized + singularized property name with trimmed nums.
                 *
                 *  if any of the user cases from above match, create a single Connect\Model object.
                 */ foreach ( $ namespaces as $ namespace ) { $ fqcn = $ namespace . ucfirst ( $ key ) ; if ( class_exists ( $ fqcn , true ) ) { return new $ fqcn ( $ value ) ; } $ fqcn = $ namespace . ucfirst ( Inflector :: singularize ( $ key ) ) ; if ( strpos ( $ key , '_' ) !== false ) { $ fqcn = $ namespace . implode ( '' , array_map ( function ( $ word ) { return ucfirst ( Inflector :: singularize ( $ word ) ) ; } , explode ( '_' , $ key ) ) ) ; } if ( class_exists ( $ fqcn , true ) ) { return new $ fqcn ( $ value ) ; } $ fqcn = trim ( $ fqcn , '0123456789' ) ; if ( class_exists ( $ fqcn , true ) ) { return new $ fqcn ( $ value ) ; } } return new Model ( $ value ) ; case 'array' : $ array = [ ] ; /**
                 * if the item is an array, call again the modelize method for each item
                 * of the array using the key as seed of the model and  keeping the index
                 * of original array.
                 */ foreach ( $ value as $ index => $ item ) { $ array [ $ index ] = self :: modelize ( is_int ( $ index ) ? $ key : $ index , $ item ) ; } return $ array ; break ; default : /**
                 * if the data is an scalar directly assign it. the data type
                 * should be correctly from the source: int as int instead
                 * of string etc...
                 */ return $ value ; } }
Modelize the given value into \Connect\Model
@param string $key
@param mixed $value
@return array|Model
Modelize the given value into \ Connect \ Model