phpphalconphinx

Phinx migration error, "Could not find class" but looking in the correct file?


I'm trying to run database migrations using the phinx library for a Phalcon framework example project called 'Vokuro' and I'm getting this error. The file directory is correct so I'm clueless as to why this is happening.

Cmd:

C:\xampp\htdocs\vokuro\vendor\bin>phinx.bat status -e development
Phinx by CakePHP - https://phinx.org.

using config file .\phinx.json
using config parser json
using migration paths
 - C:\xampp\htdocs\vokuro\db\migrations
using seed paths
 - C:\xampp\htdocs\vokuro\db\seeds
using environment development
ordering by creation time

In Manager.php line 742:

  Could not find class "CreateEmailConfirmations" in file "C:\xampp\htdocs\vokuro\vendor\bin\..\..\db\migrations\20190825181051_create_email_confirmations.php"

C:\xampp\htdocs\vokuro\db\migrations\20190825181051_create_email_confirmations.php:

<?php
declare(strict_types=1);

namespace Vokuro\Migrations;

use Phinx\Migration\AbstractMigration;

final class CreateEmailConfirmations extends AbstractMigration
{
    public function change(): void
    {
        $table = $this->table('email_confirmations');
        if ($table->exists()) {
            return;
        }

        $table->addColumn('usersId', 'integer')
            ->addColumn('code', 'char', ['limit' => 32])
            ->addColumn('createdAt', 'integer')
            ->addColumn('modifiedAt', 'integer', ['null' => true])
            ->addColumn('confirmed', 'char', ['limit' => 1, 'default' => 'N'])
            ->create();
    }
}

C:\xampp\htdocs\vokuro\vendor\robmorgan\phinx\src\Phinx\Migration\Manager.php:

// convert the filename to a class name
$class = ($namespace === null ? '' : $namespace . '\\') . Util::mapFileNameToClassName(basename($filePath));

if (isset($fileNames[$class])) {
    throw new InvalidArgumentException(sprintf(
        'Migration "%s" has the same name as "%s"',
        basename($filePath),
        $fileNames[$class]
    ));
}

$fileNames[$class] = basename($filePath);

if ($this->getOutput()->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG) {
    $this->getOutput()->writeln("Loading class <info>$class</info> from <info>$filePath</info>.");
}

// load the migration file
$orig_display_errors_setting = ini_get('display_errors');
ini_set('display_errors', 'On');
/** @noinspection PhpIncludeInspection */
require_once $filePath;
ini_set('display_errors', $orig_display_errors_setting);
if (!class_exists($class)) {
    throw new InvalidArgumentException(sprintf(
        'Could not find class "%s" in file "%s"',
        $class,
        $filePath
    ));
}

Solution

  • Because you are using your own config file:

    using config file .\phinx.json
    

    Instead of phinx.php. This file is located on the root of project. https://github.com/phalcon/vokuro/blob/master/phinx.php

    Inside this file is paths key, which specifies namespaces for migrations and seeds.