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 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制