Is it possible to use the existing / included Zend Framework in another Magento application?

I want to create a small Zend application that will work with our Magento (Enterprise) installation. Can I use existing Zend code included in Magento? Or do I need another separate copy of Zend?

I'm afraid Varien probably messed up the frame code. Just see that they commented out all the require () requirements, which throw a lot of errors (obviously). Zend AutoLoader will not work, anyway. Is there a way to use Variain AutoLoader instead?

I don’t really want to import another infrastructure (3000+ files) into our project, if I can avoid it.

Thanks!

EDIT:

Here is my structure:

/localsite/ -- root /localsite/products -- Magento install /localsite/products/lib/Zend --Zend in Mage folder /localsite/fbtest -- my Zend Framework app root /localsite/fbtest/application -- my Zend Framework app 

Here is the code I'm trying (/localsite/fbtest/public/index.php):

 <?php define('DS', DIRECTORY_SEPARATOR); defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); set_include_path(implode(PATH_SEPARATOR, array( BASE_PATH . DS . 'products' . DS . 'lib' . DS . 'Zend', get_include_path(), ))); require_once('../../products/lib/Zend/Application.php'); $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap() ->run(); 

Here is the error:

 Fatal error: Class 'Zend_Loader_Autoloader' not found in C:\xampp\htdocs\localsite\products\lib\Zend\Application.php on line 81 

Here is the include_path:

 C:\xampp\htdocs\localsite\products\lib\Zend;.;C:\php\pear 

And here you should enable AutoLoader (in / products / lib / Zend / Application.php):

 #require_once 'Zend/Loader/Autoloader.php'; $this->_autoloader = Zend_Loader_Autoloader::getInstance(); 

^^^ see that '#' where require_once is commented out? I think the Varien change that violated Frame is not? Looks like why it doesn't work for me, at least? How can I get around this and include all the comments in it?

Thanks again

+4
source share
4 answers

add the magento library folder to include the path in index.php:

 //define shortcut for DIRECTORY_SEPARATOR defined('DS') || define('DS', DIRECTORY_SEPARATOR); //define base bath obtainable throughout the whole application defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__) . DS . '..' . DS . 'basedir' . DS)); //define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', BASE_PATH . DS . 'app'); //set include path to libraries set_include_path(BASE_PATH . DS . 'library' . PATH_SEPARATOR . MAGENTO_DIR . DS . 'lib' . PATH_SEPARATOR . get_include_path()); 

But with this approach, you cannot use the latest version of ZF. Therefore, a separate installation is my choice.

autoloader works, an easy way is to place the original Zend / Loader / in your application library or enable all the necessary autoloader classes manually (only 3: loader, autoloader, Zend_Exception)

Here is my full projectName / public / index.php:

 if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); $_GET = array_map('stripslashes_deep', $_GET); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); $_REQUEST = array_map('stripslashes_deep', $_REQUEST); } //define shortcut for DIRECTORY_SEPARATOR defined('DS') || define('DS', DIRECTORY_SEPARATOR); //define base bath obtainable throughout the whole application defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__) . DS . '..' . DS . 'basedir')); //define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', BASE_PATH . DS . 'app'); //set include path to libraries set_include_path(BASE_PATH . DS . 'library' . PATH_SEPARATOR . get_include_path()); //bootstrap, and run application try { require_once 'Zend/Application.php'; //create application and configure it. $application = new Zend_Application( getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production', array('config' => array(APPLICATION_PATH . DS . 'configs' . DS . 'application.ini')) ); //run application $application->bootstrap()->run(); } catch (Exception $e) { //here was logging logic } 

Here is what your /localsite/fbtest/public/index.php looks like:

 if (get_magic_quotes_gpc()) { function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } $_POST = array_map('stripslashes_deep', $_POST); $_GET = array_map('stripslashes_deep', $_GET); $_COOKIE = array_map('stripslashes_deep', $_COOKIE); $_REQUEST = array_map('stripslashes_deep', $_REQUEST); } //define shortcut for DIRECTORY_SEPARATOR defined('DS') || define('DS', DIRECTORY_SEPARATOR); //define base bath obtainable throughout the whole application //keep your libraries and application out of public directory defined('BASE_PATH') || define('BASE_PATH', realpath(dirname(__FILE__) . DS . '..' . DS . 'basedir')); //define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', BASE_PATH . DS . 'application'); //if index.php in /localsite/fbtest/public/ defined('MAGENTO_PATH') || define('MAGENTO_PATH', realpath(dirname(__FILE__) . DS . '..' . DS . '..' . DS . 'products')); //set include path to libraries //noticed magento library added? set_include_path(BASE_PATH . DS . 'library' . PATH_SEPARATOR . MAGENTO_PATH . DS . 'lib' . PATH_SEPARATOR . get_include_path()); //bootstrap, and run application try { require_once 'Zend/Application.php'; require_once 'Zend/Loader.php'; require_once 'Zend/Loader/Autoloader.php'; require_once 'Zend/Exception.php'; //create application and configure it. $application = new Zend_Application( getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production', array('config' => array(APPLICATION_PATH . DS . 'configs' . DS . 'application.ini')) ); //run application $application->bootstrap()->run(); } catch (Exception $e) { //here was logging logic } 
+4
source

OK I understood! The Zend Framework with Magento is not really broken ... but they do things a little different than usual.

1) It is normal to comment require_once () instructions in Zend when you enable lazy loading with Zend Loader. This is a thing of execution:
http://framework.zend.com/manual/en/performance.classloading.html

2) However, it is not entirely normal to comment on them in the Application.php and Loader.php classes:

[keep] require_once () calls in Zend_Application and Zend_Loader_Autoloader, since these classes will work without them.

So the answer is to simply add 3 missing require_once () statements yourself when you enable Loader.php. Here is my new code that works (in my index.php applications):

 <?php define('DS', DIRECTORY_SEPARATOR); defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); set_include_path(implode(PATH_SEPARATOR, array( BASE_PATH . DS . 'products' . DS . 'lib', '.', ))); require_once 'Zend/Loader.php'; require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); require_once APPLICATION_PATH.'/Bootstrap.php'; $application = new Zend_Application( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $application->bootstrap() ->run(); 

Now i'm running! The problem is that I simply did not know how the autoloader was configured. Hope this helps someone!

+3
source

I'm afraid Varien probably messed up the frame code.

I assume this violates the terms of use (with the exception of the require_once exception).

Zend_Autoloader should work fine IMO. Just set up the enable path and you're fine;)

Update:

You can see from your code that you did not specify the constant BASE_PATH . Therefore, the inclusion path is not defined and Zend_Loader_Autoloader cannot be loaded. If your inclusion path is ok, then it is ok to write require_once 'Zend/Loader/Autoloader.php'; no way. There is also no need to require Zend_Loader , which it is deprecated.

You also include Zend_Application not Loader . What for? Only the class that has ever been required for "hard code" is the autoloader using the string require_once 'Zend/Loader/Autoloade.php'; - NOTHING MORE. If it does not work, your inclusion path is confused.

+1
source

The following code allowed the use of the Zend-Framework in a cli script. The Zend-Framework shipped with Magento was used for the cli script.

 // 1. point libPath to the <magento-root>/lib directory $libPath=realpath(dirname(__FILE__).'../../../lib') ; // 2. set the Zend-Framework include-path set_include_path($libPath . PATH_SEPARATOR . get_include_path()); // 3. manual includes require_once 'Zend/Loader.php'; require_once 'Zend/Loader/Autoloader.php'; // 4. instantiate the autoloader Zend_Loader_Autoloader::getInstance(); 

This allowed the use of Zend_Http_Client and all of its dependency classes.

+1
source

Source: https://habr.com/ru/post/1344112/


All Articles