Example #1
0
 /**
  * @see \TranslatorTools\I18n\Translator\Writer\FileWriterInterface::write()
  * @param array $aMessages
  * @param string $sFilename
  * @throws \InvalidArgumentException
  * @return \TranslatorTools\I18n\Translator\Writer\Ini
  */
 public function write(array $aMessages, $sFilename)
 {
     $aTempMessages = array();
     foreach ($aMessages as $sMessage => $sTranslation) {
         $aTempMessages[str_replace('"', '\'', $sMessage)] = str_replace('"', '\'', $sTranslation);
     }
     $aMessages = $aTempMessages;
     if (is_file($sFilename)) {
         if (!is_readable($sFilename)) {
             throw new \InvalidArgumentException(sprintf('Could not open file "%s" for writing', $sFilename));
         }
         $oIniReader = new \Zend\Config\Reader\Ini();
         $aMessagesNamespaced = $oIniReader->fromFile($sFilename);
         $aListMessages = isset($aMessagesNamespaced['translation']) ? $aMessagesNamespaced['translation'] : $aMessagesNamespaced;
         foreach ($aListMessages as $aMessage) {
             if (!is_array($aMessage) || count($aMessage) < 2) {
                 /* TODO remove */
                 error_log('$aMessage : ' . print_r($aMessage, true));
                 throw new \InvalidArgumentException('Each INI row must be an array with message and translation');
             }
             if (isset($aMessage['message']) && isset($aMessage['translation'])) {
                 //Add message only if not given
                 if (!isset($aMessages[$aMessage['message']])) {
                     $aMessages[$aMessage['message']] = $aMessage['translation'];
                 }
                 continue;
             }
             //Add message only if not given
             $sMessage = array_shift($aMessage);
             if (!isset($aMessages[$sMessage])) {
                 $aMessages[$sMessage] = array_shift($aMessage);
             }
         }
     } else {
         $aMessagesNamespaced = null;
     }
     //Sort messages
     ksort($aMessages);
     $aMessagesKeys = array_keys($aMessages);
     $aMessages = array_combine($aMessagesKeys, array_map(function ($sTranslation, $sMessage) {
         return array('message' => $sMessage, 'translation' => $sTranslation);
     }, $aMessages, $aMessagesKeys));
     if (isset($aMessagesNamespaced['translation'])) {
         $aMessagesNamespaced['translation'] = $aMessages;
     } else {
         $aMessagesNamespaced = $aMessages;
     }
     $oIniWriter = new \Zend\Config\Writer\Ini();
     $oIniWriter->toFile($sFilename, $aMessagesNamespaced);
     return $this;
 }
Example #2
0
 public function index2Action()
 {
     // $reader = new \Zend\Config\Reader\Ini();
     // // thay đổi ký tự tạo mảng trong file ini
     // //$reader->setNestSeparator("-");
     // $config = $reader->fromFile(__DIR__."/../../../config/ini/module.config.ini");
     $config = new \Zend\Config\Config(array(), true);
     $config->prodution = array();
     $config->prodution->website = "zing.vn";
     $config->prodution->account = array();
     $config->prodution->account->name = "trongle";
     $config->prodution->account->email = "*****@*****.**";
     $writer = new \Zend\Config\Writer\Ini();
     $writer->setNestSeparator("-");
     $writer->toFile(__DIR__ . "/../../../config/ini/config.ini", $config);
     //return false;
 }
 public function index2Action()
 {
     $reader = new \Zend\Config\Reader\Ini();
     // Cau hinh
     $reader->setNestSeparator('-');
     $data = $reader->fromFile(__DIR__ . '/../../../config/ini/module.config.ini', true);
     $config = new \Zend\Config\Config(array(), true);
     $config->production = array();
     $config->production->website = 'www.zend.vn';
     $config->production->account = array();
     $config->production->account->email = '*****@*****.**';
     $config->production->account->port = 465;
     $writer = new \Zend\Config\Writer\Ini();
     $writer->setNestSeparator('-');
     $writer->toFile(__DIR__ . '/../../../config/ini/config.ini', $config);
     //return false;
 }
Example #4
0
 /**
  * @param string $type
  */
 public function create()
 {
     /* @var $userConfig Zend\Tool\Framework\Client\Config */
     $userConfig = $this->_registry->getConfig();
     $resp = $this->_registry->getResponse();
     if ($userConfig->exists()) {
         throw new RuntimeException("A configuration already exists, cannot create a new one.");
     }
     $homeDirectory = $this->_detectHomeDirectory();
     $writer = new \Zend\Config\Writer\Ini();
     $writer->setRenderWithoutSections();
     $filename = $homeDirectory . "/.zf.ini";
     $config = array('php' => array('include_path' => get_include_path()));
     $writer->write($filename, new \Zend\Config\Config($config));
     $resp = $this->_registry->getResponse();
     $resp->appendContent("Successfully written Zend Tool config.");
     $resp->appendContent("It is located at: " . $filename);
 }
Example #5
0
 /**
  * Get the config writer that corresponds to the current config file type.
  *
  * @return \Zend\Config\Writer\AbstractFileWriter
  */
 protected function getConfigWriter()
 {
     $suffix = substr($this->getConfigFilepath(), -4);
     switch ($suffix) {
         case '.ini':
             $writer = new \Zend\Config\Writer\Ini();
             $writer->setRenderWithoutSections();
             break;
         case '.xml':
             $writer = new \Zend\Config\Writer\Xml();
             break;
         case '.php':
             $writer = new \Zend\Config\Writer\ArrayWriter();
             break;
         default:
             throw new Exception('Unknown config file type ' . $suffix . ' at location ' . $this->getConfigFilepath());
     }
     return $writer;
 }