Yii 1.1: zendautoloader

Allows to efficiently load Zend Framework classes without need to additionally call require_once() or Yii::import().
11 followers

Note: Latest release and documentation are available from component github page.

Allows to efficiently load Zend Framework classes without need to additionally call require_once() or Yii::import().

Installation

Extension

Unpack extension to protected/extensions/.

Zend Framework

Copy ZF directory Zend to protected/vendors/. You can use special service to get only required ZF classes.

Stripping all require_once from ZF

It is required for this extension and allows to load ZF classes faster.

You can do search-replace from your IDE: search require_once replace to //require_once.

Altenatively you can use console:

GNU:

% cd path/to/ZendFramework/library
% find . -name '*.php' -not -wholename '*/Loader/Autoloader.php' \
  -not -wholename '*/Application.php' -print0 | \
  xargs -0 sed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g'

MacOSX:

% cd path/to/ZendFramework/library
% find . -name '*.php' | grep -v './Loader/Autoloader.php' | \
xargs sed -E -i~ 's/(require_once)/\/\/ \1/g'
% find . -name '*.php~' | xargs rm -f

Updating your index.php

We need to register loader before application is run:

define('YII_DEBUG', true);
$webRoot=dirname(__FILE__);
require_once(dirname($webRoot).'/framework/yii.php');
$configFile=$webRoot.'/../protected/config/main.php';
$app = Yii::createWebApplication($configFile);
 
// you can load not only Zend classes but also other classes with the same naming
// convention
EZendAutoloader::$prefixes = array('Zend', 'Custom');
 
Yii::import("ext.yiiext.components.zendAutoloader.EZendAutoloader", true);
Yii::registerAutoloader(array("EZendAutoloader", "loadClass"), true);
 
$app->run();

Changelog

1.1.1

  • Fixed autoloader registration order in readme (Sam Dark)

1.1

  • Ability to load custom code that is using Zend class naming convention but with different prefix.

1.0

  • Initial public release.

Total 9 comments

#9215 report it
Rodrigo Coelho at 2012/07/29 02:02pm
Tweaking the Zend code

Well, in the end I had some issues with Zend trying to include code.
My fixes:

  • I added a return statement in the beginning of Zend_Loader::loadClass.
  • I had to disable the IDN validation in Zend_Validate_Hostname::isValid (line 583 for 1.11.12). Don't forget to add $regexChars = array() or you'll need to disable the foreach below in the file.
#9209 report it
Rodrigo Coelho at 2012/07/28 06:56pm
@yiibie

There are no require, include or include_once in Zend code.

EDIT: Actually, there are some of them on the code. They aren't causing me issues, though.

#9029 report it
yiibie at 2012/07/14 07:43am
stripping requrire_once

What is about include_once, include and require, should I strip them,too? They appear in many files.

#6087 report it
CeBe at 2011/12/11 06:43am
Bugs on github!

@shark: created an issue on github: https://github.com/yiiext/zend-autoloader-component/issues/1

Please discuss there to not spam people who follow this extension.

#6086 report it
shark at 2011/12/11 02:46am
Re: all files in right place?

@CeBe: Yes, they are.

#6082 report it
CeBe at 2011/12/10 04:03pm
all files in right place?

@shark: is your Zend library under protected/vendors/Zend and is Uri/Http.php under there? Make sure you put all files in the right directories.

#6081 report it
shark at 2011/12/10 03:24pm
Wrong path

When I want to use this extension, I got an error:

include_once(Zend/Uri/Http.php): failed to open stream: No such file or directory

My code:

$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($username, $password, $service);
$docs = new Zend_Gdata_Docs($client);
$feed = $docs->getDocumentListFeed();
$this->render('index', array('feed', $feed));

My log:

2011/12/10 21:19:13 [error] [php] include_once(Zend/Uri/Http.php): failed to open stream: No such file or directory (/var/www/modultest.dev/protected/vendors/Zend/Loader.php:146)
Stack trace:
#0 /var/www/modultest.dev/protected/vendors/Zend/Uri.php(137): loadClass()
#1 /var/www/modultest.dev/protected/vendors/Zend/Http/Client.php(305): factory()
#2 /var/www/modultest.dev/protected/vendors/Zend/Gdata/ClientLogin.php(106): Zend_Gdata_HttpClient->setUri()
#3 /var/www/modultest.dev/protected/modules/ZendTest/controllers/DefaultController.php(8): getHttpClient()
#4 /var/www/modultest.dev/framework/web/actions/CInlineAction.php(50): DefaultController->actionIndex()
#5 /var/www/modultest.dev/framework/web/CController.php(300): CInlineAction->runWithParams()
#6 /var/www/modultest.dev/framework/web/CController.php(278): DefaultController->runAction()
#7 /var/www/modultest.dev/framework/web/CController.php(257): DefaultController->runActionWithFilters()
#8 /var/www/modultest.dev/framework/web/CWebApplication.php(277): DefaultController->run()
#9 /var/www/modultest.dev/framework/web/CWebApplication.php(136): CWebApplication->runController()
#10 /var/www/modultest.dev/framework/base/CApplication.php(158): CWebApplication->processRequest()
#11 /var/www/modultest.dev/index.php(22): CWebApplication->run()

Can anyone help me?

#4320 report it
yiqing95 at 2011/06/25 10:02pm
this extension is a part of yiiext;

you needn't use the sample way to import this ext; just put it to components dir or extension dir , and shorten the deep of dir path:

backwardselvis is right , we should firs import the EZendAutoloader,and then set the static prefixes var :

// First Import the extension
Yii::import("ext.yiiext.EZendAutoloader", true);
//or Yii::import("application.components.yiiext.EZendAutoloader", true);
 
// And then call the loaded class
EZendAutoloader::$prefixes = array('Zend', 'Custom');
 
Yii::registerAutoloader(array("EZendAutoloader", "loadClass"));
#2168 report it
backwardselvis at 2010/11/21 02:47am
This didn't work for me until...
// First Import the extension
Yii::import("ext.yiiext.components.zendAutoloader.EZendAutoloader", true);
 
// And then call the loaded class
EZendAutoloader::$prefixes = array('Zend', 'Custom');
 
Yii::registerAutoloader(array("EZendAutoloader", "loadClass"));

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet