[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

[FuelPHP 1.7] Extend the Autoloader class

PHP

This is Kusakabe from the WEB team.

I was wondering how to extend the Autoloader class in FuelPHP 1.7, so I'm writing this down!

 

What I want to do

Extend the \Fuel\Core\Autoloader class and define it as an Autoloader class

 

How to extend FuelPHP's core classes

http://fuelphp.jp/docs/1.7/general/extending_core.html (FuelPHP 1.7)

As written here.

It's easier if you want to extend the Response class instead of the Autoloader.

class Response extends FuelCoreResponse { }

You can save it as app/classes/response.php and write the correspondence between class name and file path in add_classes of app/bootstrap.php.

Autoloader::add_classes(array( 'Response' => APPPATH.'classes/response.php', ));

However, when I try to extend Autoloader using the same steps, it doesn't work.
Why? Because Autoloader is an exception!

 

Where I was worried

This is what is written at the bottom of the document

Autoloader

The Autoloader class is a special case, you can only extend it once as [ Autoloader] and have it used. After extending it you have to require it manually in the [ app/bootstrap.php] file after the original [ FuelCoreAutoloader] , don 't forget to remove the line that aliases the core class to global.

In other words, this is what it means.

 

  1. Manually require the Autoloader class file that extends FuelCoreAutoloader in app/bootstrap.php
  2. remove the line that aliases the core class to global (???)

 

I understand the first one! Just do it like this.

Create app/classes/autoloader.php and

class Autoloader extends FuelCoreAutoloader { }

At the beginning of app/bootatrap.php

require APPPATH.'classes'.DIRECTORY_SEPARATOR.'autoloader.php';

Describe.

 

I didn't understand the second meaning! I didn't understand, so I ignored it and opened the page.

Cannot redeclare class Autoloader

I've been having trouble with this for a while, but I've solved it.

From the conclusion, around line 50 of public/index.php

class_alias('Fuel\Core\Autoloader', 'Autoloader');

It's ok if you comment this out.

 

What this line means is

"Create an alias from Autoloader in the global namespace to Autoloader in the FuelCore namespace"

is. See http://php.net/manual/function.class-alias.php for class_alias()

Because of this alias,

class Autoloader extends FuelCoreAutoloader { }

In this case, Autoloader was defined twice and inherited itself.

 

 

In summary,

When extending the core class Autoloader

  1. Create app/classes/autoloader.php
    class Autoloader extends FuelCoreAutoloader { }
  2. At the beginning of app/bootstrap.php
    require APPPATH.'classes'.DIRECTORY_SEPARATOR.'autoloader.php';

    describe

  3. public/index.php (around line 50)
    class_alias('Fuel\Core\Autoloader', 'Autoloader');

    comment out

It is OK as long as you keep these three points in check. Looks like things are going well later.

 

If you found this article helpful , please give it a like!
0
Loading...
0 votes, average: 0.00 / 10
1,956
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author