CodeIgniter Forums
Why spark adding ResponseInterface to controller? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Why spark adding ResponseInterface to controller? (/showthread.php?tid=90166)



Why spark adding ResponseInterface to controller? - Muzikant - 02-19-2024

Why spark adding ResponseInterface to controller as it is not directly used in the scope?

php spark make:controller Test
PHP Code:
<?php

namespace App\Controllers;

use 
App\Controllers\BaseController;
use 
CodeIgniter\HTTP\ResponseInterface// unused in the scope

class Test extends BaseController
{
    public function index()
    {
        //
    }




RE: Why spark adding ResponseInterface to controller? - kenjis - 02-19-2024

Run
Code:
php spark make:controller --restful



RE: Why spark adding ResponseInterface to controller? - Muzikant - 02-20-2024

Thank you, I appreciate it. But it is not an answer on my question. What is the reason behind adding it by default?


RE: Why spark adding ResponseInterface to controller? - kenjis - 02-20-2024

It just means that the output is not optimized for each controller.

Normal controllers do not need ResponseInterace, but a dev may use it.
Besides, unused use statements are automatically removed by php-cs-fixer,
so devs don't need to worry about them.


RE: Why spark adding ResponseInterface to controller? - luckmoshy - 02-20-2024

@Muzikant You don't have to be a fan of other developers and other developers who are interested in using ResponseInterface also won't use likewise
so bear in mind that the framework lesson basement should have basic tools to help facilitate some tasks to a developer so that you don't need to worry otherwise you may remove either by manual or php-cs-fixer as @kenjis says


RE: Why spark adding ResponseInterface to controller? - Muzikant - 02-21-2024

Kenjis, thank you. I did not know about PHP-CS-Fixer. I am still learning. I will look at it. So it was added because it can be used? Why this one and not other ones?


RE: Why spark adding ResponseInterface to controller? - kenjis - 02-21-2024

"use CodeIgniter\HTTP\ResponseInterface" was added because REST controller uses it.

Also, the return types of controller action methods are only string or ResponseInterface.


RE: Why spark adding ResponseInterface to controller? - kenjis - 02-21-2024

CodeIgniter DevKit provides useful tools for development.
https://github.com/codeigniter4/devkit


RE: Why spark adding ResponseInterface to controller? - Muzikant - 02-22-2024

Now I have a little insight into it. I was wondering why it was added. I will look at DevKit too. Thank you and good luck.


RE: Why spark adding ResponseInterface to controller? - jenniferrnovak - 08-18-2024

(02-21-2024, 06:30 PM)kenjis Wrote: CodeIgniter DevKit provides useful tools for development.
https://github.com/codeigniter4/devkit

I'm new here, and this will be useful for me, I'm grateful to you for sharing this.