[fw-general] Calling externa l autoload function – how to?

2009-04-10 Thread bytte

I'm using DOMPDF in a project of mine and I was wondering how I can call
DOMPDF's autoload function so it can function together with the one from
Zend Framework.

Here's what DOMPDF says:

/**
 * DOMPDF autoload function
 *
 * If you have an existing autoload function, add a call to this function
 * from your existing __autoload() implementation.
 *
 * @param string $class
 */
function DOMPDF_autoload($class) {
  $filename = mb_strtolower($class) . .cls.php;
  require_once(DOMPDF_INC_DIR . /$filename);
}

How exactly can I make it work together with the ZF?
-- 
View this message in context: 
http://www.nabble.com/Calling-external-autoload-function-%E2%80%93-how-to--tp22987919p22987919.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] Calling externa l autoload function – how to?

2009-04-10 Thread Matthew Weier O'Phinney
-- bytte thomas.bytteb...@gmail.com wrote
(on Friday, 10 April 2009, 06:22 AM -0700):
 I'm using DOMPDF in a project of mine and I was wondering how I can call
 DOMPDF's autoload function so it can function together with the one from
 Zend Framework.
 
 Here's what DOMPDF says:
 
 /**
  * DOMPDF autoload function
  *
  * If you have an existing autoload function, add a call to this function
  * from your existing __autoload() implementation.
  *
  * @param string $class
  */
 function DOMPDF_autoload($class) {
   $filename = mb_strtolower($class) . .cls.php;
   require_once(DOMPDF_INC_DIR . /$filename);
 }
 
 How exactly can I make it work together with the ZF?

Use spl_autoload_register() to register that function with the SPL
autoloader:

spl_autoload_register('DOMPDF_autoload');

and then call:

Zend_Loader::registerAutoload();

Starting in ZF 1.8, you can do the following instead:

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader-pushAutoloader('DOMPDF_autoload');

-- 
Matthew Weier O'Phinney
Software Architect  | matt...@zend.com
Zend Framework  | http://framework.zend.com/


Re: [fw-general] Calling externa l autoload function – how to?

2009-04-10 Thread Matthew Weier O'Phinney
-- bytte thomas.bytteb...@gmail.com wrote
(on Friday, 10 April 2009, 09:28 AM -0700):
 
 Thanks. But I'm confused. Early on in my bootstrap I have this code:
 
 set_include_path('.' . PATH_SEPARATOR . '../library/'
 . PATH_SEPARATOR . '../application/models'
 . PATH_SEPARATOR . '../application/forms'
 . PATH_SEPARATOR . '../library/dompdf-0.5.1'
 . PATH_SEPARATOR . get_include_path());
 include Zend/Loader.php;
 Zend_Loader::registerAutoload();
 
 Then where exactly do I need to insert this spl_autoload_register()
 function?

Before the Zend_Loader::registerAutoload() call.

 If I do it in my controller where I create the pdf, the pdf gets created but
 it starts with a lot of warnings because a lot of files in the DOMPDF file
 structure weren't found. Such as:
 
 Warning: Zend_Loader::include_once() [function.include]: Failed opening
 'Style.php' for inclusion
 (include_path='.:../library/:../application/models:../application/forms:../library/dompdf-0.5.1:.:/opt/local/lib/php')
 in /Users/xxx/Sites/zf-test/library/Zend/Loader.php on line 83
 
 If I do it in my bootstrap just before Zend_Loader::registerAutoload(), all
 my other code doesn't work anymore as it looks like the DOMPDF autoloader is
 used to load all the ZF classes. Here's the warnings I get then:
 
 Warning:
 require_once(/Users/xxx/Sites/zf-test/library/dompdf-0.5.1/include/zend_config_ini.cls.php)
 [function.require-once]: failed to open stream: No such file or directory in
 /Users/xxx/Sites/zf-test/library/dompdf-0.5.1/dompdf_config.inc.php on line
 194
 
 Could you provide me with some more information? It would be really helpful.
 
 
 
 
 
 Mon Zafra wrote:
  
  spl_autoload_register('DOMPDF_autoload');
  
  Make sure that loader is registered late in the stack because it does a
  require_once, meaning it will throw a fatal if it fails and will prevent
  the
  other autoloaders from trying to load the class.
  
 -- Mon
  
  
  On Fri, Apr 10, 2009 at 9:22 PM, bytte thomas.bytteb...@gmail.com wrote:
  
 
  I'm using DOMPDF in a project of mine and I was wondering how I can call
  DOMPDF's autoload function so it can function together with the one from
  Zend Framework.
 
  Here's what DOMPDF says:
 
  /**
   * DOMPDF autoload function
   *
   * If you have an existing autoload function, add a call to this function
   * from your existing __autoload() implementation.
   *
   * @param string $class
   */
  function DOMPDF_autoload($class) {
   $filename = mb_strtolower($class) . .cls.php;
   require_once(DOMPDF_INC_DIR . /$filename);
  }
 
  How exactly can I make it work together with the ZF?
  --
  View this message in context:
  http://www.nabble.com/Calling-external-autoload-function-%E2%80%93-how-to--tp22987919p22987919.html
  Sent from the Zend Framework mailing list archive at Nabble.com.
 
 
  
  
 
 -- 
 View this message in context: 
 http://www.nabble.com/Calling-external-autoload-function-%E2%80%93-how-to--tp22987919p22990711.html
 Sent from the Zend Framework mailing list archive at Nabble.com.
 

-- 
Matthew Weier O'Phinney
Software Architect  | matt...@zend.com
Zend Framework  | http://framework.zend.com/


Re: [fw-general] Calling externa l autoload function – how to?

2009-04-10 Thread Matthew Weier O'Phinney
-- Joshua Kaiser joe...@gmail.com wrote
(on Friday, 10 April 2009, 12:30 PM -0600):
 I wish to be removed as well, but I don't see a link to do it.  Any help would
 be appreciated.

Send an email to:

fw-general-unsubscr...@lists.zend.com

No subject or body necessary. You'll get a confirmation request email,
and follow the instructions from there.

 -
 Joshua Kaiser
 
 Emo Philips  - A computer once beat me at chess, but it was no match for me 
 at
 kick boxing.
 
 On Fri, Apr 10, 2009 at 10:51 AM, Richard Whitney phpmy...@gmail.com wrote:
 
 unsubscribe me please
 
 On Fri, Apr 10, 2009 at 6:22 AM, bytte thomas.bytteb...@gmail.com wrote:
 
 
 I'm using DOMPDF in a project of mine and I was wondering how I can
 call
 DOMPDF's autoload function so it can function together with the one
 from
 Zend Framework.
 
 Here's what DOMPDF says:
 
 /**
  * DOMPDF autoload function
  *
  * If you have an existing autoload function, add a call to this
 function
  * from your existing __autoload() implementation.
  *
  * @param string $class
  */
 function DOMPDF_autoload($class) {
  $filename = mb_strtolower($class) . .cls.php;
  require_once(DOMPDF_INC_DIR . /$filename);
 }
 
 How exactly can I make it work together with the ZF?
 --
 View this message in context: http://www.nabble.com/
 
 Calling-external-autoload-function-%E2%80%93-how-to--tp22987919p22987919.html
 Sent from the Zend Framework mailing list archive at Nabble.com.
 
 
 
 
 
 --
 Richard Whitney
 phpmy...@gmail.com
 http://phpmydev.com
 Ofc. 602-288-5340
 Ofc. 877-624-6302
 Fax. 480-704-4559
 
 You have ideas, I have solutions.
 
 

-- 
Matthew Weier O'Phinney
Software Architect  | matt...@zend.com
Zend Framework  | http://framework.zend.com/


Re: [fw-general] Calling externa l autoload function – how to?

2009-04-10 Thread Matthew Weier O'Phinney
-- bytte thomas.bytteb...@gmail.com wrote
(on Friday, 10 April 2009, 03:40 PM -0700):
 But then I get these errors everywhere:
 
 Warning:
 require_once(/Users/xxx/Sites/zf-test/library/dompdf-0.5.1/include/zend_config_ini.cls.php)
 [function.require-once]: failed to open stream: No such file or directory in
 /Users/xxx/Sites/zf-test/library/dompdf-0.5.1/dompdf_config.inc.php on line
 194
 
 And
 
 Fatal error: require_once() [function.require]: Failed opening required
 '/Users/xxx/Sites/zf-test/library/dompdf-0.5.1/include/zend_config_ini.cls.php'
 (include_path='.:../library/:../application/models:../application/forms:../library/dompdf-0.5.1:.:/opt/local/lib/php')
 in /Users/xxx/Sites/zf-test/library/dompdf-0.5.1/dompdf_config.inc.php on
 line 194
 
 What am I doing wrong?

Well, *you* aren't -- the authors of DOMPDF are by using require_once in
their autoloader (that's a no-no; autoloaders should be chainable, and
thus fail gracefully). Create your own autoloader function for their
stuff that's a bit less restrictive. For example, try the following in
your bootstrap:

function My_DOMPDF_Autoload($class)
{
$filename = DOMPDF_INC_DIR . '/' . mb_strtolower($class) . '.cls.php';
if (Zend_Loader::isReadable($filename)) {
return include_once $filename;
}
return false;
}

require_once 'Zend/Loader.php';
spl_register_autoload('My_DOMPDF_Autoload');
Zend_Loader::registerAutoload();

and that should work.

 Matthew Weier O'Phinney-3 wrote:
  
  -- bytte thomas.bytteb...@gmail.com wrote
  (on Friday, 10 April 2009, 09:28 AM -0700):
  
  Thanks. But I'm confused. Early on in my bootstrap I have this code:
  
  set_include_path('.' . PATH_SEPARATOR . '../library/'
  . PATH_SEPARATOR . '../application/models'
  . PATH_SEPARATOR . '../application/forms'
  . PATH_SEPARATOR . '../library/dompdf-0.5.1'
  . PATH_SEPARATOR . get_include_path());
  include Zend/Loader.php;
  Zend_Loader::registerAutoload();
  
  Then where exactly do I need to insert this spl_autoload_register()
  function?
  
  Before the Zend_Loader::registerAutoload() call.
  
  If I do it in my controller where I create the pdf, the pdf gets created
  but
  it starts with a lot of warnings because a lot of files in the DOMPDF
  file
  structure weren't found. Such as:
  
  Warning: Zend_Loader::include_once() [function.include]: Failed opening
  'Style.php' for inclusion
  (include_path='.:../library/:../application/models:../application/forms:../library/dompdf-0.5.1:.:/opt/local/lib/php')
  in /Users/xxx/Sites/zf-test/library/Zend/Loader.php on line 83
  
  If I do it in my bootstrap just before Zend_Loader::registerAutoload(),
  all
  my other code doesn't work anymore as it looks like the DOMPDF autoloader
  is
  used to load all the ZF classes. Here's the warnings I get then:
  
  Warning:
  require_once(/Users/xxx/Sites/zf-test/library/dompdf-0.5.1/include/zend_config_ini.cls.php)
  [function.require-once]: failed to open stream: No such file or directory
  in
  /Users/xxx/Sites/zf-test/library/dompdf-0.5.1/dompdf_config.inc.php on
  line
  194
  
  Could you provide me with some more information? It would be really
  helpful.
  
  
  
  
  
  Mon Zafra wrote:
   
   spl_autoload_register('DOMPDF_autoload');
   
   Make sure that loader is registered late in the stack because it does a
   require_once, meaning it will throw a fatal if it fails and will
  prevent
   the
   other autoloaders from trying to load the class.
   
  -- Mon
   
   
   On Fri, Apr 10, 2009 at 9:22 PM, bytte thomas.bytteb...@gmail.com
  wrote:
   
  
   I'm using DOMPDF in a project of mine and I was wondering how I can
  call
   DOMPDF's autoload function so it can function together with the one
  from
   Zend Framework.
  
   Here's what DOMPDF says:
  
   /**
* DOMPDF autoload function
*
* If you have an existing autoload function, add a call to this
  function
* from your existing __autoload() implementation.
*
* @param string $class
*/
   function DOMPDF_autoload($class) {
$filename = mb_strtolower($class) . .cls.php;
require_once(DOMPDF_INC_DIR . /$filename);
   }
  
   How exactly can I make it work together with the ZF?
   --
   View this message in context:
  
  http://www.nabble.com/Calling-external-autoload-function-%E2%80%93-how-to--tp22987919p22987919.html
   Sent from the Zend Framework mailing list archive at Nabble.com.
  
  
   
   
  
  -- 
  View this message in context:
  http://www.nabble.com/Calling-external-autoload-function-%E2%80%93-how-to--tp22987919p22990711.html
  Sent from the Zend Framework mailing list archive at Nabble.com.
  
  
  -- 
  Matthew Weier O'Phinney
  Software Architect  | matt...@zend.com
  Zend Framework  | http://framework.zend.com/
  
  
 
 -- 
 View this message in context: 
 http://www.nabble.com/Calling-external-autoload-function-%E2%80%93-how-to--tp22987919p22995726.html
 Sent from the Zend Framework