Last active
August 29, 2015 14:04
-
-
Save ProxiBlue/417f488bdd3ade5e5147 to your computer and use it in GitHub Desktop.
Rewrite a non existing magento core class....
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I found it is possible to do a rewrite on a core class that does not actually exist.... | |
Usage case: | |
I am creating a reCaptcha module that integrates google recaptcha into magento's core captcha system. | |
In the core captcha you have the ability to state a 'type', as can be seen in the config.xml | |
of Mage_Captcha | |
<default> | |
...... | |
<admin> | |
<captcha> | |
<type>zend</type> <<<<<<<<<<<<<<< specify a captcha type (model) | |
<enable>0</enable> | |
<font>linlibertine</font> | |
<mode>after_fail</mode> | |
<forms>backend_forgotpassword</forms> | |
<failed_attempts_login>3</failed_attempts_login> | |
<failed_attempts_ip>1000</failed_attempts_ip> | |
<timeout>7</timeout> | |
<length>4-5</length> | |
<symbols>ABCDEFGHJKMnpqrstuvwxyz23456789</symbols> | |
<case_sensitive>0</case_sensitive> | |
<always_for> | |
<backend_forgotpassword>1</backend_forgotpassword> | |
</always_for> | |
</captcha> | |
</admin> | |
...... | |
</default> | |
so in my module I added a new type called 'recapcha' | |
however, the developer of that core module kinda locked the model location down to exist | |
within the Mage_Captcha namespace, as can be seen in the helper class of that module | |
/** | |
* Get Captcha | |
* | |
* @param string $formId | |
* @return Mage_Captcha_Model_Interface | |
*/ | |
public function getCaptcha($formId) | |
{ | |
if (!array_key_exists($formId, $this->_captcha)) { | |
$type = $this->getConfigNode('type'); | |
$this->_captcha[$formId] = Mage::getModel('captcha/' . $type, array('formId' => $formId)); | |
} | |
return $this->_captcha[$formId]; | |
} | |
so Mage_Captcha_Model_Recaptcha does not actually exist, which means I cannot use this.... | |
BUT, if, I place a rewrite directive in my module for that class/file, to a model class | |
in my module, I can intercept the model instantiation, and successfully instantiate my class. | |
So, is this a bug, or a feature? Should I not depend on this ability? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment