Exemplo n.º 1
0
 /**
  * Return controller methods using reflection
  * @param string $controller Controller to reflect
  * @return array 
  */
 private function getControllerMethods($controller)
 {
     // Check controller exists
     if (!\Sonic\Sonic::_classExists(__NAMESPACE__ . '\\' . $controller)) {
         return array();
     }
     // Set actions
     $actions = array();
     /**
      * Reflect controller
      */
     $reflection = new \ReflectionClass(__NAMESPACE__ . '\\' . $controller);
     $className = $reflection->getName();
     // Get class methods
     foreach ($reflection->getMethods() as $method) {
         // Dont use methods from parent classes
         if ($method->getDeclaringClass()->getName() != $className) {
             continue;
         }
         // Skip unless the method is public
         if (!$method->isPublic()) {
             continue;
         }
         // Skip methods starting with __
         if (substr($method->getName(), 0, 2) == '__') {
             continue;
         }
         // Get class name and comment
         $name = $method->getName();
         $comment = new \Sonic\Model\Tools\Comment($method->getDocComment());
         // Skip if @ignore is set in the method comment
         if ($comment->hasTag('ignore')) {
             continue;
         }
         // Add action
         $actions[$name] = array('description' => $comment->getShortDescription(), 'notes' => $comment->getLongDescription(), 'url' => URL_ROOT . str_replace('\\', '/', strtolower($controller)) . '/' . $name, 'auth' => FALSE);
         // Deal with authenticated method
         if ($comment->hasTag('authenticated')) {
             $actions[$name]['auth'] = TRUE;
         }
         // Add method parameters
         $params = $comment->getTags('param');
         if ($params) {
             foreach ($params as $param) {
                 if (!preg_match('/^(\\w+)\\s+\\$([\\w\\d]+)\\s*(.*?)$/', $param, $arr)) {
                     continue;
                 }
                 $actions[$name]['param'][] = array('type' => $arr[1], 'name' => $arr[2], 'description' => $arr[3]);
             }
         }
     }
     // Return actions
     return $actions;
 }
Exemplo n.º 2
0
<?php

// Define database settings directory
@define('CONFIG_DB_DIR', CONFIG_DIR . 'db' . DS);
// Load settings
require_once CONFIG_DB_DIR . 'default.php';
// Set database resources
\Sonic\Sonic::newResource('db', new \Sonic\Resource\Db\DefaultConnection());
<?php

// Load settings
require_once CONFIG_DB_DIR . 'default.php';
// Set database resources
\Sonic\Sonic::newResources('db-slave', array(new Resource\Db\MySQL\Slave(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME), new Resource\Db\MySQL\Slave(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME)), FALSE);
Exemplo n.º 4
0
 /**
  * Call an API action
  * @param string $strAction Action
  * @return mixed
  */
 public function Action($strAction = FALSE)
 {
     // If an action argument is set
     if ($strAction) {
         // Set it
         $this->action = $strAction;
     } else {
         if (isset($this->args['method'])) {
             // Set it
             $this->action = $this->args['method'];
         }
     }
     // Auditlog
     $auditlog = \Sonic\Sonic::getResource('auditlog');
     $logType = 2;
     // Default to success
     $logParams = FALSE;
     $logResponse = FALSE;
     // Explode action
     $arrAction = explode('.', $this->action);
     // If there are 2 or more items then there is a module and permission
     if (count($arrAction) >= 2) {
         // Set the module and method names
         $strMethod = array_pop($arrAction);
         $strModule = implode('.', $arrAction);
         // Get the module object
         $objModule = $this->getModule($strModule);
         // If the module was loaded
         if ($objModule) {
             // If the method exists
             if ($objModule->checkMethod($strMethod)) {
                 // Check the method limitation
                 if ($this->checkLimitation($strModule, $strMethod)) {
                     // Call the method
                     $arrReturn = $objModule->callMethod($this, $strModule, $strMethod, $this->args);
                     // If the return is ok
                     if ($arrReturn['status'] == 'ok') {
                         // Set as success
                         $this->result['status'] = 'ok';
                         // Remove any result status
                         unset($arrReturn['status']);
                         // Add return
                         if ($arrReturn) {
                             $this->result[$strMethod] = $arrReturn;
                         }
                         // Auditlog
                         $logType = 2;
                         //							$logParams		= $this->args;
                         //							$logResponse	= $this->result;
                     } else {
                         // Set any results
                         foreach ($arrReturn as $strKey => $strVal) {
                             $this->result[$strKey] = $strVal;
                         }
                         // Auditlog
                         $logType = 3;
                         $logParams = $this->args;
                         $logResponse = @$this->result['message'];
                     }
                 } else {
                     // Set error
                     $this->result['status'] = 'fail';
                     $this->result['message'] = 'method access limited';
                     // Set auditlog type
                     $logType = 11;
                 }
             } else {
                 // Set error
                 $this->result['status'] = 'fail';
                 $this->result['message'] = 'invalid method';
                 // Set auditlog type
                 $logType = 10;
             }
         } else {
             // Set error
             $this->result['status'] = 'fail';
             $this->result['message'] = 'invalid module';
             // Set auditlog type
             $logType = 9;
         }
     } else {
         // Set error
         $this->result['status'] = 'fail';
         $this->result['message'] = 'invalid action';
         // Set auditlog type
         $logType = 8;
     }
     // Set the request and response types and the action
     $this->result['method'] = $this->action;
     $this->result['request_type'] = $this->requestType;
     $this->result['return_type'] = $this->returnType;
     // Auditlog
     if ($auditlog instanceof Audit\Log) {
         $auditlog::_Log($this->action, $logType, $logParams, $logResponse);
     }
     // Return TRUE
     return TRUE;
 }
Exemplo n.º 5
0
 /**
  * Send email to recipients using PHP mail
  * @return boolean
  */
 private function sendUsingPHP()
 {
     // Construct Headers
     $headers = $this->constructHeaders();
     // Get template resource
     $tpl = \Sonic\Sonic::getResource('tpl');
     // Set smarty template status
     $smarty = $tpl instanceof \Smarty;
     // If we have a smarty template object
     if ($smarty) {
         // Get caching status
         $smartyPrevCache = $tpl->caching;
         // Disable caching
         $tpl->setCaching(FALSE);
     }
     // For each recipient
     foreach ($this->_recipients as $recipient) {
         // Send email
         try {
             // Check to make sure the recipients email address is valid
             Parser::_validateEmail($recipient['email']);
             // Set recipient
             $recipientTo = $recipient['name'] . '<' . $recipient['email'] . '>';
             // Add recipient header to original headers
             $emailHeaders = $headers . 'To: ' . $recipientTo . $this->_nl;
             // If we're using smarty
             if ($smarty) {
                 // Clear variables
                 $tpl->clearAllAssign();
                 // Assign variables
                 $tpl->assign('recipient', $recipient);
                 // Fetch
                 $emailMessage = $tpl->fetch('string:' . $this->_message);
             } else {
                 // Just leave the message as it is
                 $emailMessage = $this->_message;
             }
             // Send Message
             if (!mail($recipientTo, $this->_subject, $emailMessage, $emailHeaders)) {
                 // Add error and return FALSE
                 new \Sonic\Message('error', 'Cannot send message to: ' . $recipient['email']);
                 // return FALSE
                 return FALSE;
             }
             if (is_callable($this->_callbackMethod)) {
                 call_user_func($this->_callbackMethod, $this->_subject, $recipientTo, $this->_fromAddress, $emailMessage);
             }
             // If we're logging the email
             if ($this->logFlag) {
                 // Log
                 $this->Log($recipient['email'], $emailHeaders, $emailMessage, 'phpmail');
             }
         } catch (Parser\Exception $e) {
             // Add error
             new \Sonic\Message('error', 'Invalid recipient email address: ' . $recipient['email']);
             // Skip to next recipient
             continue;
         }
     }
     // If we're using smarty
     if ($smarty) {
         // Set caching status
         $tpl->caching = $smartyPrevCache;
     }
     // Return TRUE
     return TRUE;
 }