src/classes/App.php
private function pushControllersInDefinition($alias_namespace, $controllers_directory, &$default_definitions)
    {
        $controller_files = get_files($controllers_directory);
        if (!empty($controller_files))
        {
            $controllers = array_map(function($controller) use($controllers_directory) {
                $new_controller = str_replace("{$controllers_directory}/", "", $controller);
                return basename(str_replace("/", "\\", $new_controller), ".php");
            }, $controller_files);

            $errors = [];

            foreach ($controllers as $controller) {
                if ($alias_namespace === "\\")
                {
                    $controller_definition = $controller;
                    $controller_definition_value = get_app_namespace() . "Controllers\\{$controller}";
                }
                else
                {
                    $module_name = str_replace("App\\", "", $alias_namespace);

                    $controller_sub_namespace = str_replace(app_path() . "/{$module_name}/Controllers", "", $controllers_directory);
                    $controller_sub_namespace = str_replace("/", "\\", $controller_sub_namespace);

                    $controller_definition = "{$alias_namespace}{$controller}";
                    $controller_definition_value = "{$alias_namespace}Controllers\\{$controller}";
                }

                if (!array_key_exists("{$controller_definition}", $default_definitions))
                {
                    $default_definitions["{$controller_definition}"] = function(ContainerInterface $c) use ($controller_definition_value)
                    {
                        return new $controller_definition_value($c);
                    };
                }
                else
                {
                    $errors[] = "{$controller} is already exist inside of definitions.";
                }
            }

            if (!empty($errors))
            {
                exit("Error: Please fix the ff. before run the application: <li>" . implode("</li><li>", $errors));
            }
        }
        else
        {
            exit("Error: No controller found in {$controllers_directory} path.");
        }
    }
private function pushControllersInDefinition($alias_namespace, $controllers_directory, &$default_definitions)
    {
        $controller_files = get_files($controllers_directory);
        if (!empty($controller_files))
        {
            $controllers = array_map(function($controller) use($controllers_directory) {
                $new_controller = str_replace("{$controllers_directory}/", "", $controller);
                return basename(str_replace("/", "\\", $new_controller), ".php");
            }, $controller_files);

            $errors = [];

            foreach ($controllers as $controller) {
                if ($alias_namespace === "\\")
                {
                    $controller_definition = $controller;
                    $controller_definition_value = get_app_namespace() . "Controllers\\{$controller}";
                }
                else
                {
                    $module_name = str_replace("App\\", "", $alias_namespace);

                    $controller_sub_namespace = str_replace(app_path() . "/{$module_name}/Controllers", "", $controllers_directory);
                    $controller_sub_namespace = str_replace("/", "\\", $controller_sub_namespace);

                    $controller_definition = "{$alias_namespace}{$controller}";
                    $controller_definition_value = "{$alias_namespace}Controllers\\{$controller}";
                }

                if (!array_key_exists("{$controller_definition}", $default_definitions))
                {
                    $default_definitions["{$controller_definition}"] = function(ContainerInterface $c) use ($controller_definition_value)
                    {
                        return new $controller_definition_value($c);
                    };
                }
                else
                {
                    $errors[] = "{$controller} is already exist inside of definitions.";
                }
            }

            if (!empty($errors))
            {
                exit("Error: Please fix the ff. before run the application: <li>" . implode("</li><li>", $errors));
            }
        }
        else
        {
            exit("Error: No controller found in {$controllers_directory} path.");
        }
    }
private function pushControllersInDefinition ( $ alias_namespace , $ controllers_directory , & $ default_definitions ) { $ controller_files = get_files ( $ controllers_directory ) ; if ( ! empty ( $ controller_files ) ) { $ controllers = array_map ( function ( $ controller ) use ( $ controllers_directory ) { $ new_controller = str_replace ( "{$controllers_directory}/" , "" , $ controller ) ; return basename ( str_replace ( "/" , "\\" , $ new_controller ) , ".php" ) ; } , $ controller_files ) ; $ errors = [ ] ; foreach ( $ controllers as $ controller ) { if ( $ alias_namespace === "\\" ) { $ controller_definition = $ controller ; $ controller_definition_value = get_app_namespace ( ) . "Controllers\\{$controller}" ; } else { $ module_name = str_replace ( "App\\" , "" , $ alias_namespace ) ; $ controller_sub_namespace = str_replace ( app_path ( ) . "/{$module_name}/Controllers" , "" , $ controllers_directory ) ; $ controller_sub_namespace = str_replace ( "/" , "\\" , $ controller_sub_namespace ) ; $ controller_definition = "{$alias_namespace}{$controller}" ; $ controller_definition_value = "{$alias_namespace}Controllers\\{$controller}" ; } if ( ! array_key_exists ( "{$controller_definition}" , $ default_definitions ) ) { $ default_definitions [ "{$controller_definition}" ] = function ( ContainerInterface $ c ) use ( $ controller_definition_value ) { return new $ controller_definition_value ( $ c ) ; } ; } else { $ errors [ ] = "{$controller} is already exist inside of definitions." ; } } if ( ! empty ( $ errors ) ) { exit ( "Error: Please fix the ff. before run the application: <li>" . implode ( "</li><li>" , $ errors ) ) ; } } else { exit ( "Error: No controller found in {$controllers_directory} path." ) ; } }
Push controllers in default definition

@param  string $alias_namespace
@param  string $controllers_directory
@param  array &$default_definitions
@return void
Push controllers in default definition