dongwen1909 2017-09-04 08:38 采纳率: 0%
浏览 111
已采纳

如何为Symfony4项目提供Kernel的命名空间命名空间

I'm testing Symfony4 new directory structure with Coception.

Codeception is installed and configured. Because of the end of bundle strategy, I known that an error will occured and here is the error:

PHP Fatal error: Uncaught Error: Class 'Kernel' not found in ...\my_project\vendor\codeception\codeception\src\Codeception\Module\Symfony.php:146

Codeception don't find Kernel class, because of its new namespace which is App and not an empty namespace.

Kernel is now in the src directory and declared in the App namespace.

The new Kernel declaration

<kbd>src/Kernel.php</kbd>

namespace App; // <-- the namespace

[...]

class Kernel extends BaseKernel[...]

Previously, Kernel was named AppKernel and didn't have namespace:

The old Kernel declaration

<kbd>app/AppKernel.php</kbd>

<?php

//no namespace

[...]

class AppKernel extends Kernel

I edited the 265th line of the Symfony.php file to change this line which is returning Kernel:

$class = $file->getBasename('.php');

by this line to return App\Kernel:

$class = 'App\\'.$file->getBasename('.php');

This modification forces the new namespace of the new structure.

My functional tests run perfectly, but I want to avoid modification in vendor file.

How can I force the App namespace without this hack? It seems there is no parameter to do it, but can I encapsulate codeception in the app namespace or find a hack to put it in my files, not in the vendor file?

  • 写回答

2条回答 默认 最新

  • douhai9043 2017-09-04 17:23
    关注

    You could create an alias for the Kernel class:

       class_alias('App\Kernel', 'Kernel');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下