autoload

Name Clash with Top Level constant when autoloading with Rails

北城余情 提交于 2019-12-24 00:48:53
问题 I'm having a class Dog in app/models/dog.rb and another class Services::My::Deeply::Nested::Dog in app/services/my/deeply/nested/dog.rb . Now in Services::My (app/services/my.rb), I have a reference to one of the following (no need to distinguish, since the behaviour is exaclty the same in all situations): Deeply::Nested::Dog Services::My::Deeply::Nested::Dog ::Services::My::Deeply::Nested::Dog No matter which of the above I choose, I always get the following error message: services/my.rb:

Autoloading classes when not in same directory as zend library

人盡茶涼 提交于 2019-12-24 00:27:25
问题 I've decided that rather than have a copy of the Zend Framework in each application's directory, I'd like to keep it on one location on the server, with the one copy used by all my websites. However, I'd like my app's custom classes to still be within the application folder. So a folder structure a bit like this: webroot |...library | |......Zend | |...app1 | |.....Library | |.......App1 | |...app2 |.....Library |.......App2 How can I get Zend Loader to automatically find the classes in App1

LoadError Unable to autoload constant

十年热恋 提交于 2019-12-23 16:49:44
问题 It seems that autoloader is loading up lib/tools/address and not my model Address throws the following error LoadError: Unable to autoload constant Address, expected /lib/tools/address.rb to define it Can someone tell me what I'm doing wrong. I thought that Address would point to constant models/address.rb and Tools::Address to lib/tools/address.rb app/models/address.rb class Address blah end lib/tools/address.rb module Tools class Address blah blah end end 回答1: In my experience it can be

Does PHP's use statement cause extra work when loading classes?

旧巷老猫 提交于 2019-12-23 13:57:07
问题 Code Sample 1 use Outline\Drawing; $var = new Drawing(); Code Sample 2 $var = new Outline\Drawing(); Question: Does PHP make hardware work harder (look up more files or do more processing) if I use code in sample 1? I am sure something gets done, even if it is at the level of some code that figures out which use line gets matched up with which class. I want to find out exactly what is happenning. In short: What does PHP do when working out the connection between the use of the use statement

Symfony2 File Found Class Was Not In It

怎甘沉沦 提交于 2019-12-23 09:57:48
问题 This is my first question, besides I'm not english-native speaker, so sorry in advance for newbie mistakes... I'm starting with Symfony2, and I've been facing an autoload problem for a couple of days, i'm getting crazy.. I'm just trying to use a PHP class inside my DefaultController of my AppBundle. I've read the way of doing this is by creating a service in my config.yml and giving a namespace to that class that matches. Symfony tells me that it does found the file but the class is not in it

How can I preload concerns in a rails initializer using Rails 6/Zeitwerk?

我与影子孤独终老i 提交于 2019-12-23 09:40:06
问题 I'm working with an initializer that does some monkey patching on app start by including some app concerns into a third party lib. Basically: # config/initializers/my_initializer.rb class SomeExternalLib include MyConcern1 include MyConcern2 end This works fine in Rails 5.2.3, but I got the following deprecation message when upgrading to Rails 6: DEPRECATION WARNING: Initialization autoloaded the constants MyConcern1, and MyConcern2. Being able to do this is deprecated. Autoloading during

Codeigniter 3 autoload controller

穿精又带淫゛_ 提交于 2019-12-23 08:54:04
问题 I'm using REST Server in codeigniter, and the way to use is that then in my app in all my controllers I must write this line on start: require APPPATH . '/libraries/REST_Controller.php'; Does anyone know how to autoload this REST_Controller and to avoid this line in all my controllers? I don't want to use require. Thank in advance 回答1: You can achieve this through Codeigniter 's autoload configuration. Edit your project's autoload.php which is located in directory YourProject/application

Composer autoloader not loading GuzzleHttp\ClientInterface

心已入冬 提交于 2019-12-23 07:49:52
问题 I'm trying to use Guzzle, but I'm getting the following fatal error: Fatal error: Class 'GuzzleHttp\ClientInterface' not found in /var/www/myapp/vendor/guzzlehttp/guzzle/src/functions.php on line 13 I'm autoloading with composer autoloader: require 'vendor/autoload.php'; use Guzzle\Http\Client; $client = new Client(); $requests = Array( $client->createRequest('GET', 'ams1.myapp.com:8080/api/ffmpeg_make_snapshots.php'), $client->createRequest('GET', 'ams2.myapp.com:8080/api/ffmpeg_make

PHP 5.3 autoloader

隐身守侯 提交于 2019-12-22 12:48:07
问题 I would like to use the PSR-0 Standard way to autoload classes without requiring to add includes, e.g. how can I replace the code below with the autoloading mechanism: namespace Example; use MyLib\Controller; include_once './library/MyLib/Controller/AbstractController.php'; class MyController extends Controller\AbstractController { [...] So in the example above, it shows that in every controllers I need to include the abstract controller, which is crazy... I have found the PSR-0 code here:

set_error_handler function not calling autoload

会有一股神秘感。 提交于 2019-12-22 08:26:04
问题 I have the set_error_handler() function set to call a function when there is an error. In that function I have my own implementation of the exception class: function acs_error_handler($errno, $errstr, $errfile, $errline) { throw new acs_exception($errstr, $errno); } This gives me the following error: Fatal error: Class 'acs_exception' not found For some reason, this function does not call my autoload function which I have set up using: spl_autoload_register('__autoload'); If I add the line: _