I have my own functions stored in the helpers.php
file in the helpers
folder relative to the composer.json
file.
<?php
function config (string $params){}
function redirect() {}
In the file composer.json
this file is included in autoload
"autoload": {
"psr-4": {
"App\\" : "./app"
},
"files": [
"helpers/helpers.php"
],
"scripts": {
"delete-all-tables": "App\\Migrations\\DeleteTable::deleteAllTables",
}
}
I used composer-dump
after connecting helpers
.
I am using config ()
at this location:
<?php
namespace App\Migrations;
use App\Components\Migration;
class DeleteTable extends Migration
{
public static function deleteAllTables()
{
$param = config('db.dbname');
$instance = new self();
$instance->con->query("DROP DATABASE " . $param . "; CREATE DATABASE " . $param . "; USE " . $param . ";");
}
}
When using my functions in the Migration
class not through the composer, everything works correctly, but when calling scripts
commands through Terminal
, the config
function is not executed. Then the error appears:
Fatal error: Uncaught Error: Call to undefined function App\Migrations\config() in D:\OSPanel\domains\myshop\app\Migrations\DeleteTable.php:17
Stack trace:
#0 phar://C:/composer/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(324): App\Migrations\DeleteTable::deleteAllTables(Object(Composer\Script\Event))
#1 phar://C:/composer/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(218): Composer\EventDispatcher\EventDispatcher->executeEventPhpScript('App\\Migrations\\...', 'dele
teAllTables', Object(Composer\Script\Event))
#2 phar://C:/composer/composer.phar/src/Composer/EventDispatcher/EventDispatcher.php(101): Composer\EventDispatcher\EventDispatcher->doDispatch(Object(Composer\Script\Event))
#3 phar://C:/composer/composer.phar/src/Composer/Command/ScriptAliasCommand.php(64): Composer\EventDispatcher\EventDispatcher->dispatchScript('delete-all-tabl...', true, Array)
#4 phar://C:/composer/composer.phar/vendor/symfony/console/Command/Command.php(245): Composer\Command\ScriptAliasCommand->execute(Obje in D:\OSPanel\domains\myshop\app\Migrations\Delet
eTable.php on line 11
Can you please tell me what am I doing wrong?
Are there any options for solving the problem without using helpers in the class? Thank you very much for your help!