/** * Instantiate the class and apply settings. * * @param View $view * @param array $settings */ public function __construct(View $view, $settings = array()) { parent::__construct($view, $settings); $settings = $settings + Configure::read('Decoda.config'); $locale = Configure::read('Config.language') ?: $settings['locale']; $localeMap = Configure::read('Decoda.locales'); unset($settings['locale']); $decoda = new \Decoda\Decoda('', $settings); $decoda->whitelist($settings['whitelist'])->blacklist($settings['blacklist']); if ($paths = $settings['paths']) { foreach ((array) $paths as $path) { $decoda->addPath($path); } } if ($messages = $settings['messages']) { $decoda->addMessages(new \Decoda\Loader\DataLoader($messages)); } // Set locale if (isset($localeMap[$locale])) { $decoda->setLocale($localeMap[$locale]); } else { if (in_array($locale, $localeMap)) { $decoda->setLocale($locale); } } // Apply hooks and filters if (empty($settings['filters']) && empty($settings['hooks'])) { $decoda->defaults(); } else { if ($filters = $settings['filters']) { foreach ((array) $filters as $filter) { $filter = sprintf('\\Decoda\\Filter\\%sFilter', $filter); $decoda->addFilter(new $filter()); } } if ($hooks = $settings['hooks']) { foreach ((array) $hooks as $hook) { $hook = sprintf('\\Decoda\\Hook\\%sHook', $hook); $decoda->addHook(new $hook()); } } } // Custom config $decoda->addHook(new \Decoda\Hook\EmoticonHook(array('path' => '/utility/img/emoticon/'))); $decoda->setEngine(new CakeEngine($settings['helpers'])); $this->_decoda = $decoda; }