Exemplo n.º 1
0
 public function log($message, $type = '', $identifyer = '')
 {
     if (AK_LOG_EVENTS) {
         $Logger =& Ak::getLogger();
         $Logger->log($message, $type);
     }
 }
Exemplo n.º 2
0
 function &updateClassDetails(&$File, &$Component, &$SourceAnalyzer)
 {
     Ak::import('method');
     $MethodInstance =& new Method();
     $parsed_details = $SourceAnalyzer->getParsedArray($File->body);
     $available_classes = empty($parsed_details['classes']) ? array() : array_keys($parsed_details['classes']);
     if (empty($available_classes)) {
         return $available_classes;
     }
     $Classes = array();
     foreach ($available_classes as $class_name) {
         $extends = !empty($parsed_details['classes'][$class_name]['extends']) ? $parsed_details['classes'][$class_name]['extends'] : false;
         if ($extends) {
             $SourceAnalyzer->log('Looking for parent class: ' . $extends);
             $ParentClass =& $this->_addOrUpdateClassDetails($extends, $File, $Component, $SourceAnalyzer, array(), true);
         }
         $Class =& $this->_addOrUpdateClassDetails($class_name, $File, $Component, $SourceAnalyzer, $parsed_details['classes'][$class_name]);
         if (!empty($ParentClass)) {
             $SourceAnalyzer->log('Setting ' . $extends . ' as the parent of ' . $class_name);
             $ParentClass->tree->addChild($Class);
             $ParentClass->save();
         }
         $Class->methods = array();
         if (!empty($parsed_details['classes'][$class_name]['methods'])) {
             foreach ($parsed_details['classes'][$class_name]['methods'] as $method_name => $method_details) {
                 $Class->methods[] =& $MethodInstance->updateMethodDetails($Class, $method_name, $method_details, $SourceAnalyzer);
             }
         }
         $Classes[] =& $Class;
     }
     return $Classes;
 }
Exemplo n.º 3
0
 function makeClassExtensible($class_name_to_extend)
 {
     list($checksum, $source) = $this->_getExtensionSourceAndChecksum($class_name_to_extend);
     $merge_path = AK_TMP_DIR . DS . '.lib';
     if ($source) {
         if (preg_match_all('/[ \\n\\t]*([a-z]+)[ \\n\\t]*extends[ \\n\\t]*(' . $class_name_to_extend . ')[ \\n\\t]*[ \\n\\t]*{/i', $source, $matches)) {
             $replacements = array();
             $extended_by = array();
             foreach ($matches[2] as $k => $class_to_extend) {
                 if (empty($last_method) && class_exists($class_to_extend)) {
                     $last_method = $class_to_extend;
                 }
                 if ($class_to_extend == $last_method || !empty($extended_by[$class_to_extend]) && in_array($last_method, $extended_by[$class_to_extend])) {
                     if (!class_exists($matches[1][$k])) {
                         $replacements[trim($matches[0][$k], "\n\t {")] = $matches[1][$k] . ' extends ' . $last_method;
                         $last_method = $matches[1][$k];
                         $extended_by[$class_to_extend][] = $last_method;
                     } else {
                         trigger_error(Ak::t('The class %class is already defined and can\'t be used for extending %parent_class', array('%class' => $matches[1][$k], '%parent_class' => $class_name_to_extend)), E_NOTICE);
                     }
                 }
             }
             $source = str_replace(array_keys($replacements), array_values($replacements), $source);
         }
         $source = "{$source}<?php class Extensible{$class_name_to_extend} extends {$last_method}{} ?>";
         if (md5($source) != @md5_file($merge_path . DS . 'Extensible' . $class_name_to_extend . '.php')) {
             AkFileSystem::file_put_contents($merge_path . DS . 'Extensible' . $class_name_to_extend . '.php', $source);
             AkFileSystem::file_put_contents($merge_path . DS . 'checksums' . DS . 'Extensible' . $class_name_to_extend, $checksum);
         }
     }
     include_once $merge_path . DS . 'Extensible' . $class_name_to_extend . '.php';
 }
Exemplo n.º 4
0
    public function test_should_fill_the_table_with_yaml_data()
    {
        $unit_tester = new AkUnitTest();
        $unit_tester->installAndIncludeModels(array('TheModel'=>'id,name'));
        $TheModel =& $unit_tester->TheModel;
        $TheModel->create(array('name'=>'eins'));
        $TheModel->create(array('name'=>'zwei'));
        $TheModel->create(array('name'=>'drei'));
        $TheModel->create(array('name'=>'vier'));
        $this->assertEqual($TheModel->count(),4);

        $this->assertTrue($AllRecords = $TheModel->find());
        $yaml = $TheModel->toYaml($AllRecords);
        $this->assertFalse(file_exists(AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.'the_models.yaml'));
        Ak::file_put_contents(AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.'the_models.yaml',$yaml);

        $unit_tester->installAndIncludeModels(array('TheModel'=>'id,name'));
        $this->assertFalse($TheModel->find());
        $this->assertEqual($TheModel->count(),0);

        $unit_tester->installAndIncludeModels(array('TheModel'=>'id,name'),array('populate'=>true));
        $this->assertEqual($TheModel->count(),4);
        unlink(AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.'the_models.yaml');

    }
Exemplo n.º 5
0
    function generate()
    {
        $this->_preloadPaths();

        $this->class_name = AkInflector::camelize($this->class_name);

        $files = array(
        'model'=>AkInflector::toModelFilename($this->class_name),
        'unit_test'=>AK_TEST_DIR.DS.'unit'.DS.'app'.DS.'models'.DS.$this->underscored_model_name.'.php',
        'model_fixture.tpl'=>AK_TEST_DIR.DS.'fixtures'.DS.$this->model_path,
        'installer_fixture.tpl'=>AK_TEST_DIR.DS.'fixtures'.DS.$this->installer_path
        );

        $this->_template_vars = (array)$this;

        foreach ($files as $template=>$file_path){
            $this->save($file_path, $this->render($template));
        }

        $installer_path = AK_APP_DIR.DS.'installers'.DS.$this->underscored_model_name.'_installer.php';
        if(!file_exists($installer_path)){
            $this->save($installer_path, $this->render('installer'));
        }

        $unit_test_runner = AK_TEST_DIR.DS.'unit.php';
        if(!file_exists($unit_test_runner)){
            Ak::file_put_contents($unit_test_runner, file_get_contents(AK_FRAMEWORK_DIR.DS.'test'.DS.'app.php'));
        }

    }
Exemplo n.º 6
0
 function _run_from_file($file_name, $all_in_one_test = true)
 {
     $multiple_expected_php = $multiple_sintags = '';
     $tests = explode('===================================', file_get_contents(AK_TEST_DIR . DS . 'fixtures' . DS . 'data' . DS . $file_name));
     foreach ($tests as $test) {
         list($sintags, $php) = explode('-----------------------------------', $test);
         $sintags = trim($sintags);
         $expected_php = trim($php);
         if (empty($sintags)) {
             break;
         } else {
             $multiple_sintags .= $sintags;
             $multiple_expected_php .= $expected_php;
         }
         $AkSintags =& new AkSintagsParser();
         $php = $AkSintags->parse($sintags);
         if ($php != $expected_php) {
             Ak::trace("GENERATED: \n" . $php);
             Ak::trace("EXPECTED: \n" . $expected_php);
             Ak::trace("SINTAGS: \n" . $sintags);
         }
         $this->assertEqual($php, $expected_php);
     }
     if ($all_in_one_test) {
         $AkSintags =& new AkSintagsParser();
         $php = $AkSintags->parse($multiple_sintags);
         if ($php != $multiple_expected_php) {
             Ak::trace("GENERATED: \n" . $php);
             Ak::trace("EXPECTED: \n" . $expected_php);
             Ak::trace("SINTAGS: \n" . $sintags);
         }
         $this->assertEqual($php, $multiple_expected_php);
     }
 }
    function test_should_establish_multiple_connections()
    {
        if(AK_PHP5){
            $db_settings = Ak::convert('yaml', 'array', AK_CONFIG_DIR.DS.'database.yml');
            $db_settings['sqlite_databases'] = array(
                    'database_file' => AK_TMP_DIR.DS.'testing_sqlite_database.sqlite',
                    'type' => 'sqlite'
                    );
            file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings));
        
       
            $this->installAndIncludeModels(array('TestOtherConnection'));

            Ak::import('test_other_connection');
            $OtherConnection = new TestOtherConnection(array('name'=>'Delia'));
            $this->assertTrue($OtherConnection->save());
        
        
            $this->installAndIncludeModels(array('DummyModel'=>'id,name'));
            $Dummy = new DummyModel();
        
            $this->assertNotEqual($Dummy->getConnection(), $OtherConnection->getConnection());
        
            unset($db_settings['sqlite_databases']);
            file_put_contents(AK_CONFIG_DIR.DS.'database.yml', Ak::convert('array', 'yaml', $db_settings));
        }
    }
Exemplo n.º 8
0
 function test_should_update_plugin()
 {
     Ak::directory_delete(AK_PLUGINS_DIR.DS.'acts_as_versioned'.DS.'lib');
     $this->assertFalse(file_exists(AK_PLUGINS_DIR.DS.'acts_as_versioned'.DS.'lib'.DS.'ActsAsVersioned.php'));
     $this->PluginManager->updatePlugin('acts_as_versioned');
     $this->assertTrue(file_exists(AK_PLUGINS_DIR.DS.'acts_as_versioned'.DS.'lib'.DS.'ActsAsVersioned.php'));
 }
Exemplo n.º 9
0
 function saveReport()
 {
     if ($this->report == '') {
         $this->renderReport();
     }
     Ak::file_put_contents('profiler_results.txt', $this->report);
 }
Exemplo n.º 10
0
 private function _getModelAttributesForViews()
 {
     $attributes = array();
     $ModelInstance = Ak::get($this->class_name);
     if ($ModelInstance instanceof $this->class_name) {
         $table_name = $ModelInstance->getTableName();
         if (!empty($table_name)) {
             $attributes = $ModelInstance->getContentColumns();
             unset($attributes['updated_at'], $attributes['updated_on'], $attributes['created_at'], $attributes['created_on']);
         }
         $internationalized_columns = $ModelInstance->getInternationalizedColumns();
         foreach ($internationalized_columns as $column_name => $languages) {
             foreach ($languages as $lang) {
                 $attributes[$column_name] = $attributes[$lang . '_' . $column_name];
                 $attributes[$column_name]['name'] = $column_name;
                 unset($attributes[$lang . '_' . $column_name]);
             }
         }
     }
     $helper_methods = array('string' => 'text_field', 'text' => 'text_area', 'date' => 'text_field', 'datetime' => 'text_field');
     foreach ($attributes as $k => $v) {
         $attributes[$k]['type'] = $helper_methods[$attributes[$k]['type']];
     }
     return $attributes;
 }
Exemplo n.º 11
0
 public function index()
 {
     $this->base_dir = AK_BASE_DIR;
     $this->akelos_dir = AK_FRAMEWORK_DIR;
     $this->tasks_dir = AK_TASKS_DIR;
     $this->has_configuration = file_exists(AkConfig::getDir('config') . DS . 'config.php');
     $this->has_routes = file_exists(AkConfig::getDir('config') . DS . 'routes.php');
     $this->has_database = file_exists(AkConfig::getDir('config') . DS . 'database.yml');
     $this->using_root_path = $this->Request->getPath() == '/';
     $this->new_install = !$this->has_configuration || !$this->has_routes || $this->using_root_path;
     $this->environment = AK_ENVIRONMENT;
     $this->memcached_on = AkMemcache::isServerUp();
     $this->constants = AkDebug::get_constants();
     $this->langs = Ak::langs();
     $this->database_settings = Ak::getSettings('database', false);
     $this->server_user = trim(AK_WIN ? `ECHO %USERNAME%` : `whoami`);
     $this->local_ips = AkConfig::getOption('local_ips', array('localhost', '127.0.0.1', '::1'));
     $paths = array(AK_APP_DIR . DS . 'locales');
     $this->invalid_permissions = array();
     foreach ($paths as $path) {
         if (is_dir($path) && !@file_put_contents($path . DS . '__test_file')) {
             $this->invalid_permissions[] = $path;
         } else {
             @unlink($path . DS . '__test_file');
         }
     }
 }
Exemplo n.º 12
0
    function generate()
    {
        $this->_preloadPaths();

        $this->class_name = AkInflector::camelize($this->class_name);

        $files = array(
        'mailer'=>AkInflector::toModelFilename($this->class_name),
        'unit_test'=>AK_TEST_DIR.DS.'unit'.DS.'app'.DS.'models'.DS.$this->underscored_class_name.'.php'
        );

        foreach ($files as $template=>$file_path){
            $this->save($file_path, $this->render($template));
        }

        $mailer_views_folder = AK_VIEWS_DIR.DS.AkInflector::underscore($this->class_name);
        @Ak::make_dir($mailer_views_folder);

        foreach ($this->actions as $action){
            $this->assignVarToTemplate('action', $action);
            $path = $mailer_views_folder.DS.$action.'.tpl';
            $this->assignVarToTemplate('path', $path);
            $this->save($path, $this->render('view'));
        }
    }
Exemplo n.º 13
0
 public function setImage($image_path)
 {
     $this->Image = new AkImage($image_path);
     $this->Image->transform('resize', array('size' => '24x24'));
     $this->_tmp_file = AK_TMP_DIR . DS . '__AkImageColorScheme_' . Ak::randomString(32) . '.jpg';
     $this->Image->save($this->_tmp_file);
 }
Exemplo n.º 14
0
 function setup()
 {
     $this->installAndIncludeModels(array('Post', 'Tag', 'Comment'));
     $Installer = new AkInstaller();
     @$Installer->dropTable('posts_tags');
     @Ak::file_delete(AK_MODELS_DIR.DS.'post_tag.php');
 }
Exemplo n.º 15
0
 public function test_start()
 {
     $this->installAndIncludeModels(array(
     'Category'=>'id, parent_id, description, department string(25)'
     ));
     Ak::import('DependentCategory');
 }
Exemplo n.º 16
0
 /**
  * @param int $errNo
  * @param string $errMsg
  * @param string $file
  * @param int $line
  * @return void
  * @access public
  */
 function raiseError($errNo, $errMsg, $file, $line)
 {
     if (!($errNo & error_reporting())) {
         return;
     }
     while (ob_get_level()) {
         ob_end_clean();
     }
     //echo nl2br(print_r(get_defined_vars(),true)).'<hr />';
     if (!($errNo & error_reporting())) {
         return;
     }
     while (ob_get_level()) {
         ob_end_clean();
     }
     $errType = array(1 => "Php Error", 2 => "Php Warning", 4 => "Parsing Error", 8 => "Php Notice", 16 => "Core Error", 32 => "Core Warning", 64 => "Compile Error", 128 => "Compile Warning", 256 => "Php User Error", 512 => "Php User Warning", 1024 => "Php User Notice");
     if (substr($errMsg, 0, 9) == 'database|') {
         die('Database connection error');
         header('Location: ' . AK_URL . Ak::tourl(array('controller' => 'error', 'action' => 'database')));
         exit;
     }
     $info = array();
     if ($errNo & E_USER_ERROR && is_array($arr = @unserialize($errMsg))) {
         foreach ($arr as $k => $v) {
             $info[$k] = $v;
         }
     }
 }
Exemplo n.º 17
0
 public function testLangHasAutomaticRequirements()
 {
     $this->get('/jp/person/martin')->doesntMatch();
     foreach (Ak::langs() as $lang) {
         $this->get("/{$lang}/person")->matches(array('lang' => $lang));
     }
 }
Exemplo n.º 18
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";
         }
     }
 }
Exemplo n.º 19
0
    function up_1()
    {
        $new_code = '
    private function __call ($method, $args)
    {
        if(substr($method,0,4) == \'find\'){
            $finder = substr(AkInflector::underscore($method), 5);
            list($type, $columns) = explode(\'by_\', $finder);
            $callback = strstr($type,\'create\') ?  \'findOrCreateBy\' : (strstr($type,\'first\') || !strstr($type,\'all\') ? \'findFirstBy\' : \'findAllBy\');
            $columns = strstr($columns, \'_and_\') ? explode(\'_and_\', $columns) : array($columns);
            array_unshift($args, join(\' AND \', $columns));
            return Ak::call_user_func_array(array(&$this,$callback), $args);
        }

        $backtrace = debug_backtrace();
        trigger_error(\'Call to undefined method \'.__CLASS__.\'::\'.$method.\'() in <b>\'.$backtrace[1][\'file\'].\'</b> on line <b>\'.$backtrace[1][\'line\'].\'</b> reported \', E_USER_ERROR);
    }

';
        $original_class = Ak::file_get_contents(AK_APP_DIR.DS.'shared_model.php');
        if(strstr($original_class, '__call')){
            trigger_error('You seem to have a __call method on your shared model. This plugin can\'t be installed as it will conflict with your existing code.', E_USER_ERROR);
        }

        $modified_class = preg_replace('/ActiveRecord[ \n\t]*extends[ \n\t]*AkActiveRecord[ \n\t]*[ \n\t]*{/i', "ActiveRecord extends AkActiveRecord \n{\n\n$new_code", $original_class);

        Ak::file_put_contents(AK_APP_DIR.DS.'shared_model.php', $modified_class);
    }
Exemplo n.º 20
0
 function test_setup()
 {
     $this->uninstallAndInstallMigration('AdminPlugin');
     Ak::import('extension');
     $this->Extension =& new Extension();
     $this->populateTables('extensions');
 }
Exemplo n.º 21
0
 public function setUp()
 {
     $cache_settings = Ak::getSettings('caching', false);
     $cache_settings['handler']['type'] = 3;
     $this->memcache = AkCache::lookupStore($cache_settings);
     $this->assertIsA($this->memcache, 'AkCache');
 }
Exemplo n.º 22
0
 public function getClasses($options = null)
 {
     if ($options == null) {
         return $this->classes;
     } else {
         if (is_array($options)) {
             $default_options = array();
             $available_options = array('visibility', 'tags');
             $parameters = array('available_options' => $available_options);
             Ak::parseOptions($options, $default_options, $parameters);
             $returnClasses = array();
             foreach ($this->classes as $class) {
                 if (isset($options['visibility']) && $class->getVisibility() != $options['visibility']) {
                     continue;
                 }
                 if (isset($options['tags'])) {
                     $options['tags'] = !is_array($options['tags']) ? array($options['tags']) : $options['tags'];
                     $docBlock = $method->getDocBlock();
                     foreach ($options['tags'] as $tag) {
                         if ($docBlock->getTag($tag) == false) {
                             continue;
                         }
                     }
                 }
                 $returnClasses[] = $class;
             }
             return $returnClasses;
         }
     }
 }
Exemplo n.º 23
0
    public function _encodeAddress($address_string, $header_name = '', $names = true)
    {
        $headers = '';
        $addresses = Ak::toArray($address_string);
        $addresses = array_map('trim', $addresses);
        foreach ($addresses as $address){
            $address_description = '';
            if(preg_match('#(.*?)<(.*?)>#', $address, $matches)){
                $address_description = trim($matches[1]);
                $address = $matches[2];
            }

            if(empty($address) || !$this->_isAscii($address) || !$this->_isValidAddress($address)){
                continue;
            }
            if($names && !empty($address_description)){
                $address = "<$address>";
                if(!$this->_isAscii($address_description)){
                    $address_description = '=?'.AK_ACTION_MAILER_DEFAULT_CHARSET.'?Q?'.$this->quoted_printable_encode($address_description, 0).'?=';
                }
            }
            $headers .= (!empty($headers)?','.AK_MAIL_HEADER_EOL.' ':'').$address_description.$address;
        }

        return empty($headers) ? false : (!empty($header_name) ? $header_name.': '.$headers.AK_MAIL_HEADER_EOL : $headers);
    }
Exemplo n.º 24
0
 public function getLocation($Location)
 {
     if (Ak::is_array($Location)) {
         return array_values($this->Location->collect($Location, 'id', 'name'));
     } else {
         return $Location->get('name');
     }
 }
Exemplo n.º 25
0
 function log_memory($reset = false, $vervose = false)
 {
     ($reset || empty($this->initial)) && ($this->initial = memory_get_usage());
     $this->current = memory_get_usage();
     $this->difference = $this->current - $this->initial;
     $this->difference && $vervose && Ak::trace($this->difference / 1048576 . ' MB increased');
     return $this->difference;
 }
Exemplo n.º 26
0
 function _protectAction()
 {
     $protected_actions = Ak::toArray($this->protected_actions);
     $action_name = $this->getActionName();
     if (in_array($action_name, $protected_actions) && !$this->CurrentUser->can($action_name . ' action', 'Admin::' . $this->getControllerName())) {
         $this->redirectTo(array('action' => 'protected_action'));
     }
 }
Exemplo n.º 27
0
 /**
  * Returns the escaped +html+ without affecting existing escaped entities.
  *
  *  <%= escape_once "1 > 2 &amp; 3" %>
  *    # => "1 &gt; 2 &amp; 3"
  */
 function escape_once($html)
 {
     static $charset;
     if (empty($charset)) {
         $charset = Ak::locale('charset');
     }
     return TagHelper::_fix_double_escape(htmlentities($html, ENT_COMPAT, $charset));
 }
Exemplo n.º 28
0
 function _addOrEditRole($action)
 {
     $this->role->setAttributes(Ak::pick('name,description,is_enabled', $this->params['role']));
     if ($this->role->save()){
         $this->flash_options = array('seconds_to_close' => 10);
         $this->flash['notice'] = $this->t('Role was successfully '.($action=='add'?'created':'updated'.'.'));
         $this->redirectToAction('listing');
     }
 }
Exemplo n.º 29
0
 function _linkWebServiceApis()
 {
     if (!empty($this->web_service_api)) {
         $this->web_service_api = Ak::toArray($this->web_service_api);
         foreach ($this->web_service_api as $api) {
             $this->_linkWebServiceApi($api);
         }
     }
 }
Exemplo n.º 30
0
 public function hasCollisions()
 {
     $this->collisions = array();
     $this->destination_path = rtrim($this->destination_path, DS);
     if (is_dir($this->destination_path)) {
         $this->collisions[] = Ak::t('%path already exists', array('%path' => $this->destination_path));
     }
     return count($this->collisions) > 0;
 }