function handle() { $this->__ParentController->params = $this->__ParentController->Request->getParams(); $this->_file_name = AkInflector::underscore($this->__ParentController->params['controller']) . '_controller.php'; $this->_class_name = AkInflector::camelize($this->__ParentController->params['controller']) . 'Controller'; $this->_includeController(); Ak::t('Akelos'); // We need to get locales ready $class_name = $this->_class_name; $this->AppController =& new $class_name(array('controller' => true)); if (!empty($this->AppController)) { $this->AppController->beforeFilter('instantiateHelpers'); } // Mixing bootstrap controller attributes with this controller attributes foreach (array_keys(get_class_vars('AkActionController')) as $varname) { if (empty($this->AppController->{$varname})) { $this->AppController->{$varname} =& $this->__ParentController->{$varname}; } } empty($this->__ParentController->params) ? $this->__ParentController->params = $this->__ParentController->Request->getParams() : null; $action_name = $this->_getActionName(); $this->_before($this->AppController); $this->AppController->performActionWithFilters($action_name); $this->_after($this->AppController); $this->AppController->Response->outputResults(); }
function cast() { $this->model_name = AkInflector::camelize($this->model_name); $this->model_file_path = AkInflector::toModelFilename($this->model_name); $this->controller_name = empty($this->controller_name) ? $this->model_name : (AkInflector::camelize($this->controller_name)); $this->controller_file_path = AkInflector::toControllerFilename($this->controller_name); $this->controller_class_name = $this->controller_name.'Controller'; $this->controller_human_name = AkInflector::humanize($this->controller_name); $this->helper_var_name = '$'.AkInflector::underscore($this->controller_name).'_helper'; $this->singular_name = AkInflector::underscore($this->model_name); $this->plural_name = AkInflector::pluralize($this->singular_name); $this->singular_controller_name = AkInflector::underscore($this->controller_name); $this->files = array( 'controller.php' => $this->controller_file_path, /** * @todo Implement generic functional tests */ // 'functional_test.php' => AK_TEST_DIR.DS.'functional'.DS.'test_'.$this->controller_class_name.'.php', 'helper.php' => AK_HELPERS_DIR.DS.trim($this->helper_var_name,'$').'.php', 'layout' => AK_VIEWS_DIR.DS.'layouts'.DS.$this->singular_controller_name.'.tpl', 'view_add' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'add.tpl', 'view_destroy' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'destroy.tpl', 'view_edit' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'edit.tpl', 'view_listing' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'listing.tpl', 'view_show' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'show.tpl', 'form' => AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.'_form.tpl', ); $this->user_actions = array(); foreach ((array)@$this->actions as $action){ $this->user_actions[$action] = AK_VIEWS_DIR.DS.$this->singular_controller_name.DS.$action.'.tpl'; } }
function runCommand($command) { $commands = $this->getOptionsFromCommand($command); $generator_name = isset($commands['generator']) ? $commands['generator'] : array_shift($commands); if (empty($generator_name)) { echo "\n " . Ak::t("You must supply a valid generator as the first command.\n\n Available generator are:"); echo "\n\n " . join("\n ", $this->_getAvailableGenerators()) . "\n\n"; AK_CONSOLE_MODE ? null : exit; return; } if (count(array_diff($commands, array('help', '-help', 'usage', '-usage', 'h', '-h', 'USAGE', '-USAGE'))) != count($commands) || count($commands) == 0) { $usage = method_exists($this, 'banner') ? $this->banner() : @Ak::file_get_contents(AK_SCRIPT_DIR . DS . 'generators' . DS . $generator_name . DS . 'USAGE'); echo empty($usage) ? "\n" . Ak::t('Could not locate usage file for this generator') : "\n" . $usage . "\n"; return; } if (file_exists(AK_SCRIPT_DIR . DS . 'generators' . DS . $generator_name . DS . $generator_name . '_generator.php')) { include_once AK_SCRIPT_DIR . DS . 'generators' . DS . $generator_name . DS . $generator_name . '_generator.php'; $generator_class_name = AkInflector::camelize($generator_name . '_generator'); $generator = new $generator_class_name(); $generator->type = $generator_name; $generator->_identifyUnnamedCommands($commands); $generator->_assignVars($commands); $generator->cast(); $generator->_generate(); } else { echo "\n" . Ak::t('Could not find %generator_name generator', array('%generator_name' => $generator_name)) . "\n"; } }
public function createController($controller_name) { $controller_class_name = AkInflector::camelize($controller_name) . 'Controller'; $this->Controller = $this->partialMock($controller_class_name, $this->getMethodsToMockForController()); #$this->Controller->Template = $this->getMock('AkActionView'); return $this->Controller; }
function runCommand($command) { $commands = $this->getOptionsFromCommand($command); $generator_name = AkInflector::underscore(isset($commands['generator']) ? $commands['generator'] : array_shift($commands)); $available_generators = $this->_getAvailableGenerators(); $generator_file_name = array_shift(array_keys($available_generators, $generator_name)); if (empty($generator_file_name)) { echo "\n " . Ak::t("You must supply a valid generator as the first command.\n\n Available generator are:"); echo "\n\n " . join("\n ", $available_generators) . "\n\n"; defined('AK_CONSOLE_MODE') && AK_CONSOLE_MODE ? null : exit; return; } if (include_once $generator_file_name) { $generator_class_name = AkInflector::camelize($generator_name . '_generator'); $generator = new $generator_class_name(); $generator->_generator_base_path = dirname($generator_file_name); if (count(array_diff($commands, array('help', '-help', 'usage', '-usage', 'h', '-h', 'USAGE', '-USAGE'))) != count($commands) || count($commands) == 0) { if (empty($generator->command_values) && empty($commands)) { // generator without commands } else { $generator->banner(); return; } } $generator->type = $generator_name; $generator->_identifyUnnamedCommands($commands); $generator->_assignVars($commands); $generator->cast(); $generator->_generate(); } else { echo "\n" . Ak::t('Could not find %generator_name generator', array('%generator_name' => $generator_name)) . "\n"; } }
function _preloadPaths() { $this->class_name = AkInflector::camelize(preg_replace('/_?controller$/i', '', $this->class_name)); $this->assignVarToTemplate('class_name', $this->class_name); $this->underscored_controller_name = AkInflector::underscore($this->class_name); $this->controller_path = 'controllers' . DS . $this->underscored_controller_name . '_controller.php'; }
function cast() { $this->model_name = AkInflector::camelize($this->model_name); $this->model_file_path = AkInflector::toModelFilename($this->model_name); if (empty($this->actions) && !empty($this->controller_name) && strstr($this->controller_name, ',')) { $this->controller_name = ''; } $this->controller_name = empty($this->controller_name) ? AkInflector::pluralize($this->model_name) : AkInflector::camelize($this->controller_name); $this->controller_file_path = AkInflector::toControllerFilename($this->controller_name); $this->controller_class_name = str_replace(array('/', '::'), '_', $this->controller_name . 'Controller'); $this->controller_name = AkInflector::demodulize($this->controller_name); $this->controller_human_name = AkInflector::humanize($this->controller_name); $this->helper_name = (AkInflector::is_plural($this->controller_name) ? AkInflector::singularize($this->controller_name) : $this->controller_name) . 'Helper'; $this->helper_var_name = '$' . AkInflector::underscore($this->helper_name); $this->singular_name = AkInflector::underscore($this->model_name); $this->plural_name = AkInflector::pluralize($this->singular_name); $this->singular_controller_name = AkInflector::underscore($this->controller_name); $this->module_preffix = AkInflector::underscore(substr($this->controller_class_name, 0, strrpos($this->controller_class_name, '_'))); $this->module_preffix = empty($this->module_preffix) ? '' : DS . $this->module_preffix; $this->files = array('controller.php' => $this->controller_file_path, 'helper.php' => AK_HELPERS_DIR . $this->module_preffix . DS . trim($this->helper_var_name, '$') . '.php', 'layout' => AK_VIEWS_DIR . DS . 'layouts' . DS . $this->singular_controller_name . '.tpl', 'view_add' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'add.tpl', 'view_destroy' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'destroy.tpl', 'view_edit' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'edit.tpl', 'view_listing' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'listing.tpl', 'view_show' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . 'show.tpl', 'form' => AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . '_form.tpl'); $this->user_actions = array(); foreach ((array) @$this->actions as $action) { $this->user_actions[$action] = AK_VIEWS_DIR . $this->module_preffix . DS . $this->singular_controller_name . DS . $action . '.tpl'; } }
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')); } }
function _preloadPaths() { if(!empty($this->class_name_arg)){ $this->class_name = $this->class_name_arg; } $this->class_name = $this->controller_name = $this->class_name_arg = str_replace('::', '/', AkInflector::camelize(preg_replace('/_?controller$/i','',$this->class_name))); $this->module_path = ''; // Controller inside module if(strstr($this->class_name_arg,'/')){ $module_parts = substr($this->class_name, 0, strrpos($this->class_name_arg, '/')); $this->module_path = join(DS, array_map(array('AkInflector','underscore'), strstr($module_parts, '/') ? explode('/', $module_parts) : array($module_parts))).DS; $this->controller_name = substr($this->class_name_arg, strrpos($this->class_name_arg, '/') + 1); $this->underscored_controller_name = $this->module_path.AkInflector::underscore($this->controller_name); $this->controller_path = 'controllers'.DS.$this->underscored_controller_name.'_controller.php'; $this->class_name = str_replace('/', '_', $this->class_name_arg); }else{ $this->underscored_controller_name = AkInflector::underscore($this->class_name); $this->controller_path = 'controllers'.DS.$this->underscored_controller_name.'_controller.php'; } $this->assignVarToTemplate('class_name', $this->class_name); }
public function generate() { $destination_path = AK_APP_LIB_DIR . DS . 'generators' . DS . $this->generator_name; $this->assignVarToTemplate('class_name', AkInflector::camelize($this->generator_name)); $this->save($destination_path . DS . $this->generator_name . '_generator.php', $this->render('generator')); $this->save($destination_path . DS . 'templates' . DS . 'template.tpl', $this->render('template')); $this->save($destination_path . DS . 'USAGE', $this->render('usage')); }
function Test_of_camelize() { foreach ($this->CamelToUnderscore as $camel => $underscore) { $this->assertEqual($camel, AkInflector::camelize($underscore)); } foreach ($this->CamelWithModuleToUnderscoreWithSlash as $camel => $underscore) { $this->assertEqual($camel, AkInflector::camelize($underscore)); } }
function &recognize($Map = null) { AK_ENVIRONMENT != 'setup' ? $this->_connectToDatabase() : 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 = AK_CONTROLLERS_DIR . 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 = AK_CONTROLLERS_DIR . DS . $module_path . $controller_file_name; include_once AK_APP_DIR . DS . 'application_controller.php'; if (!empty($module_path) && file_exists($module_shared_model)) { include_once $module_shared_model; } if (!is_file($controller_path) || !(include_once $controller_path)) { defined('AK_LOG_EVENTS') && AK_LOG_EVENTS && $this->Logger->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 AK_PUBLIC_DIR . 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)) { defined('AK_LOG_EVENTS') && AK_LOG_EVENTS && $this->Logger->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 AK_PUBLIC_DIR . 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->_module_path = $module_path; isset($_SESSION) ? $Controller->session =& $_SESSION : null; return $Controller; }
private function _instantiateAdapterClass($type, $settings = array()) { $class_name = strstr($type, 'Adapter') ? $type : 'AkOdb' . AkInflector::camelize($type) . 'Adapter'; if (!class_exists($class_name) && !$this->_includeAdapterClass($settings['type'])) { trigger_error(Ak::t('Could not find document adapter class %class', array('%class' => $class_name)), E_USER_ERROR); return false; } $this->_Adapter = new $class_name($settings); return true; }
public function __construct($client_driver) { $client_driver = AkInflector::underscore($client_driver); if (in_array($client_driver, $this->_available_drivers)) { $client_class_name = 'Ak' . AkInflector::camelize($client_driver) . 'Client'; require_once AK_ACTION_PACK_DIR . DS . 'action_web_service' . DS . 'clients' . DS . $client_driver . '.php'; $this->_Client = new $client_class_name($this); } else { trigger_error(Ak::t('Invalid Web Service driver provided. Available Drivers are: %drivers', array('%drivers' => join(', ', $this->_available_drivers))), E_USER_WARNING); } }
function _preloadPaths() { $this->api_name = AkInflector::camelize($this->api_name); $this->api_class_name = $this->api_name . 'Api'; $this->assignVarToTemplate('api_class_name', $this->api_class_name); $this->service_class_name = $this->api_name . 'Service'; $this->assignVarToTemplate('service_class_name', $this->service_class_name); $this->api_path = AK_APIS_DIR . DS . AkInflector::underscore($this->api_class_name) . '.php'; $this->underscored_service_name = AkInflector::underscore($this->api_name); $this->service_path = AK_MODELS_DIR . DS . $this->underscored_service_name . '_service.php'; }
public function _preloadPaths() { $this->api_name = AkInflector::camelize($this->api_name); $this->api_class_name = $this->api_name . 'Api'; $this->assignVarToTemplate('api_class_name', $this->api_class_name); $this->service_class_name = $this->api_name . 'Service'; $this->assignVarToTemplate('service_class_name', $this->service_class_name); $this->api_path = AkConfig::getDir('apis') . DS . AkInflector::underscore($this->api_class_name) . '.php'; $this->underscored_service_name = AkInflector::underscore($this->api_name); $this->service_path = AkConfig::getDir('models') . DS . $this->underscored_service_name . '_service.php'; }
public function _linkWebServiceApi($api) { $api_path = AkInflector::underscore($api); if (substr($api_path, -4) != '_api') { $api_name_space = $api_path; $api_path = $api_path . '_api'; } else { $api_name_space = substr($api_path, 0, -4); } $api_class_name = AkInflector::camelize($api_path); require_once AkConfig::getDir('apis') . DS . $api_path . '.php'; $this->_apis[$api_name_space] = new $api_class_name(); }
/** * @return TemplatePathsController */ function createControllerFor($action_name, $mime_type = 'html') { $controller_class_name = AkInflector::camelize($this->controller_name) . 'Controller'; $controller = new $controller_class_name(); $Request = $this->createGetRequest($action_name, $mime_type); $Response = $this->getMock('AkResponse', array('outputResults')); $controller->setRequestAndResponse($Request, $Response); $this->Template = $controller->Template = $this->getMock('AkActionView', array('renderFile'), array(AK_VIEWS_DIR . DS . $this->controller_name)); $this->Template->_registerTemplateHandler('tpl', 'AkPhpTemplateHandler'); $this->Template->_registerTemplateHandler('html.tpl', 'AkPhpTemplateHandler'); $this->action_name = $action_name; return $this->Controller = $controller; }
private function &_getTemplateEngineInstance() { static $TemplateEngineInstances = array(); if (!isset($TemplateEngineInstances[$this->_templateEngine])) { if (!class_exists($this->_templateEngine)) { require_once AK_ACTION_PACK_DIR . DS . 'template_engines' . DS . $this->_templateEngine . DS . 'base.php'; $template_engine_name = 'Ak' . AkInflector::camelize($this->_templateEngine); } else { $template_engine_name = $this->_templateEngine; } $TemplateEngineInstances[$this->_templateEngine] = new $template_engine_name(); } return $TemplateEngineInstances[$this->_templateEngine]; }
/** * @return TemplatePathsController */ public function createControllerFor($action_name, $mime_type = 'html') { $controller_class_name = AkInflector::camelize($this->controller_name) . 'Controller'; $controller = new $controller_class_name(); $Request = $this->createGetRequest($action_name, $mime_type); $Response = $this->mock('AkResponse', array('outputResults' => '')); $controller->setRequestAndResponse($Request, $Response); $controller->Template = new AkActionView($controller->_getTemplateBasePath(), array(), $controller); $controller->Template->registerTemplateHandler('tpl', 'AkPhpTemplateHandler'); //$this->Template->registerTemplateHandler('html.tpl','AkPhpTemplateHandler'); $this->Template = $controller->Template; $this->action_name = $action_name; return $this->Controller = $controller; }
function _linkWebServiceApi($api) { $api_path = AkInflector::underscore($api); if (substr($api_path, -4) != '_api') { $api_name_space = $api_path; $api_path = $api_path . '_api'; } else { $api_name_space = substr($api_path, 0, -4); } $api_class_name = AkInflector::camelize($api_path); require_once AK_LIB_DIR . DS . 'AkActionWebService' . DS . 'AkActionWebServiceApi.php'; require_once AK_APIS_DIR . DS . $api_path . '.php'; $this->_apis[$api_name_space] =& new $api_class_name(); }
protected function _installOrUninstallExtension($action = 'install') { if ($installer_path = $this->getInstallerPath()) { include_once $installer_path; $installer_class_name = AkInflector::camelize($this->get('name')) . 'ExtensionInstaller'; if (class_exists($installer_class_name)) { $Installer = new $installer_class_name(); if (method_exists($Installer, $action)) { $Installer->Extension = $this; return $Installer->{$action}(); } } } return true; }
function _setupCloner() { $this->clone_setup_done = true; $this->class_to_clone = AkInflector::underscore($this->class_to_clone); $this->class_name = AkInflector::underscore($this->class_name); $this->clone_replacements = array(AkInflector::camelize($this->class_to_clone) . 'Controller' => AkInflector::camelize($this->class_name) . 'Controller', AkInflector::humanize(AkInflector::pluralize($this->class_to_clone)) => AkInflector::humanize(AkInflector::pluralize($this->class_name)), AkInflector::titleize(AkInflector::pluralize($this->class_to_clone)) => AkInflector::titleize(AkInflector::pluralize($this->class_name)), AkInflector::humanize($this->class_to_clone) => AkInflector::humanize($this->class_name), AkInflector::titleize($this->class_to_clone) => AkInflector::titleize($this->class_name), AkInflector::camelize(AkInflector::pluralize($this->class_to_clone)) => AkInflector::camelize(AkInflector::pluralize($this->class_name)), AkInflector::pluralize($this->class_to_clone) => AkInflector::pluralize($this->class_name), AkInflector::camelize($this->class_to_clone) => AkInflector::camelize($this->class_name), $this->class_to_clone => $this->class_name); //AK_VIEWS_DIR.DS.AkInflector::underscore($this->class_name).DS.$action.'.tpl' $this->files_to_clone = array(AkInflector::toModelFilename($this->class_to_clone) => AkInflector::toModelFilename($this->class_name), AK_TEST_DIR . DS . 'unit' . DS . 'test_' . $this->class_to_clone . '.php' => AK_TEST_DIR . DS . 'unit' . DS . 'test_' . $this->class_name . '.php', AK_TEST_DIR . DS . 'fixtures' . DS . AkInflector::tableize($this->class_to_clone) . '.yml' => AK_TEST_DIR . DS . 'fixtures' . DS . AkInflector::tableize($this->class_name) . '.yml', AkInflector::toControllerFilename($this->class_to_clone) => AkInflector::toControllerFilename($this->class_name), AK_TEST_DIR . DS . 'functional' . DS . 'test_' . AkInflector::camelize($this->class_to_clone . '_controller') . '.php' => AK_TEST_DIR . DS . 'functional' . DS . 'test_' . AkInflector::camelize($this->class_name . '_controller') . '.php', AK_HELPERS_DIR . DS . AkInflector::underscore("{$this->class_to_clone}_helper") . '.php' => AK_HELPERS_DIR . DS . AkInflector::underscore("{$this->class_name}_helper") . '.php'); foreach ($this->_getControllerViews() as $view_file) { $this->files_to_clone[AK_VIEWS_DIR . DS . $this->class_to_clone . DS . $view_file . '.tpl'] = AK_VIEWS_DIR . DS . $this->class_name . DS . $view_file . '.tpl'; } $this->files_to_clone[AK_VIEWS_DIR . DS . 'layouts' . DS . $this->class_to_clone . '.tpl'] = AK_VIEWS_DIR . DS . 'layouts' . DS . $this->class_name . '.tpl'; foreach (Ak::dir(AK_APP_DIR . DS . 'locales' . DS . $this->class_to_clone, array('dirs' => false)) as $locale_file) { $this->files_to_clone[AK_APP_DIR . DS . 'locales' . DS . $this->class_to_clone . DS . $locale_file] = AK_APP_DIR . DS . 'locales' . DS . $this->class_name . DS . $locale_file; } }
function &addAssociated($association_id, $options = array()) { $default_options = array('class_name' => empty($options['class_name']) ? AkInflector::camelize($association_id) : $options['class_name'], 'foreign_key' => empty($options['foreign_key']) ? AkInflector::singularize($this->Owner->getTableName()) . '_id' : $options['foreign_key'], 'remote' => false, 'instantiate' => false, 'conditions' => false, 'include_conditions_when_included' => true, 'order' => false, 'include_order_when_included' => true, 'dependent' => false, 'counter_cache' => false); $options = array_merge($default_options, $options); $options['table_name'] = empty($options['table_name']) ? AkInflector::tableize($options['class_name']) : $options['table_name']; $this->setOptions($association_id, $options); $this->addModel($association_id, new AkAssociatedActiveRecord()); $associated =& $this->getModel($association_id); $this->setAssociatedId($association_id, $associated->getId()); $associated =& $this->_build($association_id, &$associated, false); $this->_saveLoadedHandler($association_id, $associated); if ($options['instantiate']) { $associated =& $this->addModel($association_id, new $options['class_name']($options['foreign_key'] . ' = ' . $this->Owner->quotedId())); } return $associated; }
public function removeExtensions($pluginIdentifier = null) { if ($pluginIdentifier == null) { $pluginIdentifier = AkInflector::camelize($this->plugin_name); } foreach ($this->extension_points as $targetClass => $baseFile) { $file = $this->app_app_dir . DS . $baseFile; $reflection = new AkReflectionFile($file); $classes = $reflection->getClasses(); foreach ($classes as $class) { $methods = $class->getMethods(array('tags' => array('Plugin' => $pluginIdentifier))); foreach ($methods as $method) { $this->_removeMethodFromClass($file, $method->getName(), $pluginIdentifier); } } } }
function addService($service) { $service_file = AkInflector::underscore($service); if (substr($service_file, -8) != '_service') { $service_file = $service_file . '_service'; } $service_model = AkInflector::camelize($service_file); $service_name_space = substr($service_file, 0, -8); if (empty($this->_services[$service_name_space])) { require_once AK_MODELS_DIR . DS . $service_file . '.php'; if (!class_exists($service_model)) { trigger_error(Ak::t('Could not find class for the service %service at %models_dir', array('%service' => $service_model, '%models_dir' => AK_MODELS_DIR), E_USER_ERROR)); return false; } $this->_services[$service_name_space] =& new $service_model(); } }
private function _setDefaults() { $this->class_name = AkInflector::camelize($this->class_name); $this->table_name = AkInflector::tableize($this->class_name); $this->file_name = AkInflector::underscore($this->class_name); $this->controller_class_name = AkInflector::pluralize($this->class_name); $this->controller_file_name = AkInflector::toControllerFilename($this->controller_class_name); $this->table_columns = trim(join(' ', (array) @$this->table_columns)); $this->assignVarToTemplate('attributes', $this->_getModelAttributesForViews()); $this->assignVarToTemplate('class_name', $this->class_name); $this->assignVarToTemplate('table_name', $this->table_name); $this->assignVarToTemplate('plural_name', $this->table_name); $this->assignVarToTemplate('singular_name', AkInflector::singularize($this->table_name)); $this->assignVarToTemplate('file_name', $this->file_name); $this->assignVarToTemplate('table_columns', $this->table_columns); $this->assignVarToTemplate('controller_class_name', $this->controller_class_name); }
public function &addAssociated($association_id, $options = array()) { $default_options = array('class_name' => empty($options['class_name']) ? AkInflector::camelize($association_id) : $options['class_name'], 'primary_key_name', 'remote', 'conditions', 'order', 'instantiate' => false, 'counter_cache' => false); $options = array_merge($default_options, $options); $options['primary_key_name'] = empty($options['primary_key_name']) ? AkInflector::underscore($options['class_name']) . '_id' : $options['primary_key_name']; if ($options['counter_cache']) { $options['counter_cache_column'] = !isset($options['counter_cache_column']) ? $this->Owner->getTableName() . '_counter' : $options['counter_cache_column']; } $this->setOptions($association_id, $options); $associated = $this->addModel($association_id, new AkAssociatedActiveRecord()); $this->setAssociatedId($association_id, $associated->getId()); $this->_build($association_id, $associated); $this->_saveLoadedHandler($association_id, $associated); if ($options['instantiate']) { $associated =& $this->assign($association_id, new $options['class_name']($this->Owner->get($options['primary_key_name']))); } return $associated; }
static function importStructure(&$MailOrPart, $structure = array()) { if (isset($structure['header'])) { $structure['headers'] = $structure['header']; unset($structure['header']); } foreach ($structure as $attribute => $value) { if ($attribute[0] != '_') { $attribute_setter = 'set' . AkInflector::camelize($attribute); if (method_exists($MailOrPart, $attribute_setter)) { $MailOrPart->{$attribute_setter}($value); } else { $MailOrPart->{AkInflector::underscore($attribute)} = $value; } } } return; }
/** * Returns a JavaScript snippet to be used on the Ajax callbacks for * starting visual effects. * * Example: * <?= $prototype_helper->link_to_remote( * 'Reload', * 'update' => 'posts', * 'url' => array('action' => 'reload'), * 'complete' => $scriptaculous_helper->visual_effect('highlight', 'posts', array('duration' => 0.5))) ?> * * If no element_id is given, it assumes "element" which should be a local * variable in the generated JavaScript execution context. This can be * used for example with drop_receiving_element: * * <?= $scriptaculous_helper->drop_receiving_element (..., array('loading' => $scriptaculous_helper->visual_effect('fade'))) ?> * * This would fade the element that was dropped on the drop receiving * element. * * For toggling visual effects, you can use 'toggle_appear', 'toggle_slide', and * 'toggle_blind' which will alternate between appear/fade, slidedown/slideup, and * blinddown/blindup respectively. * * You can change the behaviour with various options, see * http://script.aculo.us for more documentation. */ public function visual_effect($name, $element_id = false, $js_options = array()) { $element = $element_id ? Ak::toJson($element_id) : "element"; if (!empty($js_options['queue']) && is_array($js_options['queue'])) { $js_queue = array(); foreach ($js_options['queue'] as $k => $v) { $js_queue[] = $k == 'limit' ? "{$k}:{$v}" : "{$k}:'{$v}'"; } if (!empty($js_options['queue'])) { $js_options['queue'] = '{' . join(',', $js_queue) . '}'; } } elseif (!empty($js_options['queue'])) { $js_options['queue'] = "'{$js_options['queue']}'"; } if (in_array('toggle_' . $name, $this->_toggle_effects)) { return "Effect.toggle({$element},'" . str_replace('toggle_', '', $name) . "'," . AkJavascriptHelper::_options_for_javascript($js_options) . ");"; } else { return "new Effect." . AkInflector::camelize($name) . "({$element}," . AkJavascriptHelper::_options_for_javascript($js_options) . ");"; } }