autoload

Is autoload thread-safe in Ruby 1.9?

痴心易碎 提交于 2019-12-02 22:00:00
It seems to me that the Ruby community has been freaking out a little about autoload since this famous thread , discouraging its use for thread safety reasons. Does anyone know if this is no longer an issue in Ruby 1.9.1 or 1.9.2? I've seen a bit of talk about wrapping requires in mutexes and such, but the 1.9 changelogs (or at least as much as I've been able to find) don't seem to address this particular question. I'd like to know if I can reasonably start autoloading in 1.9-only libraries without any reasonable grief. Thanks in advance for any insights. I don't know about the general case,

Loading namespaced classes with Symfony 1.4's autoloader?

亡梦爱人 提交于 2019-12-02 21:09:26
How to register namespaces (with PHP 5.3) in the Symfony 1.4 for the autoloader class feature (like the Symfony 2.0 )? You can use Autoloader from Symfony2 in Symfony 1.4 framework. 1. Copy Symfony2 classloaders to vendor directory of your Symfony 1.4 sandbox project: SF_ROOT_DIR/lib/vendor/Symfony2/src/Symfony/Component/ClassLoader/UniversalClassLoader.php SF_ROOT_DIR/lib/vendor/Symfony2/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php 2. Modify your SF_ROOT_DIR/config/ProjectConfiguration.class.php file as follows: require_once dirname(__FILE__) . '/../lib/vendor/symfony/lib

Adding a Custom Form Element to an Adminhtml Form

无人久伴 提交于 2019-12-02 20:51:53
Is there a way to add a custom form element to a Magento Adminhtml form without placing the custom element in the lib/Varian folder? I've tracked down the code that's essentially a Varian_Data_Form_Element_ factory public function addField($elementId, $type, $config, $after=false) { if (isset($this->_types[$type])) { $className = $this->_types[$type]; } else { $className = 'Varien_Data_Form_Element_'.ucfirst(strtolower($type)); } $element = new $className($config); $element->setId($elementId); if ($element->getRequired()) { $element->addClass('required-entry'); } $this->addElement($element,

How to generate Absolute URL from Early/Auto loaded Symfony 3 router

≡放荡痞女 提交于 2019-12-02 19:37:07
问题 I am writing Guards to handle OAuth for my Symfony 3 application. As part of it, in one of my services, I need to generate an absolute URL to send to Twitter as the Callback URL. #services.yml ... app.twitter_client: class: MyApiBundle\Services\TwitterClient arguments: - %twitter_client_id% - %twitter_client_secret% - connect_twitter_check - '@request_stack' - '@router' - '@logger' app.twitter_authenticator: class: MyApiBundle\Security\TwitterAuthenticator arguments: - '@app.twitter_client' -

How to use spl_autoload() as __autoload() goes DEPRECATED

喜夏-厌秋 提交于 2019-12-02 18:39:48
According to http://php.net/manual/en/language.oop5.autoload.php the magic function __autoload() will become DEPRECATED and DELETED (!) in upcoming PHP versions. The official alternative is spl_autoload(). See http://www.php.net/manual/en/function.spl-autoload.php . But the php manual does not explain the proper use of this baby. My question: How to replace this (my automatic class autoloader) function __autoload($class) { include 'classes/' . $class . '.class.php'; } with a version with spl_autoload() ? Problem is: I cannot figure out how to give that function a path (it only accepts

Convert CamelCase to under_score_case in php __autoload()

佐手、 提交于 2019-12-02 17:41:14
PHP manual suggests to autoload classes like function __autoload($class_name){ require_once("some_dir/".$class_name.".php"); } and this approach works fine to load class FooClass saved in the file my_dir/FooClass.php like class FooClass{ //some implementation } Question How can I make it possible to use _autoload() function and access FooClass saved in the file my_dir/foo_class.php ? You could convert the class name like this... function __autoload($class_name){ $name = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $class_name)); require_once("some_dir/".$name.".php"); } This is

Composer autoload file not working

亡梦爱人 提交于 2019-12-02 10:54:55
My Autoload specification are as follows "autoload" : { "psr-4" : { "MyMVC\\" : "app/" }, "classmap": [ "app/Controllers", "app/Helpers" ], "files": ["app/routes.php"] }, The contents of routes.php file are: <?php use MyMVC\Core\Route; $route = new Route; $route->add('/', 'HomeController@index'); $route->add('about', 'AboutController@index'); $route->add('contact', 'ContactController@index'); now in my app/init.php i am trying to use the $route object but its giving me error Notice: Undefined variable: route in /var/www/html/mymvc/app/init.php on line 29 Here is how i am trying to use the

Composer classmap and loading files with non-standard extensions

别说谁变了你拦得住时间么 提交于 2019-12-02 05:40:35
问题 When loading files through the composer classmap functionality is it possible to load PHP files that have non-standard extensions such as myFileName.stub or myFileName.foo ? At present it seems not to be loading them. 回答1: Composer will currently include files with the following extensions: .php .inc .hh The last one is for HHVM stuff. Relevant lines from the class map generator here: https://github.com/composer/composer/blob/master/src/Composer/Autoload/ClassMapGenerator.php#L62 https:/

PHP use class in global namespace

隐身守侯 提交于 2019-12-02 04:16:57
问题 I have a DB wrapper class that uses PDO and in the constructor I create a PDO object. The wrapper class is in our namespace and we are using an autoloader. The issue is that the PDO class cannot be found within our namespace, so I tried using the global namespace as described here. //Class file namespace Company\Common; class DB { private function __construct(){ $this->Handle=new PDO(...); } } With this, I get this (as expected): Warning: require(...\vendors\Company\Common\PDO.class.php):

How to add autoload-function to CodeIgniter?

无人久伴 提交于 2019-12-01 18:04:11
I would like to be able to use OOP and create new objects in my controllers in CodeIgniter. So I need to use an autoload-function: function __autoload( $classname ) { require_once("../records/$classname.php"); } But how can I add that to CodeIgniter? You can add your auto loader above to app/config/config.php . I've used a similar autoload function before in this location and it's worked quite neatly. function __autoload($class) { if (strpos($class, 'CI_') !== 0) { @include_once(APPPATH . 'core/' . $class . EXT); } } Courtesy of Phil Sturgeon. This way may be more portable. core would probably