autoload

How to I use Composer to autoload classes from outside the vendor?

岁酱吖の 提交于 2019-11-27 04:25:14
I use psr-4 autoloader from composer: "autoload": { "psr-4": { "DG\\Munchkin\\": "src/DG/Munch/" } } This loads classes from /var/www/html/xxx/vendor/yyy/src/DG/Munch But how can I load classes from /var/www/html/xxx/ ? I wrote my own autoloader, but when I require vendor/autoload.php (composer autoload) and my autoloader, it won't work until I create instance of a class in my own autoloader. The src directory would be in your project root. Its on the same level as vendor directory is. If you define "autoload": { "psr-4": { "DG\\Munchkin\\": "src/DG/Munch/" } } this will not load classes from

Autoloading classes in PHPUnit using Composer and autoload.php

。_饼干妹妹 提交于 2019-11-27 03:06:21
I have just installed PHPUnit version 3.7.19 by Sebastian Bergmann via Composer and have written a class I would like to unit test. I would like to have all my classes autoloaded into each unit test without having to use include or require at the top of my test but this is proving to be difficult! This is what my directory structure looks like (a trailing / slash indicates a directory, not a file): composer.json composer.lock composer.phar lib/ returning.php tests/ returningTest.php vendor/ bin/ phpunit composer/ phpunit/ symfony/ autoload.php My composer.json file includes the following:

Auto-load a module on python startup

霸气de小男生 提交于 2019-11-27 02:49:51
问题 I want IPython or the Python interpreter to auto-load a module when I start them. Is it possible? For example when I start IPython: $ ipython ... >>> from __future__ import division >>> from mymodule import * In [1]: Something like SymPy's live shell found in the tutorial pages. 回答1: Check the file ~/.ipython/ipythonrc - you can list all modules you want to load at the startup. 回答2: Have a .pythonstartup in your home directory and load modules there and point PYTHONSTARTUP env to that file.

Composer/PSR - How to autoload functions?

て烟熏妆下的殇ゞ 提交于 2019-11-27 02:29:43
问题 How can I autoload helper functions (outside of any class)? Can I specify in composer.json some kind of bootstrap file that should be loaded first? 回答1: You can autoload specific files by editing your composer.json file like this: "autoload": { "files": ["src/helpers.php"] } (thanks Kint) 回答2: After some tests, I have came to the conclusions that adding a namespace to a file that contains functions, and setting up composer to autoload this file seems to not load this function across all the

PHP adding custom namespace using autoloader from composer

旧时模样 提交于 2019-11-27 01:34:37
问题 Here is my folder structure: Classes - CronJobs - Weather - WeatherSite.php I want to load WeatherSite class from my script. Im using composer with autoload: $loader = include(LIBRARY .'autoload.php'); $loader->add('Classes\Weather',CLASSES .'cronjobs/weather'); $weather = new Classes\Weather\WeatherSite(); Im assuming the above code is adding the namespace and the path that namespace resolves to. But when the page loads I always get this error: Fatal error: Class 'Classes\Weather\WeatherSite

Using PHP namespaces in a Zend Framework (v1) application

本小妞迷上赌 提交于 2019-11-27 01:23:22
问题 Is it possible in the current stable version of the Zend Framework (1.11), to work with application classes using PHP namespaces? Application\Form\Abc instead of Application_Form_Abc Application\Model\Xyz instead of Application_Model_Xyz etc. Starting from v1.10, ZF supports autoloading namespaces, and it's working fine when including namespaced libraries, but I was unsuccessful when trying to do the same job with application classes. 回答1: Actually there is a simple workaround suggested by

Rails 5: Load lib files in production

你说的曾经没有我的故事 提交于 2019-11-26 23:34:47
I've upgraded one of my apps from Rails 4.2.6 to Rails 5.0.0. The Upgrade Guide says, that the Autoload feature is now disabled in production by default. Now I always get an error on my production server since I load all lib files with autoload in the application.rb file. module MyApp class Application < Rails::Application config.autoload_paths += %W( lib/ ) end end For now, I've set the config.enable_dependency_loading to true but I wonder if there is a better solution to this. There must be a reason that Autoloading is disabled in production by default. My list of changes after moving to

Autoload classes from different folders

杀马特。学长 韩版系。学妹 提交于 2019-11-26 23:31:51
This is how I autoload all the classes in my controllers folder, # auto load controller classes function __autoload($class_name) { $filename = 'class_'.strtolower($class_name).'.php'; $file = AP_SITE.'controllers/'.$filename; if (file_exists($file) == false) { return false; } include ($file); } But I have classes in models folder as well and I want to autoload them too - what should I do? Should I duplicate the autoload above and just change the path to models/ (but isn't this repetitive??)? Thanks. EDIT: these are my classes file names in the controller folder: class_controller_base.php class

Loading view outside view folder with CodeIgniter

醉酒当歌 提交于 2019-11-26 23:12:13
问题 I have the need to load a view from outside the scope of: $this->load->view(); which appears to work from base/application/views directory. How can I access a view from outside the /application/ directory ? I assume i will have to extend the CI_Loader class would this be the best way forward ? I have also found the array which holds the view_paths: // base/system/core/Loader.php // CI_Loader /** * List of paths to load views from * * @var array * @access protected */ protected $_ci_view_paths

php spl_autoload_register vs __autoload?

时光毁灭记忆、已成空白 提交于 2019-11-26 19:43:18
问题 hello is there any diffrence useing this excepts that we can use our own name auto load? is there any performance difference? how do they internally work? between function __autoload_libraries($class){ include_once 'lib.'.$class.'.php'; } spl_autoload_register('__autoload_libraries'); vs function __autoload($class){ include_once 'lib.'.$class.'.php'; } 回答1: __autoload is generally considered obsolete. It only allows for a single autoloader. Generally you should only use __autoload if you're