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 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真