Beispiel #1
0
 /**
  * undocumented function
  *
  * @return void
  */
 function main()
 {
     $choice = '';
     $Tasks = new Folder(dirname(__FILE__) . DS . 'tasks');
     list($folders, $files) = $Tasks->read();
     $i = 1;
     $choices = array();
     foreach ($files as $file) {
         if (preg_match('/upgrade_/', $file)) {
             $choices[$i] = basename($file, '.php');
             $this->out($i++ . '. ' . basename($file, '.php'));
         }
     }
     while ($choice == '') {
         $choice = $this->in("Enter a number from the list above, or 'q' to exit", null, 'q');
         if ($choice === 'q') {
             $this->out("Exit");
             $this->_stop();
         }
         if ($choice == '' || intval($choice) > count($choices)) {
             $this->err("The number you selected was not an option. Please try again.");
             $choice = '';
         }
     }
     if (intval($choice) > 0 && intval($choice) <= count($choices)) {
         $upgrade = Inflector::classify($choices[intval($choice)]);
     }
     $this->tasks = array($upgrade);
     $this->loadTasks();
     return $this->{$upgrade}->execute();
 }
Beispiel #2
0
 /**
  * Execution method always used for tasks
  *
  * @return void
  */
 public function execute()
 {
     if (!empty($this->args)) {
         $command = Inflector::classify(array_shift($this->args));
         if ($this->hasTask($command)) {
             return $this->{$command}->runCommand('execute', $this->args);
         }
     }
     $this->out(__d('webmaster', "Interactive Requirements Shell"));
     $this->hr();
     $this->out(__d('webmaster', "[A]vailability"));
     $this->out(__d('webmaster', "[I]mplementation"));
     $this->out(__d('webmaster', "[S]takeholder"));
     $this->out(__d('webmaster', "[Q]uit"));
     $option = $this->in(__d('webmaster', "What would you like to do?"), array_keys($this->__options));
     $method = $this->__options[strtoupper($option)];
     if ($this->hasMethod($method)) {
         $this->{$method}();
     } else {
         if ($this->hasTask($method)) {
             $this->{$method}->runCommand('execute', $this->args);
         }
     }
     $this->execute();
 }
 /**
  * Delegates the job of enforcing authorization to the active controller.
  *
  * When using this Authorize object, each Controller must define an
  * `::isAuthorized($user)` method. An Exception will be thrown if such
  * a method does not exist.
  *
  * The method takes as its only argument an array of User data as
  * normally provided by `Auth->user()` to use in determining access.
  *
  * The method must return a boolean true/false value where true
  * indicates the currently logged in User is allowed to access the
  * current CakeRequest, and false indicates the User's access is denied.
  *
  * As an example, if you wanted all logged-in-users to have access to
  * all parts of your app, you could add the following method to your
  * AppController:
  *
  * 		public function isAuthorized($user) {
  * 			return true;
  * 		}
  *
  * @param array $user An array containing a User record, typically provided by Auth->user().
  * @param CakeRequest $request The active HTTP request object.
  * @throws NotImplementedException If the controller does not define a valid ::isAuthorized() method.
  * @return bool	True if the current User has access to the requested section of the app, false otherwise.
  */
 public function authorize($user, CakeRequest $request)
 {
     if (!$this->controllerIsAuthorizedExists()) {
         throw new NotImplementedException(sprintf("%sController does not define the mandatory `::isAuthorized()` method used for authorization.", Inflector::classify($request->params['controller'])));
     }
     return $this->delegateToIsAuthorized($user);
 }
Beispiel #4
0
 public static function generate($args, $subfolder = 'default')
 {
     $subfolder = trim($subfolder, '/');
     if (!is_dir(PKGPATH . 'oil/views/' . $subfolder)) {
         throw new Exception('The subfolder for scaffolding templates doesn\'t exist or is spelled wrong: ' . $subfolder . ' ');
     }
     // Do this first as there is the largest chance of error here
     Generate::model($args, false);
     // Go through all arguments after the first and make them into field arrays
     $fields = array();
     foreach (array_slice($args, 1) as $arg) {
         // Parse the argument for each field in a pattern of name:type[constraint]
         preg_match('/([a-z0-9_]+):([a-z0-9_]+)(\\[([0-9]+)\\])?/i', $arg, $matches);
         $fields[] = array('name' => strtolower($matches[1]), 'type' => isset($matches[2]) ? $matches[2] : 'string', 'constraint' => isset($matches[4]) ? $matches[4] : null);
     }
     $data['singular'] = $singular = strtolower(array_shift($args));
     $data['model'] = $model_name = 'Model_' . \Inflector::classify($singular);
     $data['plural'] = $plural = \Inflector::pluralize($singular);
     $data['fields'] = $fields;
     $filepath = APPPATH . 'classes/controller/' . trim(str_replace(array('_', '-'), DS, $plural), DS) . '.php';
     $controller = \View::factory($subfolder . '/scaffold/controller', $data);
     $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::factory($subfolder . '/scaffold/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/view', $data)), array('name' => 'create', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::factory($subfolder . '/scaffold/actions/delete', $data)));
     // Write controller
     Generate::create($filepath, $controller, 'controller');
     // Create each of the views
     foreach (array('index', 'view', 'create', 'edit', '_form') as $view) {
         Generate::create(APPPATH . 'views/' . $plural . '/' . $view . '.php', \View::factory($subfolder . '/scaffold/views/' . $view, $data), 'view');
     }
     // Add the default template if it doesnt exist
     if (!file_exists($app_template = APPPATH . 'views/template.php')) {
         Generate::create($app_template, file_get_contents(PKGPATH . 'oil/views/default/template.php'), 'view');
     }
     Generate::build();
 }
Beispiel #5
0
 public function __construct($from, $name, array $config)
 {
     $this->name = $name;
     $this->model_from = $from;
     $this->model_to = array_key_exists('model_to', $config) ? $config['model_to'] : \Inflector::get_namespace($from) . 'Model_' . \Inflector::classify($name);
     $this->key_from = array_key_exists('key_from', $config) ? (array) $config['key_from'] : $this->key_from;
     $this->key_to = array_key_exists('key_to', $config) ? (array) $config['key_to'] : $this->key_to;
     $this->conditions = array_key_exists('conditions', $config) ? (array) $config['conditions'] : array();
     if (!empty($config['table_through'])) {
         $this->table_through = $config['table_through'];
     } else {
         $table_name = array($this->model_from, $this->model_to);
         natcasesort($table_name);
         $table_name = array_merge($table_name);
         $this->table_through = \Inflector::tableize($table_name[0]) . '_' . \Inflector::tableize($table_name[1]);
     }
     $this->key_through_from = !empty($config['key_through_from']) ? (array) $config['key_through_from'] : (array) \Inflector::foreign_key($this->model_from);
     $this->key_through_to = !empty($config['key_through_to']) ? (array) $config['key_through_to'] : (array) \Inflector::foreign_key($this->model_to);
     $this->cascade_save = array_key_exists('cascade_save', $config) ? $config['cascade_save'] : $this->cascade_save;
     $this->cascade_delete = array_key_exists('cascade_delete', $config) ? $config['cascade_delete'] : $this->cascade_delete;
     if (!class_exists($this->model_to)) {
         throw new \FuelException('Related model not found by Many_Many relation "' . $this->name . '": ' . $this->model_to);
     }
     $this->model_to = get_real_class($this->model_to);
 }
Beispiel #6
0
 public static function getExternalConditions($select, $parentModel, $childName, $attributes)
 {
     $parentModelName = get_class($parentModel);
     $parentTableName = $parentModel->getTableName();
     // exhibitions
     $childName = array_key_exists('source', $attributes) ? $attributes['source'] : $childName;
     $childModelName = Inflector::classify($childName);
     $childTableName = Bbx_Model::load($childModelName)->getTableName();
     // images
     if (!array_key_exists($childTableName, $select->getPart('from'))) {
         $select->from($childTableName, array());
         // images
     }
     if (array_key_exists('as', $attributes)) {
         $refColumn = $attributes['as'] . '_id';
         $polyType = $attributes['as'] . '_type';
     } else {
         $refColumn = Inflector::singularize($parentTableName) . '_id';
     }
     try {
         $parentModel->getRowData();
         $select->where("`" . $childTableName . "`.`" . $refColumn . "` = " . $parentModel->id);
     } catch (Exception $e) {
         $select->where("`" . $childTableName . "`.`" . $refColumn . "` = `" . $parentTableName . "`.`id`");
     }
     if (isset($polyType)) {
         $select->where("`" . $childTableName . "`.`" . $polyType . "` = '" . Inflector::underscore($parentModelName) . "'");
     }
     return $select;
 }
Beispiel #7
0
 /**
  * @todo Implement testClassify().
  */
 public function testClassify()
 {
     $this->assertEquals(Inflector::classify('path.to.class_name'), 'Path\\To\\ClassName');
     $this->assertEquals(Inflector::classify('/path/to/class-name'), '\\Path\\To\\ClassName');
     $this->assertEquals(Inflector::classify('Path/To/ClassName'), 'Path\\To\\ClassName');
     $this->assertEquals(Inflector::classify('class_name'), 'ClassName');
 }
Beispiel #8
0
 function main()
 {
     if (empty($this->args)) {
         return $this->err('Usage: ./cake fixturize <table>');
     }
     if ($this->args[0] == '?') {
         return $this->out('Usage: ./cake fixturize <table> [-force] [-reindex]');
     }
     $options = array('force' => false, 'reindex' => false);
     foreach ($this->params as $key => $val) {
         foreach ($options as $name => $option) {
             if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) {
                 $options[$name] = true;
             }
         }
     }
     foreach ($this->args as $table) {
         $name = Inflector::classify($table);
         $Model = new AppModel(array('name' => $name, 'table' => $table));
         $file = sprintf('%stests/fixtures/%s_fixture.php', APP, Inflector::underscore($name));
         $File = new File($file);
         if ($File->exists() && !$options['force']) {
             $this->err(sprintf('File %s already exists, use --force option.', $file));
             continue;
         }
         $records = $Model->find('all');
         $out = array();
         $out[] = '<?php';
         $out[] = '';
         $out[] = sprintf('class %sFixture extends CakeTestFixture {', $name);
         $out[] = sprintf('	var $name = \'%s\';', $name);
         $out[] = '	var $records = array(';
         $File->write(join("\n", $out));
         foreach ($records as $record) {
             $out = array();
             $out[] = '		array(';
             if ($options['reindex']) {
                 foreach (array('old_id', 'vendor_id') as $field) {
                     if ($Model->hasField($field)) {
                         $record[$name][$field] = $record[$name]['id'];
                         break;
                     }
                 }
                 $record[$name]['id'] = String::uuid();
             }
             foreach ($record[$name] as $field => $val) {
                 $out[] = sprintf('			\'%s\' => \'%s\',', addcslashes($field, "'"), addcslashes($val, "'"));
             }
             $out[] = '		),';
             $File->write(join("\n", $out));
         }
         $out = array();
         $out[] = '	);';
         $out[] = '}';
         $out[] = '';
         $out[] = '?>';
         $File->write(join("\n", $out));
         $this->out(sprintf('-> Create %sFixture with %d records (%d bytes) in "%s"', $name, count($records), $File->size(), $file));
     }
 }
 /**
  * Helper for firing jobs
  *
  * @param array $data array of data to pass into a job
  * @return bool
  * @throws CakeException If if the job is invalid, could not be loaded or could not be enqueued
  */
 public function fireJob($data = array())
 {
     if (isset($data['job'])) {
         $new = $data;
         unset($data);
         $data[$this->alias] = $new;
     }
     if (empty($data[$this->alias]['job'])) {
         throw new CakeException(__('Invalid job.'));
     }
     foreach ($data[$this->alias] as $key => $val) {
         if ($key == 'job') {
             continue;
         }
         if (strpos($key, '_id') !== false) {
             $model = Inflector::classify(substr($key, 0, strpos($key, '_id')));
             $Model = ClassRegistry::init($model);
             $res = $Model->findById($val);
             $data[$this->alias][$key] = $res[$Model->alias];
         }
     }
     if (empty($data[$this->alias]['job'])) {
         throw new CakeException(__('Job could not be loaded.'));
     }
     $job = $data[$this->alias]['job'];
     unset($data[$this->alias]['job']);
     $data = array_values($data[$this->alias]);
     if ($this->enqueue($job, $data)) {
         return true;
     }
     throw new CakeException(__('Job could not be enqueued.'));
 }
Beispiel #10
0
 /**
  * Execution method always used for tasks
  *
  * @return void
  */
 function execute()
 {
     if (empty($this->params['skel'])) {
         $this->params['skel'] = '';
         if (is_dir(CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel') === true) {
             $this->params['skel'] = CAKE_CORE_INCLUDE_PATH . DS . 'cake' . DS . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel';
         }
     }
     $plugin = null;
     if (isset($this->args[0])) {
         $plugin = Inflector::camelize($this->args[0]);
         $this->Dispatch->shiftArgs();
         $this->out(sprintf('Plugin: %s', $plugin));
         $pluginPath = Inflector::underscore($plugin) . DS;
         $this->out(sprintf('Plugin: %s', $this->path . $pluginPath));
     }
     if (isset($this->args[0]) && isset($plugin)) {
         $task = Inflector::classify($this->args[0]);
         $this->Dispatch->shiftArgs();
         if (in_array($task, $this->tasks)) {
             $this->{$task}->path = $this->path . $pluginPath . Inflector::underscore(Inflector::pluralize($task)) . DS;
             if (!is_dir($this->{$task}->path)) {
                 $this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
             }
             $this->{$task}->loadTasks();
             $this->{$task}->execute();
         }
         exit;
     }
     $this->__interactive($plugin);
 }
Beispiel #11
0
 protected static function get_class_name($prefix = '')
 {
     if (!$prefix) {
         return __CLASS__;
     }
     return sprintf('%s_%s', __CLASS__, Inflector::classify($prefix));
 }
Beispiel #12
0
 /**
  * send
  *
  */
 public function send($model)
 {
     $models = Configure::read('Reminder.models');
     $modelName = Inflector::classify($model);
     $loader = ReminderConfigLoader::init($modelName);
     $layout = $loader->load('layout');
     try {
         $this->Reminder = ClassRegistry::init('Reminder.Reminder');
         $result = $this->Reminder->send($this->request->data, $modelName);
         if ($result === true) {
             $this->request->data = null;
             $this->Session->setFlash(__('Reminder mail has been sent'), Configure::read('Reminder.setFlashElement.success'), Configure::read('Reminder.setFlashParams.success'));
             $view = $loader->load('view.sent');
             if (empty($view)) {
                 $view = 'sent';
             }
             return $this->render($view, $layout);
         }
     } catch (ReminderException $e) {
         $this->Session->setFlash($e->getMessage(), Configure::read('Reminder.setFlashElement.error'), Configure::read('Reminder.setFlashParams.error'));
     }
     $emailField = $loader->load('email');
     $this->set(array('model' => $model, 'modelName' => $modelName, 'emailField' => $emailField));
     $view = $loader->load('view.send');
     if (empty($view)) {
         $view = 'send';
     }
     return $this->render($view, $layout);
 }
Beispiel #13
0
 private function initModel()
 {
     if (!$this->model) {
         $model = Inflector::classify($this->controller);
     }
     $this->{$model} = new $model();
 }
Beispiel #14
0
 function main()
 {
     if (empty($this->args)) {
         return $this->err('Usage: ./cake uuidize <table>');
     }
     if ($this->args[0] == '?') {
         return $this->out('Usage: ./cake uuidize <table> [-force] [-reindex]');
     }
     $options = array('force' => false, 'reindex' => false);
     foreach ($this->params as $key => $val) {
         foreach ($options as $name => $option) {
             if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) {
                 $options[$name] = true;
             }
         }
     }
     foreach ($this->args as $table) {
         $name = Inflector::classify($table);
         $Model = new AppModel(array('name' => $name, 'table' => $table));
         $records = $Model->find('all');
         foreach ($records as $record) {
             $Model->updateAll(array('id' => '"' . String::uuid() . '"'), array('id' => $record[$name]['id']));
         }
     }
 }
Beispiel #15
0
 /**
  * setup
  *
  * @param Model $Model
  * @param array $config
  * @return void
  */
 public function setup(Model $Model, $config = array())
 {
     $recipe = Configure::read('Oven.recipe');
     if (!empty($recipe)) {
         foreach ($recipe as $key => $type) {
             $modelName = Inflector::classify($key);
             if (!isset($this->settings['uploadFields'][$modelName])) {
                 $this->settings['uploadFields'][$modelName] = array();
             }
             if (!empty($type['schema'])) {
                 foreach ($type['schema'] as $field => $val) {
                     if (empty($val['type'])) {
                         continue;
                     }
                     if ($val['type'] == 'file') {
                         $this->settings['uploadFields'][$modelName][] = $field;
                     }
                 }
             }
         }
     }
     if (empty($config['uploadLocation'])) {
         $config['uploadLocation'] = Configure::read('Oven.config.upload_location');
         if (empty($config['uploadLocation'])) {
             $config['uploadLocation'] = WWW_ROOT . 'files' . DS . 'uploads' . DS;
         }
     }
     if (!file_exists($config['uploadLocation'])) {
         new Folder($config['uploadLocation'], true);
     }
     $this->settings = Set::merge($this->settings, $config);
 }
Beispiel #16
0
 /**
  * Override loadTasks() to handle paths
  *
  * @access public
  */
 function loadTasks()
 {
     parent::loadTasks();
     $task = Inflector::classify($this->command);
     if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
         if (empty($this->{$task}->path)) {
             $path = Inflector::underscore(Inflector::pluralize($this->command));
             $this->{$task}->path = $this->params['working'] . DS . $path . DS;
         }
         if (isset($this->params['connection'])) {
             $this->{$task}->connection = $this->params['connection'];
         }
         foreach ($this->args as $i => $arg) {
             if (strpos($arg, '.')) {
                 list($this->params['plugin'], $this->args[$i]) = pluginSplit($arg);
                 break;
             }
         }
         if (isset($this->params['plugin'])) {
             $this->{$task}->plugin = $this->params['plugin'];
         }
         if (!is_dir($this->{$task}->path)) {
             $this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
             $this->_stop();
         }
     }
 }
Beispiel #17
0
 public function before()
 {
     parent::before();
     $this->app = \Uri::segment(1);
     // guess app_name, if it is not provided
     if (is_null($this->app_name)) {
         $this->app_name = \Inflector::classify($this->app);
     }
     // guess model name from URI segment, if it is not provided
     if (is_null($this->model)) {
         $this->model = 'Model_' . $this->app_name;
     }
     // set app title
     $this->template->title = static::$title;
     // render menus
     $this->template->set('menu', Petro_Menu::render(static::$menu), false);
     // use uri segment to find ref_type from defined menu for later use
     $menu = Petro_Menu::find($this->app, static::$menu);
     // if page_title is not set, default to menu label
     if (!isset($this->template->page_title)) {
         $this->template->page_title = empty($menu['label']) ? \Inflector::pluralize($this->app_name) : $menu['label'];
     }
     $this->sidebars = new Petro_Sidebar();
     is_null($this->must_login) and $this->must_login = \Config::get('petro.auth.enable', true);
     // if require login and not in the ignore login list, then check for login
     if ($this->must_login and !in_array(\Uri::string(), static::$ignore_login)) {
         if (!\Auth::instance()->check()) {
             $this->login_then_redirect(\Uri::string());
         }
     }
 }
Beispiel #18
0
 protected static function get_class_name($prefix = '', $namespace = null)
 {
     $namespace_prefix = $namespace ? sprintf('\\%s\\', $namespace) : '';
     if (!$prefix) {
         return $namespace_prefix . __CLASS__;
     }
     return sprintf('%s%s_%s', $namespace_prefix, __CLASS__, Inflector::classify($prefix));
 }
Beispiel #19
0
 static function define($alias, $attributes = array(), $model = null, $extends = null)
 {
     $_this = self::getInstance();
     if (empty($model)) {
         $model = Inflector::classify($alias);
     }
     $_this->models[$alias] = array('attributes' => $attributes, 'model' => $model, 'extends' => $extends);
 }
 public function createAttributeHandler(PHPTAL_NamespaceAttribute $att, PHPTAL_Dom_Element $tag, $expression)
 {
     $name = Inflector::classify($att->getLocalName());
     $class = 'Cake_PHPTAL_Php_Attribute_Cake_' . $name;
     include_once dirname(__FILE__) . DS . $class . '.php';
     $result = new $class($tag, $expression);
     return $result;
 }
Beispiel #21
0
 function loadPaimentComponent($name)
 {
     $importName = 'Shop.' . Inflector::classify($name);
     if (App::import('Component', $importName)) {
         return $this->ComponentLoader->loadComponent(Inflector::classify($name) . 'Payment');
     }
     return null;
 }
Beispiel #22
0
 public function __get($name)
 {
     $class = Inflector::classify($name);
     if ($name === 'Transaction') {
         return $this->{$class} = ClassRegistry::init('Ninja.TransactionService');
     }
     return $this->{$class} = ClassRegistry::init($class);
 }
Beispiel #23
0
 /** 
  * Tree generation method. 
  * 
  * Accepts the results of  
  *     find('all', array('fields' => array('lft', 'rght', 'whatever'), 'order' => 'lft ASC'));
  *     children(); // if you have the tree behavior of course! 
  * or     findAllThreaded(); and generates a tree structure of the data. 
  * 
  * Settings (2nd parameter): 
  *    'model' => name of the model (key) to look for in the data array. defaults to the first model for the current
  * controller. 
  *    'alias' => the array key to output for a simple ul (not used if element is specified) 
  *    'type' => type of output defaults to ul 
  *    'itemType => type of item output default to li 
  *    'class' => class for top level 'item' 
  *    'element' => path to an element to render to get node contents. 
  * 
  * @param array $data data to loop on 
  * @param array $settings 
  * @return string html representation of the passed data 
  * @access public 
  */
 function generate($data, $settings = array())
 {
     $element = false;
     $class = false;
     $model = false;
     $options = '';
     $alias = 'name';
     $left = 'lft';
     $right = 'rght';
     $type = 'ul';
     $itemType = 'li';
     extract($settings);
     $view =& ClassRegistry::getObject('view');
     if (!$model) {
         $model = Inflector::classify($view->params['models'][0]);
     }
     $stack = array();
     if ($class) {
         $options .= ' class="' . $class . '" ';
     }
     $return = "\r\n" . '<' . $type . $options . '>';
     foreach ($data as $i => $result) {
         // Prefix
         while ($stack && $stack[count($stack) - 1] < $result[$model][$right]) {
             array_pop($stack);
             $return .= "\r\n" . str_repeat("\t", count($stack) + 1) . '</' . $type . '>';
             $return .= '</' . $itemType . '>';
         }
         $return .= "\r\n" . str_repeat("\t", count($stack) + 1) . '<' . $itemType . '>';
         // Main Content
         if ($element) {
             $return .= $view->renderElement($element, array('data' => $result));
         } else {
             $return .= $this->Html->link($result[$model][$alias], array('controller' => 'store', 'action' => 'browse', $result[$model]['handle']));
         }
         // Suffix
         if (!isset($result[$model][$right]) || !isset($result[$model][$left]) || isset($result['children'])) {
             if (isset($result['children'])) {
                 unset($settings['class']);
                 $return .= $this->generate($result['children'], $settings);
             }
             $return .= '</' . $itemType . '>';
         } elseif ($result[$model][$right] == $result[$model][$left] + 1) {
             // Has no children
             $return .= '</' . $itemType . '>';
         } else {
             $return .= '<' . $type . '>';
             $stack[] = $result[$model][$right];
         }
     }
     while ($stack) {
         array_pop($stack);
         $return .= "\r\n" . str_repeat("\t", count($stack) + 1) . '</' . $type . '>';
         $return .= '</' . $itemType . '>';
     }
     $return .= "\r\n" . '</' . $type . '>' . "\r\n";
     return $return;
 }
 /**
  * get processor for payment method
  * @param $id int PaymentMethod id
  */
 public function getProcessor($id)
 {
     $data = $this->findById($id);
     $returnData['name'] = $data['PaymentMethod']['processor'];
     if (is_file(APP . 'plugins' . DS . 'payment' . DS . 'models' . DS . $returnData['name'] . '.php')) {
         $returnData['model'] = Inflector::classify($returnData['name']);
     }
     return $returnData;
 }
Beispiel #25
0
 /**
  * Setup behavior
  *
  * @param object $model Model
  * @param array $settings Settings
  */
 public function setup($model, $settings = array())
 {
     if (!isset($this->settings[$model->alias])) {
         $configured = Configure::read('Geocode');
         if (!empty($configured)) {
             foreach ($this->default as $key => $value) {
                 if (isset($configured[$key])) {
                     $this->default[$key] = $configured[$key];
                 }
             }
         }
         $this->settings[$model->alias] = $this->default;
     }
     if (!empty($settings['models'])) {
         foreach ($settings['models'] as $field => $data) {
             unset($settings['models'][$field]);
             if (is_numeric($field) && !is_array($data)) {
                 $field = $data;
                 $data = array('model' => Inflector::classify($field));
             } else {
                 if (is_numeric($field) && !empty($data['field'])) {
                     $field = $data['field'];
                 }
             }
             if (!is_array($data)) {
                 $data = array('model' => $data);
             }
             if (empty($data['model'])) {
                 continue;
             }
             if (empty($data['referenceField'])) {
                 $modelName = $data['model'];
                 if (strpos($data['model'], '.') !== false) {
                     list($modelName, $childModelName) = explode('.', $data['model']);
                 }
                 $data['referenceField'] = Inflector::underscore($modelName) . '_id';
             }
             $settings['models'][$field] = array_merge(array('field' => 'name'), $data);
         }
     }
     $settings = Set::merge($this->settings[$model->alias], $settings);
     if (empty($this->services[strtolower($settings['service'])])) {
         trigger_error(sprintf(__('Geocode service %s not implemented', true), $settings['service']), E_USER_WARNING);
         return false;
     }
     if (!isset($this->socket)) {
         $this->socket = new HttpSocket();
     }
     foreach (array('fields', 'addressFields') as $parameter) {
         $fields = array();
         foreach ($settings[$parameter] as $i => $field) {
             $fields[is_numeric($i) ? $field : $i] = $parameter != 'fields' || $model->hasField($field) ? $field : false;
         }
         $settings[$parameter] = $fields;
     }
     $this->settings[$model->alias] = $settings;
 }
Beispiel #26
0
 function defModel()
 {
     $defmodel = null;
     //$defmodel = $this->model();
     if ($defmodel == null) {
         $defmodel = Inflector::classify($this->params['controller']);
     }
     return $defmodel;
 }
Beispiel #27
0
 /**
  * Install registries table
  *
  * @static
  * @access  protected
  * @return  void
  */
 public static function generate($table_name = null)
 {
     $table_name or $table_name = \Config::get('hybrid.tables.registry', 'options');
     $class_name = \Inflector::classify($table_name, true);
     if ('y' === \Cli::prompt("Would you like to install `registry.{$table_name}` table?", array('y', 'n'))) {
         Generate::migration(array('create_' . $table_name, 'name:string[255]', 'value:longtext'));
         Generate::$create_files = array();
     }
 }
Beispiel #28
0
 /**
  * Assign $this->connection to the active task if a connection param is set.
  *
  */
 public function startup()
 {
     parent::startup();
     $task = Inflector::classify($this->command);
     if (isset($this->{$task}) && !in_array($task, array('Project', 'DbConfig'))) {
         if (isset($this->params['connection'])) {
             $this->{$task}->connection = $this->params['connection'];
         }
     }
 }
Beispiel #29
0
 /**
  * Forge
  *
  * @param   array   Fields mainly
  * @param   string  Subfolder (or admin "theme") where views are held
  * @return	mixed
  */
 public static function forge($args, $subfolder)
 {
     $data = array();
     $subfolder = trim($subfolder, '/');
     if (!is_dir(PKGPATH . 'oil/views/' . static::$view_subdir . $subfolder)) {
         throw new Exception('The subfolder for admin templates does not exist or is spelled wrong: ' . $subfolder . ' ');
     }
     // Go through all arguments after the first and make them into field arrays
     $data['fields'] = array();
     foreach (array_slice($args, 1) as $arg) {
         // Parse the argument for each field in a pattern of name:type[constraint]
         preg_match(static::$fields_regex, $arg, $matches);
         $data['fields'][] = array('name' => \Str::lower($matches[1]), 'type' => isset($matches[2]) ? $matches[2] : 'string', 'constraint' => isset($matches[4]) ? $matches[4] : null);
     }
     $name = array_shift($args);
     // Replace / with _ and classify the rest. DO NOT singularize
     $controller_name = \Inflector::classify(static::$controller_prefix . str_replace(DS, '_', $name), false);
     // Replace / with _ and classify the rest. Singularize
     $model_name = \Inflector::classify(static::$model_prefix . str_replace(DS, '_', $name));
     // Either foo or folder/foo
     $view_path = $controller_path = str_replace(array('_', '-'), DS, \Str::lower($controller_name));
     // Models are always singular, tough!
     $model_path = str_replace(array('_', '-'), DS, \Str::lower($model_name));
     // uri's have forward slashes, DS is a backslash on Windows
     $uri = str_replace(DS, '/', $controller_path);
     $data['include_timestamps'] = !\Cli::option('no-timestamp', false);
     // If a folder is used, the entity is the last part
     $name_parts = explode(DS, $name);
     $data['singular_name'] = \Inflector::singularize(end($name_parts));
     $data['plural_name'] = \Inflector::pluralize($data['singular_name']);
     $data['table'] = \Inflector::tableize($model_name);
     $data['controller_parent'] = static::$controller_parent;
     /** Generate the Migration **/
     $migration_args = $args;
     array_unshift($migration_args, 'create_' . \Inflector::pluralize(\Str::lower($name)));
     Generate::migration($migration_args, false);
     // Merge some other data in
     $data = array_merge(compact(array('controller_name', 'model_name', 'model_path', 'view_path', 'uri')), $data);
     /** Generate the Model **/
     $model = \View::forge(static::$view_subdir . $subfolder . '/model', $data);
     Generate::create(APPPATH . 'classes/model/' . $model_path . '.php', $model, 'model');
     /** Generate the Controller **/
     $controller = \View::forge(static::$view_subdir . $subfolder . '/controller', $data);
     $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/view', $data)), array('name' => 'create', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/delete', $data)));
     Generate::create(APPPATH . 'classes/controller/' . $controller_path . '.php', $controller, 'controller');
     // Create each of the views
     foreach (array('index', 'view', 'create', 'edit', '_form') as $view) {
         Generate::create(APPPATH . 'views/' . $controller_path . '/' . $view . '.php', \View::forge(static::$view_subdir . $subfolder . '/views/actions/' . $view, $data), 'view');
     }
     // Add the default template if it doesnt exist
     if (!file_exists($app_template = APPPATH . 'views/template.php')) {
         Generate::create($app_template, file_get_contents(PKGPATH . 'oil/views/' . static::$view_subdir . $subfolder . '/views/template.php'), 'view');
     }
     Generate::build();
 }
Beispiel #30
0
 /**
  * create log table
  *
  * @param string $modelName
  */
 function _create($modelName)
 {
     $modelName = Inflector::classify($modelName);
     $logModelName = $modelName . 'Log';
     // TODO: read suffix option
     $logTableName = Inflector::tableize($logModelName);
     // -- load model
     $Model = ClassRegistry::init($modelName);
     $fieldPrefix = Inflector::singularize($Model->table) . '_';
     $modelSchema = $Model->schema();
     // == create log table schema
     // primaryKey
     if (!empty($modelSchema[$Model->primaryKey])) {
         $assocField = $fieldPrefix . $Model->primaryKey;
         $modelSchema[$assocField] = $modelSchema[$Model->primaryKey];
         $modelSchema[$assocField]['key'] = 'index';
         $modelSchema['indexes']['IX_' . $assocField] = array('column' => $assocField, 'unique' => 0);
         unset($modelSchema[$Model->primaryKey]);
     }
     foreach (array('created', 'modified', 'updated') as $field) {
         if (!empty($modelSchema[$field])) {
             $modelSchema[$fieldPrefix . $field] = $modelSchema[$field];
             unset($modelSchema[$field]);
         }
     }
     $modelSchema = am(array('id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'length' => 20, 'key' => 'primary'), 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL)), $modelSchema);
     $modelSchema['indexes']['PRIMARY'] = array('column' => 'id', 'unique' => 1);
     // == process
     $ds = $Model->getDataSource();
     /* @var $ds DboSource */
     $this->Schema->load(array($logTableName => $modelSchema));
     $dropStatement = $ds->dropSchema($this->Schema, $logTableName);
     $createStatement = $ds->createSchema($this->Schema, $logTableName);
     $this->out("\n" . __('The following table(s) will be dropped.', true));
     $this->out($logTableName);
     if ('y' == $this->in(__('Are you sure you want to drop the table(s)?', true), array('y', 'n'), 'n')) {
         $this->out(__('Dropping table(s).', true));
         if (!$ds->execute($dropStatement)) {
             $this->error($logTableName . ': ' . $ds->lastError());
         } else {
             $this->out(sprintf(__('%s updated.', true), $logTableName));
         }
     }
     $this->out("\n" . __('The following table(s) will be created.', true));
     $this->out($logTableName);
     if ('y' == $this->in(__('Are you sure you want to create the table(s)?', true), array('y', 'n'), 'y')) {
         $this->out(__('Creating table(s).', true));
         if (!$ds->execute($createStatement)) {
             $this->error($logTableName . ': ' . $ds->lastError());
         } else {
             $this->out(sprintf(__('%s updated.', true), $logTableName));
         }
     }
     $this->out(__('End create.', true));
 }