Re: Namespaced code with SabreDAV

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Oct 6, 2011 at 7:37 AM, Andrew Mason <slackmase2@xxxxxxxxx> wrote:

> Hello all,
> I am trying to use the wonderful SabreDAV library to create a webdav
> share. I have a demo up and running however the framework / class i'm
> using is namespaced, and SabreDAV unfortunately does not have a 5.3
> style namespace declaration.
>
> I have an spl_autoload function registered in my base controller and
> so long as I prefix the classname with a \ it all works:
>
>
>  $rootDirectory = new \Sabre_DAV_FS_Directory($rootDir);
>
> // The server object is responsible for making sense out of the WebDAV
> protocol
> $server = new \Sabre_DAV_Server($rootDirectory);
>
>
> However, SabreDAV it's self has a large amount of other PHP classes
> which it calls which obviously aren't prefixed with '\'
>
> Is there a way i can tell PHP any class name that get's instanciated
> with 'Sabre_' should resolve to '\Sabre' ?
>
> Many thanks
> Andrew
>
>
If my memory serves regarding PHP's namespace, you could build something
like this

        $file = APP_DIR.'\'.$class;
        if( file_exists( $file ) ) require_once $file;

into your autoloader.  You may have to adjust '/' to/from '\\' depending on
your platform or you can use the constant DIRECTORY_SEPARATOR in the full
path to the class.  Then you don't need add \ before your class to
instantiate.  I don't know how the SabreDAV framework looks like but you may
want to look at how Zend framework loads their class as to give you some
idea what you may need to do in your autoload to circumvent SabreDAV being
not 5.3 namespace declaration.  You may also want to take a look at
CodeIgniter's autoloading mechanism.

Regards,
Tommy

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux