Exemple #1
0
 function _init()
 {
     $this->logger =& Ak::getLogger();
     $base = AK_TEST_DIR . DS . 'unit' . DS . 'lib' . DS;
     $this->GroupTest($this->title);
     $allFiles = glob($base . $this->baseDir);
     if (isset($this->excludes)) {
         $excludes = array();
         $this->excludes = @Ak::toArray($this->excludes);
         foreach ($this->excludes as $pattern) {
             $excludes = array_merge($excludes, glob($base . $pattern));
         }
         $this->excludes = $excludes;
     } else {
         $this->excludes = array();
     }
     if (count($allFiles) >= 1 && $allFiles[0] != $base . $this->baseDir && $this->partial_tests === true) {
         $this->_includeFiles($allFiles);
     } else {
         if (is_array($this->partial_tests)) {
             foreach ($this->partial_tests as $test) {
                 //$this->log('Including partial testfile:'.$test);
                 $this->addTestFile($base . $this->baseDir . DS . $test . '.php');
             }
         } else {
             echo "No files in : " . $this->title . "\n";
         }
     }
 }
Exemple #2
0
 public function log($message, $type = '', $identifyer = '')
 {
     if (AK_LOG_EVENTS) {
         $Logger =& Ak::getLogger();
         $Logger->log($message, $type);
     }
 }
Exemple #3
0
 public function deliver(&$Mailer, $settings = array())
 {
     $encoded_message = $Mailer->getRawMessage();
     $settings['ActionMailer']->deliveries[] = $encoded_message;
     if (AK_DEV_MODE) {
         $Logger = Ak::getLogger('mail');
         $Logger->message($encoded_message);
     }
 }
Exemple #4
0
 /**
  * @param array $database_settings
  */
 function __construct($database_settings, $auto_connect = false)
 {
     $this->settings = $database_settings;
     if ($auto_connect){
         $this->connect();
     }
     if (AK_LOG_EVENTS){
         $this->logger =& Ak::getLogger();
     }
 }
Exemple #5
0
 public function &recognize($Map = null)
 {
     $this->_startSession();
     $this->_enableInternationalizationSupport();
     $this->mapRoutes($Map);
     $params = $this->getParams();
     $module_path = $module_class_peffix = '';
     if (!empty($params['module'])) {
         $module_path = trim(str_replace(array('/', '\\'), DS, Ak::sanitize_include($params['module'], 'high')), DS) . DS;
         $module_shared_model = AkConfig::getDir('controllers') . DS . trim($module_path, DS) . '_controller.php';
         $module_class_peffix = str_replace(' ', '_', AkInflector::titleize(str_replace(DS, ' ', trim($module_path, DS)))) . '_';
     }
     $controller_file_name = AkInflector::underscore($params['controller']) . '_controller.php';
     $controller_class_name = $module_class_peffix . AkInflector::camelize($params['controller']) . 'Controller';
     $controller_path = AkConfig::getDir('controllers') . DS . $module_path . $controller_file_name;
     if (!empty($module_path) && file_exists($module_shared_model)) {
         include_once $module_shared_model;
     }
     if (!is_file($controller_path) || !(include_once $controller_path)) {
         AK_LOG_EVENTS && Ak::getLogger()->error('Controller ' . $controller_path . ' not found.');
         if (AK_ENVIRONMENT == 'development') {
             trigger_error(Ak::t('Could not find the file /app/controllers/<i>%controller_file_name</i> for ' . 'the controller %controller_class_name', array('%controller_file_name' => $controller_file_name, '%controller_class_name' => $controller_class_name)), E_USER_ERROR);
         } elseif (@(include AkConfig::getDir('public') . DS . '404.php')) {
             $response = new AkTestResponse();
             $response->addHeader('Status', 404);
             return false;
             //exit;
         } else {
             //header("HTTP/1.1 404 Not Found");
             $response = new AkResponse();
             $response->addHeader('Status', 404);
             return false;
             //die('404 Not found');
         }
     }
     if (!class_exists($controller_class_name)) {
         AK_LOG_EVENTS && Ak::getLogger()->error('Controller ' . $controller_path . ' does not implement ' . $controller_class_name . ' class.');
         if (AK_ENVIRONMENT == 'development') {
             trigger_error(Ak::t('Controller <i>%controller_name</i> does not exist', array('%controller_name' => $controller_class_name)), E_USER_ERROR);
         } elseif (@(include AkConfig::getDir('public') . DS . '405.php')) {
             exit;
         } else {
             $response = new AkResponse();
             $response->addHeader('Status', 405);
             return false;
             //header("HTTP/1.1 405 Method Not Allowed");
             //die('405 Method Not Allowed');
         }
     }
     $Controller = new $controller_class_name(array('controller' => true));
     $Controller->setModulePath($module_path);
     isset($_SESSION) ? $Controller->session =& $_SESSION : null;
     return $Controller;
 }
Exemple #6
0
 public function deliver(&$Mailer, $settings = array())
 {
     $encoded_message = $Mailer->getRawMessage();
     $settings['ActionMailer']->deliveries[] = $encoded_message;
     if (!AK_PRODUCTION_MODE) {
         $Logger = Ak::getLogger('mail');
         $Logger->message($encoded_message);
     }
     if (AK_TEST_MODE) {
         Ak::setStaticVar('last_mail_delivered', $encoded_message);
     }
 }
 public function logError($Exception)
 {
     if (!($Logger = Ak::getLogger())) {
         return;
     }
     $message = $Exception->getMessage() . "\n" . $Exception->getTraceAsString();
     $original_faltal_setting = AkConfig::getOption('logger.exit_on_fatal', true);
     $original_display_setting = AkConfig::getOption('logger.display_message', true);
     $original_mail_setting = AkConfig::getOption('logger.send_mails', true);
     AkConfig::setOption('logger.exit_on_fatal', false);
     AkConfig::setOption('logger.display_message', false);
     AkConfig::setOption('logger.send_mails', false);
     $Logger->fatal("\n" . get_class($Exception) . (empty($message) ? '' : ': (' . $message . ")") . "\n  ");
     AkConfig::setOption('logger.exit_on_fatal', $original_faltal_setting);
     AkConfig::setOption('logger.display_message', $original_display_setting);
     AkConfig::setOption('logger.send_mails', $original_mail_setting);
 }
Exemple #8
0
 function _raiseError($error)
 {
     if (AK_LOG_EVENTS) {
         empty($this->_Logger) && ($this->_Logger =& Ak::getLogger());
         $this->_Logger->error($error);
     }
     if (AK_ENVIRONMENT == 'development') {
         header('HTTP/1.1 404 Not Found');
         trigger_error($error, E_USER_ERROR);
     } elseif (@(include AK_PUBLIC_DIR . DS . '404.php')) {
         exit;
     } else {
         header('HTTP/1.1 404 Not Found');
         die('404 Not Found');
     }
 }
Exemple #9
0
 public function runTaskFiles($task_name, $options = array())
 {
     $files = $this->_getTaskFiles($task_name);
     $task_name = str_replace(':', DS, $task_name);
     $Makelos = $this;
     $Logger = Ak::getLogger('makelos' . DS . AkInflector::underscore($task_name));
     foreach ($files as $file) {
         $pathinfo = pathinfo($file);
         if (isset($pathinfo['extension']) && $pathinfo['extension'] == 'php') {
             include $file;
         } else {
             echo `{$file}`;
         }
     }
 }
Exemple #10
0
 protected function _log($message, $parameters = array(), $type = 'info')
 {
     if (AK_LOG_EVENTS) {
         if (empty($this->_Logger)) {
             $this->_Logger = Ak::getLogger();
         }
         $this->_Logger->{$type}($message, $parameters);
     }
 }
Exemple #11
0
 function &AkResponse()
 {
     $null = null;
     $AkResponse =& Ak::singleton('AkResponse', $null);
     AK_LOG_EVENTS && empty($AkResponse->_Logger) ? $AkResponse->_Logger =& Ak::getLogger() : null;
     return $AkResponse;
 }
Exemple #12
0
 function process(&$Request, &$Response)
 {
     AK_LOG_EVENTS && empty($this->_Logger) ? $this->_Logger =& Ak::getLogger() : null;
     $this->Request =& $Request;
     $this->Response =& $Response;
     $this->params = $this->Request->getParams();
     $this->_action_name = $this->Request->getAction();
     $this->_ensureActionExists();
     Ak::t('Akelos');
     // We need to get locales ready
     if ($this->_high_load_mode !== true) {
         if (!empty($this->_auto_instantiate_models)) {
             $this->instantiateIncludedModelClasses();
         }
         if (!empty($this->_enable_plugins)) {
             $this->loadPlugins();
         }
         if (!empty($this->helpers)) {
             $this->instantiateHelpers();
         }
     } else {
         $this->_enableLayoutOnRender = false;
     }
     $this->_ensureProperProtocol();
     // After filters
     $this->afterFilter('_handleFlashAttribute');
     $this->_loadActionView();
     if (isset($this->api)) {
         require_once AK_LIB_DIR . DS . 'AkActionWebService.php';
         $this->aroundFilter(new AkActionWebService($this));
     }
     $this->performActionWithFilters($this->_action_name);
     if (!$this->_hasPerformed()) {
         $this->_enableLayoutOnRender ? $this->renderWithLayout() : $this->renderWithoutLayout();
     }
     if (!empty($this->validate_output)) {
         $this->_validateGeneratedXhtml();
     }
     $this->Response->outputResults();
 }
Exemple #13
0
 function log($message)
 {
     if (AK_LOG_EVENTS){
         static $logger;
         if(empty($logger)) {
             $logger = &Ak::getLogger();
         }
         $logger->log('unit-test',$message);
     }
 }
Exemple #14
0
    function init($attributes = array())
    {
        AK_LOG_EVENTS ? ($this->Logger =& Ak::getLogger()) : null;
        $this->_internationalize = is_null($this->_internationalize) && AK_ACTIVE_RECORD_INTERNATIONALIZE_MODELS_BY_DEFAULT ? count($this->getAvailableLocales()) > 1 : $this->_internationalize;

        @$this->_instantiateDefaultObserver();

        $this->establishConnection();

        if(!empty($this->table_name)){
            $this->setTableName($this->table_name);
        }
        $load_acts = isset($attributes[1]['load_acts']) ? $attributes[1]['load_acts'] : (isset($attributes[0]['load_acts']) ? $attributes[0]['load_acts'] : true);
        $this->act_as = !empty($this->acts_as) ? $this->acts_as : (empty($this->act_as) ? false : $this->act_as);
        if (!empty($this->act_as) && $load_acts) {
            $this->_loadActAsBehaviours();
        }

        if(!empty($this->combined_attributes)){
            foreach ($this->combined_attributes as $combined_attribute){
                $this->addCombinedAttributeConfiguration($combined_attribute);
            }
        }

        if(isset($attributes[0]) && is_array($attributes[0]) && count($attributes) === 1){
            $attributes = $attributes[0];
            $this->_newRecord = true;
        }

        // new AkActiveRecord(23); //Returns object with primary key 23
        if(isset($attributes[0]) && count($attributes) === 1 && $attributes[0] > 0){
            $record = $this->find($attributes[0]);
            if(!$record){
                return false;
            }else {
                $this->setAttributes($record->getAttributes(), true);
            }
            // This option is only used internally for loading found objects
        }elseif(isset($attributes[0]) && isset($attributes[1]) && $attributes[0] == 'attributes' && is_array($attributes[1])){
            foreach(array_keys($attributes[1]) as $k){
                $attributes[1][$k] = $this->castAttributeFromDatabase($k, $attributes[1][$k]);
            }

            $avoid_loading_associations = isset($attributes[1]['load_associations']) ? false : !empty($this->disableAutomatedAssociationLoading);
            $this->setAttributes($attributes[1], true);
        }else{
            $this->newRecord($attributes);
        }

        if($this->_dynamicMethods){
            $this->_buildFinders();
        }
        empty($avoid_loading_associations) ? $this->loadAssociations() : null;

    }
Exemple #15
0
 public function reportError($options = array())
 {
     if (AK_LOG_EVENTS && !empty($options['log'])) {
         Ak::getLogger()->error($options['log']);
     }
     if (AK_DEV_MODE && !empty($options['message'])) {
         trigger_error($options['message'], E_USER_ERROR);
     } else {
         $status_code = intval(empty($options['status_code']) ? 501 : $options['status_code']);
         $status_header = AkResponse::getStatusHeader($status_code);
         if (!@(include AkConfig::getDir('public') . DS . $status_code . '.php')) {
             @Ak::header($status_header);
             echo str_replace('HTTP/1.1 ', '', $status_header);
         }
     }
     exit(0);
 }
Exemple #16
0
 public function runTaskFiles($task_name, $options = array())
 {
     $task_name = str_replace(':', DS, $task_name);
     $Makelos = $this;
     $Logger = Ak::getLogger('makelos'.DS.AkInflector::underscore($task_name));
     foreach (glob(AK_TASKS_DIR.DS.$task_name.'*.task.*') as $file){
         $pathinfo = @pathinfo($file);
         if(@$pathinfo['extension'] == 'php'){
             include($file);
         }else{
             echo `$file`;
         }
     }
 }
Exemple #17
0
 public function _config($key = null, $value = null, $environment = AK_ENVIRONMENT, $unset = false)
 {
     if (AkDbSchemaCache::shouldRefresh()) {
         return false;
     }
     static $config;
     if (!isset($config[$environment])) {
         $file_name = AkDbSchemaCache::getCacheFileName($environment);
         $config[$environment] = file_exists($file_name) ? unserialize(Ak::file_get_contents($file_name)) : array();
         if (AK_LOG_EVENTS) {
             $Logger =& Ak::getLogger();
             $Logger->message('Loading cached database settings');
         }
     }
     if (!is_null($key)) {
         if (!is_null($value)) {
             $config[$environment][$key] = $value;
         } elseif ($unset) {
             unset($config[$environment][$key]);
         }
         return isset($config[$environment][$key]) ? $config[$environment][$key] : false;
     }
     return $config[$environment];
 }
Exemple #18
0
 function checkForRoutedRequests(&$Router)
 {
     $ak_request = isset($this->_request['ak']) ? str_replace('//', '/', '/' . trim($this->_request['ak'], '/') . '/') : '/';
     if ($this->_route_params = $Router->toParams($ak_request)) {
         if (!isset($this->_route_params['controller'])) {
             trigger_error(Ak::t('No controller was specified.'), E_USER_WARNING);
         }
         if (!isset($this->_route_params['action'])) {
             trigger_error(Ak::t('No action was specified.'), E_USER_WARNING);
         }
         if (isset($this->_route_params['controller'])) {
             if ($this->_addParam('controller', $this->_route_params['controller'])) {
                 $this->controller = $this->_request['controller'] = $this->_route_params['controller'];
             }
         }
         if (isset($this->_route_params['action'])) {
             if ($this->_addParam('action', $this->_route_params['action'])) {
                 $this->action = $this->_request['action'] = $this->_route_params['action'];
             }
         }
         if (isset($this->_route_params['module'])) {
             if ($this->_addParam('module', $this->_route_params['module'])) {
                 $this->module = $this->_request['module'] = $this->_route_params['module'];
             }
         }
         foreach ($this->_route_params as $k => $v) {
             if ($this->_addParam($k, $v)) {
                 $this->_request[$k] = $v;
             }
         }
     }
     if (defined('AK_LOG_EVENTS') && AK_LOG_EVENTS) {
         $this->Logger =& Ak::getLogger();
         $this->Logger->message($this->Logger->formatText('Request', 'green') . ' from ' . $this->getRemoteIp(), $this->getParams());
     }
 }
Exemple #19
0
    function process(&$Request, &$Response)
    {
        AK_ENABLE_PROFILER &&  Ak::profile('AkActionController::process() start');
        AK_LOG_EVENTS && empty($this->_Logger) ? ($this->_Logger =& Ak::getLogger()) : null;

        $this->Request =& $Request;
        $this->Response =& $Response;
        $this->params = $this->Request->getParams();
        AK_ENABLE_PROFILER &&  Ak::profile('Got request paramenters');

        $this->_action_name = $this->Request->getAction();

        $actionExists = $this->_ensureActionExists();

        if (!$actionExists) {
            $this->handleResponse();
            return false;
        }

        Ak::t('Akelos'); // We need to get locales ready
        AK_ENABLE_PROFILER &&  Ak::profile('Got multilingual ');


        if($this->_high_load_mode !== true){
            if(!empty($this->_auto_instantiate_models)){
                $this->instantiateIncludedModelClasses();
                AK_ENABLE_PROFILER &&  Ak::profile('Instantiated models');
            }
            if(!empty($this->_enable_plugins)){
                $this->loadPlugins();
                AK_ENABLE_PROFILER &&  Ak::profile('Instantiated plugins');
            }
            if(!empty($this->helpers)){
                $this->instantiateHelpers();
                AK_ENABLE_PROFILER &&  Ak::profile('Instantiated helpers');
            }
        }else{
            $this->_enableLayoutOnRender = false;
        }

        $this->_ensureProperProtocol();

        // After filters
        $this->afterFilter('_handleFlashAttribute');

        $this->_initExtensions();

        $this->_loadActionView();

        if(isset($this->api)){
            require_once(AK_LIB_DIR.DS.'AkActionWebService.php');
            $this->aroundFilter(new AkActionWebService($this));
        }

        $this->_identifyRequest();


        $this->performActionWithFilters($this->_action_name);


        $this->handleResponse();
    }
Exemple #20
0
 /**
  * Initialization method.
  * 
  * Initialization method. Use this via the class constructor.
  * 
  * @access public
  * @uses parseRequest
  * @return void 
  */
 function init()
 {
     if (!$this->_init_check) {
         $this->env =& $_SERVER;
         $this->_fixGpcMagic();
         $this->_urlDecode();
         $this->_mergeRequest();
         if (is_array($this->_request)) {
             foreach ($this->_request as $k => $v) {
                 $this->_addParam($k, $v);
             }
         }
         $this->_init_check = true;
     }
     if (defined('AK_LOG_EVENTS') && AK_LOG_EVENTS) {
         $this->Logger =& Ak::getLogger();
         $this->Logger->message($this->Logger->formatText('Request', 'green') . ' from ' . $this->getRemoteIp(), $this->getParams());
     }
 }
Exemple #21
0
    function process(&$Request, &$Response)
    {
        AK_LOG_EVENTS && empty($this->_Logger) ? ($this->_Logger =& Ak::getLogger()) : null;
        
        $this->Request =& $Request;
        $this->Response =& $Response;
        $this->params = $this->Request->getParams();
        $this->_action_name = $this->Request->getAction();
        
        if(!method_exists($this, $this->_action_name)){
            trigger_error(Ak::t('Controller <i>%controller_name</i> can\'t handle action %action_name',
            array(
            '%controller_name' => $this->getControllerName(),
            '%action_name' => $this->_action_name,
            )), E_USER_ERROR);
        }
        
        Ak::t('Akelos'); // We need to get locales ready
        
        if($this->_high_load_mode !== true){
            if(!empty($this->_auto_instantiate_models)){
                $this->instantiateIncludedModelClasses();
            }
            if(!empty($this->_enable_plugins)){
                $this->loadPlugins();
            }
            if(!empty($this->helpers)){
                $this->instantiateHelpers();
            }
        }else{
            $this->_enableLayoutOnRender = false;
        }
       
        $this->_ensureProperProtocol();
        
        // After filters
        $this->afterFilter('_handleFlashAttribute');
        
        if(!empty($this->validate_output)){
            $this->beforeFilter('_validateGeneratedXhtml');
        
        }
        
        $this->_loadActionView();
        
        if(isset($this->api)){
            require_once(AK_LIB_DIR.DS.'AkActionWebService.php');
            $this->aroundFilter(new AkActionWebService($this));
        }
        
        $this->performActionWithFilters($this->_action_name);
        
        if (!$this->_hasPerformed()){
            $this->_enableLayoutOnRender ? $this->renderWithLayout() : $this->renderWithoutLayout();
        }

        $this->Response->outputResults();
    }