Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon\Loader removes leading charakter from subnamespace in getCheckedPath

Hallo, i got an

"PHP Fatal error:  Uncaught Error: Class 'fhac\idm\sva2idm\Config\Config' not found in /opt/sva2idm/app/cli.php:79"

while using Phalcon\Loader. The reason is that the searchpath used by the Loader removes the leading character from the path.

Phpinfo

phalcon

Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 3.1.2
Build Date => Apr  6 2017 14:16:21
Powered by Zephir => Version 0.9.7-1fae5e50ac

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On
phalcon.orm.events => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.virtual_foreign_keys => On => On

Composer PSR4 Autoloader

// autoload_psr4.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
'fhac\\idm\\sva2idm\\' => array($baseDir . '/app'),
'XdgBaseDir\\' => array($vendorDir . '/dnoegel/php-xdg-base-dir/src'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Component\\VarDumper\\' => array($vendorDir . '/symfony/var-dumper'),
'Symfony\\Component\\Debug\\' => array($vendorDir . '/symfony/debug'),
'Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'),
'Psy\\' => array($vendorDir . '/psy/psysh/src/Psy'),
'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
'PhpParser\\' => array($vendorDir . '/nikic/php-parser/lib/PhpParser'),
'Phalcon\\' => array($vendorDir . '/phalcon/devtools/scripts/Phalcon'),
);

Loader

$loader = new Loader();
$loader->registerNamespaces(require __DIR__ . '/../vendor/composer/autoload_psr4.php');

$eventsManager = new EventsManager();
$eventsManager->attach("loader:afterCheckClass", function (Event $event, Loader $loader)
{
echo print_r($loader->getNamespaces());
echo $loader->getCheckedPath();
echo "\n";
}
);
$loader->setEventsManager($eventsManager);

$loader->register();

Calling:

use fhac\idm\sva2idm\Config\Config;
$config = new Config();

Output:

Array
(
[fhac\idm\sva2idm\] => Array
(
[0] => /opt/sva2idm/app
)
.
.
.
)
CheckedPath: /opt/sva2idm/app/onfig/Config.php

Now the leading C of Config is missing: /opt/sva2idm/app/onfig/Config.php.



2.9k
edited May '17

Hi

You use the variable $baseDir to locate "Config/Config" ? because you have notdeclared a namespace for fhac\idm\sva2idm\Config can you check this variable ? if the last character is "\" it removes the first character from the next string

else in this doucmentation there are no "\\" at the end of namespaces



119
Accepted
answer

Thaks for your answer, I have removed the "\" manualy from the composer namespace definition and it works. So we have to parse these files to use it whit the Pahlcon\Loader.

Hi

You use the variable $baseDir to locate "Config/Config" ? because you have notdeclared a namespace for fhac\idm\sva2idm\Config can you check this variable ? if the last character is "\" it removes the first character from the next string

else in this doucmentation there are no "\\" at the end of namespaces