Good practice in handling includes & requires

What are good practices in handling includes and requires of huge/small third party libraries?

I already made use of autloading, but there are scenarios where autoloading does not help.

If you download huge external libraries like SwiftMailer or Google API, the filename is not really similar to their classnames and contains lots of files which actually use the native "include" and "require" functions.

Sometimes we just want to separate a part of our code from the body of a function to a sperate file.

If i need to include bunch of php files to my components or a portion of the body of a function I do this:


        

        public function showErrorPage()

        {

            $applicationPath = Yii::getPathOfAlias('webroot');  

            include("$applicationPath/protected/modules/users/view/tool/errorpage.php");

        }



If I need to include the google API library which has lots of baggage on it I could do it this way




        $applicationPath = Yii::getPathOfAlias('webroot'); 

        // Google Adwords API Library

        include('$applicationPath/protected/libraries/aw_api_php_lib_2.5.1/src/Google/Api/Ads/AdWords/Lib/AdWordsUser.php');



Is there a specific Yii-way to do this?

There’s not really a Yii-specific way AFAIK, but this is a neat way of doing it:


require_once(dirname(__FILE__).'/vendors/the_vendor.php');

If you put your vendor code in a ‘vendor’ directory in a subdirectory of your component/widget/whatever.

And another - probably more Yii-ish (which I use for my Rss feed code), using the application-wide ‘vendors’ directory:


Yii::import('application.vendors.*');

require_once('Zend/Feed.php');

require_once('Zend/Feed/Rss.php');



HTH :)

Almost every library provides its own autoloader (as SwiftMailer does, for example). Just register it with Yii::registerAutoloader().