/** * @param string $language * @param string $application Backend or Frontend */ public function buildCache($language, $application) { // get types $this->types = $this->database->getEnumValues('locale', 'type'); $this->locale = $this->getLocale($language, $application); $this->dumpJsonCache($language, $application); }
/** * Build the language files * * @return void * @param SpoonDatabase $db The database connection instance. * @param string $language The language to build the locale-file for. * @param string $application The application to build the locale-file for. */ public function buildCache(SpoonDatabase $db, $language, $application) { // get types $types = $db->getEnumValues('locale', 'type'); // get locale for backend $locale = (array) $db->getRecords('SELECT type, module, name, value FROM locale WHERE language = ? AND application = ? ORDER BY type ASC, name ASC, module ASC', array((string) $language, (string) $application)); // start generating PHP $value = '<?php' . "\n"; $value .= '/**' . "\n"; $value .= ' *' . "\n"; $value .= ' * This file is generated by the Installer, it contains' . "\n"; $value .= ' * more information about the locale. Do NOT edit.' . "\n"; $value .= ' * ' . "\n"; $value .= ' * @author Installer' . "\n"; $value .= ' * @generated ' . date('Y-m-d H:i:s') . "\n"; $value .= ' */' . "\n"; $value .= "\n"; // loop types foreach ($types as $type) { // default module $modules = array('core'); // continue output $value .= "\n"; $value .= '// init var' . "\n"; $value .= '$' . $type . ' = array();' . "\n"; $value .= '$' . $type . '[\'core\'] = array();' . "\n"; // loop locale foreach ($locale as $i => $item) { // types match if ($item['type'] == $type) { // new module if (!in_array($item['module'], $modules)) { $value .= '$' . $type . '[\'' . $item['module'] . '\'] = array();' . "\n"; $modules[] = $item['module']; } // parse if ($application == 'backend') { $value .= '$' . $type . '[\'' . $item['module'] . '\'][\'' . $item['name'] . '\'] = \'' . str_replace('\\"', '"', addslashes($item['value'])) . '\';' . "\n"; } else { $value .= '$' . $type . '[\'' . $item['name'] . '\'] = \'' . str_replace('\\"', '"', addslashes($item['value'])) . '\';' . "\n"; } // unset unset($locale[$i]); } } } // close php $value .= "\n"; $value .= '?>'; // store SpoonFile::setContent(PATH_WWW . '/' . $application . '/cache/locale/' . $language . '.php', $value); }
/** * @depends testExecute */ public function testGetEnumValues() { $this->assertEquals(array('Y', 'N'), $this->db->getEnumValues('users', 'developer')); }