public function log($message, $type = '', $identifyer = '') { if (AK_LOG_EVENTS) { $Logger =& Ak::getLogger(); $Logger->log($message, $type); } }
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; }
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'; }
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'); }
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')); } }
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)); } }
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')); }
function saveReport() { if ($this->report == '') { $this->renderReport(); } Ak::file_put_contents('profiler_results.txt', $this->report); }
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; }
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'); } } }
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')); } }
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); }
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'); }
public function test_start() { $this->installAndIncludeModels(array( 'Category'=>'id, parent_id, description, department string(25)' )); Ak::import('DependentCategory'); }
/** * @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; } } }
public function testLangHasAutomaticRequirements() { $this->get('/jp/person/martin')->doesntMatch(); foreach (Ak::langs() as $lang) { $this->get("/{$lang}/person")->matches(array('lang' => $lang)); } }
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"; } } }
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); }
function test_setup() { $this->uninstallAndInstallMigration('AdminPlugin'); Ak::import('extension'); $this->Extension =& new Extension(); $this->populateTables('extensions'); }
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'); }
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; } } }
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); }
public function getLocation($Location) { if (Ak::is_array($Location)) { return array_values($this->Location->collect($Location, 'id', 'name')); } else { return $Location->get('name'); } }
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; }
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')); } }
/** * Returns the escaped +html+ without affecting existing escaped entities. * * <%= escape_once "1 > 2 & 3" %> * # => "1 > 2 & 3" */ function escape_once($html) { static $charset; if (empty($charset)) { $charset = Ak::locale('charset'); } return TagHelper::_fix_double_escape(htmlentities($html, ENT_COMPAT, $charset)); }
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'); } }
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); } } }
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; }