autoload

Autoload in Python

给你一囗甜甜゛ 提交于 2019-11-28 04:34:56
In the past I've used perl's AUTOLOAD facility for implementing lazy loading of symbols into a namespace, and wanted the same functionality in python. Traditionally the closest you appear to be able to get is to use a class and a __getattr__ class to achieve this sort of thing. However I've also tried rummaging around in sys.modules , and come up with this: # mymod.py def greet(greeting="Hello World"): print greeting class autoload(object): def __init__(self, __name__): super(autoload, self).__init__() self.wrapped_name = __name__ self.wrapped = sys.modules[__name__] def __getattr__(self, name

PSR4 auto load without composer

爷,独闯天下 提交于 2019-11-28 01:33:24
问题 I have one package in a project which is autoloaded using composer and composer.json entry is as follows : "autoload": { "psr-4": { "CompanyName\\PackageName\\": "packages/package-folder/src/" } } Now I am copying this over to another project which is not using composer. How can I autoload this same package there ? 回答1: You have to read the composer and load the classes yourself for each namespaces defined into the composer.json . Here is how : function loadPackage($dir) { $composer = json

composer autoloader psr-0 namespaces

拈花ヽ惹草 提交于 2019-11-28 00:00:38
问题 I have create a custom composer package but I am having troubles to set the correct autoload options for it. All my classes are under MyNamespace/Common namespace. So for example for including my ArrayHelper class I do use Mynamespace/Common/Helper/ArrayHelper . This is the relevant part of my composer.json : "autoload": { "psr-0": { "MyNamespace\\": "" } } I have read this: composer.json / autoload Any help? 回答1: You have to navigate the file location of your namespace. "autoload": { "psr-0"

Loading view outside view folder with CodeIgniter

岁酱吖の 提交于 2019-11-27 22:34:32
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 = array(); but the comment above all the declared variables has got me stuck // All these are set

Rails3 not reloading code in lib while in development mode

淺唱寂寞╮ 提交于 2019-11-27 20:12:52
问题 THE SITUATION: I have code in lib/foo/bar.rb with a simple method defined as such: module Foo class Bar def test "FooBar" end end end In my helper, FooBarHelper , I have: require `lib/foo/bar` module FooBarHelper def test_foo_bar fb = Foo::Bar.new fb.test end end In my view, I call this helper method like so: <%= test_foo_bar => In my config/environments/development.rb , I added the directory to my config.autoload_paths : config.autoload_paths += ["#{config.root}/lib/foo"] THE PROBLEM: When I

php spl_autoload_register vs __autoload?

强颜欢笑 提交于 2019-11-27 19:02:46
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'; } __autoload is generally considered obsolete. It only allows for a single autoloader. Generally you should only use __autoload if you're using a version of PHP without support for spl_autload_register . spl_autoload_register allows several

Using Composer's Autoload

霸气de小男生 提交于 2019-11-27 17:07:54
I have been looking around the net with no luck on this issue. I am using composer's autoload with this code in my composer.json : "autoload": { "psr-0": {"AppName": "src/"} } But I need to autoload at a higher level than the vendor folder. Doing something like this does not work: "autoload": { "psr-0": {"AppName": "../src/"} } Does anyone know a fix or how I can do this? Every package should be responsible for autoloading itself, what are you trying to achieve with autoloading classes that are out of the package you define? One workaround if it's for your application itself is to add a

Do PHP opcode cache work with __autoload?

烈酒焚心 提交于 2019-11-27 15:30:49
Sorry if this is basic, I am trying to learn as much as I can about OO in PHP and I am slowly learning how to use it (very limited). So I am wanting to know if __autoload() has any affect on PHP opcode cache's? Pascal MARTIN (Disclaimer : I only know APC) What an opcode cache do is : when a file is included/required, it take the full path to that file check if the opcodes corresponding to that file are already in RAM (in opcode cache) if yes, return those opcode so they are executed if no, load the file and compile it to opcodes ; and store opcodes in cache. The important point, here, is the

Zend Framework: Autoloading a Class Library

心已入冬 提交于 2019-11-27 15:07:25
问题 I've got a class library in defined here .../projectname/library/Me/Myclass.php defined as follows: <?php class Me_Myclass{ } ?> I've got the following bootstrap: <?php /** * Application bootstrap * * @uses Zend_Application_Bootstrap_Bootstrap */ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { /** * Bootstrap autoloader for application resources * * @return Zend_Application_Module_Autoloader */ protected function _initAutoload() { $autoloader = new Zend_Application_Module

Composer classmap autoload does not load new files in folder

天涯浪子 提交于 2019-11-27 14:41:53
问题 The following problem: I have defined a classmap in my composer.json: "autoload": { "classmap": [ "app/controllers", "app/models", "app/helper.php" ] } However, when I create a new file in the "controllers" or "models" folder, it will not load them and I always have to make a composer dump-autoload. Is this the correct behavior? I thought the autoloader from composer monitors the folder for new files then? 回答1: Yes, this is correct behaviour. If you want new classes to be loaded automatically