/**
  * Changes the editor on the fly
  *
  * @param string $editor String name of editor, excluding the word 'Helper'
  * @return void
  * @author Jose Diaz-Gonzalez
  **/
 public function changeEditor($editor)
 {
     $this->helper = ucfirst($editor);
     $prefix = '';
     if ($editor !== 'Form') {
         $prefix = 'Wysiwyg.';
     }
     if (!$this->importedHelpers[$this->helper]) {
         $this->importedHelpers[$this->helper] = true;
         $this->helpers[] = $prefix . $this->helper;
         $this->_helperMap = ObjectCollection::normalizeObjectArray($this->helpers);
     }
 }
  function testAdd()
  {
    $obj1 = new Object();
    $obj1->set('id', 1);

    $obj2 = new Object();
    $obj2->set('id', 2);

    $arr = array($obj1);
    $col = new ObjectCollection($arr);

    $col->add($obj2);

    $col->rewind();

    $this->assertEqual($col->current(), $obj1);

    $col->next();
    $this->assertEqual($col->current(), $obj2);

    $col->next();
    $this->assertFalse($col->valid());
  }
Ejemplo n.º 3
0
 /**
  * Default Constructor
  *
  * @param View $View The View this helper is being attached to.
  * @param array $settings Configuration settings for the helper.
  */
 public function __construct(View $View, $settings = array())
 {
     $this->_View = $View;
     $this->request = $View->request;
     if (!empty($this->helpers)) {
         $this->_helperMap = ObjectCollection::normalizeObjectArray($this->helpers);
     }
 }
Ejemplo n.º 4
0
 /**
  * Detaches a behavior from a model
  *
  * @param string $name CamelCased name of the behavior to unload
  * @return void
  */
 public function unload($name)
 {
     list(, $name) = pluginSplit($name);
     if (isset($this->_loaded[$name])) {
         $this->_loaded[$name]->cleanup(ClassRegistry::getObject($this->modelName));
         parent::unload($name);
     }
     foreach ($this->_methods as $m => $callback) {
         if (is_array($callback) && $callback[0] === $name) {
             unset($this->_methods[$m]);
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Trigger a callback method on every object in the collection.
  * Used to trigger methods on objects in the collection. Will fire the methods in the
  * order they were attached.
  *
  * ### Options
  *
  * - `breakOn` Set to the value or values you want the callback propagation to stop on.
  *    Can either be a scalar value, or an array of values to break on. Defaults to `false`.
  *
  * - `break` Set to true to enabled breaking. When a trigger is broken, the last returned value
  *    will be returned. If used in combination with `collectReturn` the collected results will be returned.
  *    Defaults to `false`.
  *
  * - `collectReturn` Set to true to collect the return of each object into an array.
  *    This array of return values will be returned from the trigger() call. Defaults to `false`.
  *
  * - `modParams` Allows each object the callback gets called on to modify the parameters to the next object.
  *    Setting modParams to an integer value will allow you to modify the parameter with that index.
  *    Any non-null value will modify the parameter index indicated.
  *    Defaults to false.
  *
  * @param string|CakeEvent $callback Method to fire on all the objects. Its assumed all the objects implement
  *   the method you are calling. If an instance of CakeEvent is provided, then then Event name will parsed to
  *   get the callback name. This is done by getting the last word after any dot in the event name
  *   (eg. `Model.afterSave` event will trigger the `afterSave` callback)
  * @param array $params Array of parameters for the triggered callback.
  * @param array $options Array of options.
  * @return mixed Either the last result or all results if collectReturn is on.
  * @throws CakeException when modParams is used with an index that does not exist.
  */
 public function trigger($callback, $params = array(), $options = array())
 {
     if ($callback instanceof CakeEvent) {
         $callback->omitSubject = true;
     }
     return parent::trigger($callback, $params, $options);
 }
Ejemplo n.º 6
0
 /**
  * test normalizeObjectArray
  *
  * @return void
  */
 public function testnormalizeObjectArray()
 {
     $components = array('Html', 'Foo.Bar' => array('one', 'two'), 'Something', 'Banana.Apple' => array('foo' => 'bar'));
     $result = ObjectCollection::normalizeObjectArray($components);
     $expected = array('Html' => array('class' => 'Html', 'settings' => array()), 'Bar' => array('class' => 'Foo.Bar', 'settings' => array('one', 'two')), 'Something' => array('class' => 'Something', 'settings' => array()), 'Apple' => array('class' => 'Banana.Apple', 'settings' => array('foo' => 'bar')));
     $this->assertEquals($expected, $result);
     // This is the result after Controller::_mergeVars
     $components = array('Html' => null, 'Foo.Bar' => array('one', 'two'), 'Something' => null, 'Banana.Apple' => array('foo' => 'bar'));
     $result = ObjectCollection::normalizeObjectArray($components);
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 7
0
<?php

namespace DesignPatterns\Strategy;

/**
 * strategy pattern
 *
 * Terminology:
 * - Context
 * - Strategy
 * - Concrete Strategy
 *
 * Purpose:
 * to separate strategies and to enable fast switching between them.
 * also this pattern is a good alternative to inheritance (instead of having an abstract class that is extended)
 *
 * Examples:
 * - sorting a list of objects, one strategy by date, the other by id
 * - simplify unit testing: e.g. switching between file and in-memory storage
 *
 */
$elements = array(array('id' => 2, 'date' => '2011-01-01'), array('id' => 1, 'date' => '2011-02-01'));
$collection = new ObjectCollection($elements);
$collection->setComparator(new IdComparator());
$collection->sort();
$collection->setComparator(new DateComparator());
$collection->sort();
Ejemplo n.º 8
0
<?php

require 'Strategy/ObjectCollection.php';
require 'Strategy/ComparerInterface.php';
require 'Strategy/TitleComparer.php';
require 'Strategy/DateComparer.php';
require 'Strategy/AuthorComparer.php';
error_reporting(E_ALL);
ini_set("display_errors", 1);
$elements = array(array('title' => 'Bushcraft 101: A Field Guide to the Art of Wilderness Survival', 'pub-date' => '2014-09-01', 'author' => 'Dave Canterbury'), array('title' => 'Complexity and the Arrow of Time', 'pub-date' => '2013-09-23', 'author' => 'Charles H. Lineweaver'), array('title' => 'Parable of the Sower', 'pub-date' => '2000-01-01', 'author' => 'Octavia E. Butler'), array('title' => 'JavaScript: The Good Parts', 'pub-date' => '2008-05-01', 'author' => 'Douglas Crockford'));
$type = !empty($_GET['type']) ? htmlspecialchars($_GET['type']) : 'title';
$collection = new ObjectCollection($elements);
switch ($type) {
    case 'date':
        $collection->setComparer(new DateComparer());
        break;
    case 'author':
        $collection->setComparer(new AuthorComparer());
        break;
    case 'title':
    default:
        $collection->setComparer(new TitleComparer());
}
$collection->sort();
$collection->display();
 function add(&$obj)
 {
   $this->_ensureCollection();
   parent :: add($obj);
 }
Ejemplo n.º 10
0
 /**
  * Changes the editor on the fly
  *
  * @param string $editor String name of editor, excluding the word 'Helper'
  * @param array $helperOptions Each type of wysiwyg helper takes different options.
  * @return void
  * @throws MissingHelperException
  **/
 public function changeEditor($editor, $helperOptions = array())
 {
     $this->helper = ucfirst($editor);
     if (!empty($helperOptions)) {
         $this->updateSettings($helperOptions);
     }
     if (!isset($this->importedHelpers[$this->helper])) {
         throw new MissingHelperException(sprintf("Missing Wysiwyg.%s Helper", $this->helper));
     }
     if (!$this->importedHelpers[$this->helper]) {
         $class = 'Wysiwyg.' . $this->helper;
         $helpers = ObjectCollection::normalizeObjectArray(array($class));
         foreach ($helpers as $properties) {
             list($plugin, $class) = pluginSplit($properties['class']);
             $this->{$class} = $this->_View->Helpers->load($properties['class'], $properties['settings']);
         }
         $this->importedHelpers[$this->helper] = true;
     }
 }
Ejemplo n.º 11
0
 public function __construct(NodeSchema $node_schema)
 {
     parent::__construct($node_schema);
 }