Akismet.php

Go to the documentation of this file.
00001 <?php
00002 
00031 class Robo47_Application_Resource_Service_Akismet
00032 extends Zend_Application_Resource_ResourceAbstract
00033 {
00034 
00038     protected $_service = null;
00039     
00040     public function init()
00041     {
00042         if (!empty($this->_options)) {
00043             $this->_service = $this->_setupService($this->_options);
00044         } else {
00045             $message = 'Empty options in resource ' .
00046                 'Robo47_Application_Resource_Service_Akismet.';
00047             throw new Robo47_Application_Resource_Exception($message);
00048         }
00049     }
00050 
00057     protected function _setupService($options)
00058     {
00059         if (!isset($options['apiKey'])) {
00060             $message = 'option "apiKey" not found for Service_Akismet';
00061             throw new Robo47_Application_Resource_Exception($message);
00062         }
00063         if (!isset($options['blog'])) {
00064             $message = 'option "blog" not found for Service_Akismet';
00065             throw new Robo47_Application_Resource_Exception($message);
00066         }
00067 
00068         $akismet = new Zend_Service_Akismet(
00069             $options['apiKey'],
00070             $options['blog']
00071         );
00072 
00073         if (isset($options['charset'])) {
00074             $akismet->setCharset($options['charset']);
00075         }
00076 
00077         if (isset($options['userAgent'])) {
00078             $akismet->setUserAgent($options['userAgent']);
00079         }
00080 
00081         if (isset($options['port'])) {
00082             // casting needed because of is_int in Zend_Service_Akismet::setPort
00083             $akismet->setPort((int) $options['port']);
00084         }
00085 
00086         if (isset($options['registryKey'])) {
00087             Zend_Registry::set($options['registryKey'], $akismet);
00088         }
00089 
00090         return $akismet;
00091     }
00092 
00098     public function getService()
00099     {
00100         return $this->_service;
00101     }
00102 }