/**
  *
  * @param array $params
  * @param string $posts
  */
 public function processRequest(array $params = null, $posts = null)
 {
     try {
         if (isset($posts['data']['current'])) {
             $this->setPath(self::ASSET_PATH . DS . str_replace('_', DS, $posts['data']['current']));
         }
         $filter = new Prepare();
         $ident = Name::get($posts['data']['ident']);
         if ('php' === Extension::get($posts['data']['filename'])) {
             $filename = Name::get($posts['data']['filename']);
         } else {
             $filename = $posts['data']['filename'];
         }
         $this->setDestination($this->getPath() . DS . $filename . '.php');
         if (!is_file($this->getStorage()->getDocumentRoot() . DS . $this->getDestination())) {
             if (is_writable($this->getStorage()->getDocumentRoot() . DS . $this->getPath())) {
                 $dir = $this->getStorage()->getDocumentRoot() . DS . $this->getPath();
                 $filecontent = file_get_contents($dir . DS . $ident . '.php');
                 file_put_contents($dir . DS . $filename . '.php', str_replace($ident, $filename, $filecontent));
                 return array('success' => true);
             } else {
                 return array('error' => 'no_write_permissions');
             }
         } else {
             return array('warn' => 'file_exist');
         }
     } catch (\Exception $e) {
         return array('error' => $e->getMessage());
     }
 }
 /**
  * Prepare datas before save
  *
  * @see \ContentinumComponents\Mapper\Process::save()
  */
 public function save($datas, $entity = null, $stage = '', $id = null)
 {
     $filter = new Prepare();
     //
     $filename = $this->getStorage($this->getSl()->get('contentinum_files_storage_manager'))->getDocumentRoot() . DS . $this->entity->getCurrentPath();
     $filename .= DS . $filter->filter(Name::get($datas['name'])) . '.' . Extension::get($datas['name']);
     file_put_contents($filename, $datas['content']);
 }
 /**
  * 
  * @param unknown $filename
  */
 protected function delCacheFile($filename)
 {
     try {
         $this->getStorage()->delete($this->getDocumentRoot() . self::ASSET_CACHE_PATH . DS . 'lastmodifiedstamp' . Name::get($filename));
     } catch (\Exception $e) {
         $e->getMessage();
     }
 }
 /**
  * Get result from cache or read from php file
  *
  * @param string $file path to file and filename
  * @param string $key template file ident
  * @param ServiceLocatorInterface $sl            
  */
 protected function getFileAsConfig($dir, $key, $sl)
 {
     $result = array();
     foreach (scandir($dir) as $file) {
         if ('.' != $file && '..' != $file) {
             $result['data/assets/collections/' . $file] = Name::get($file);
         }
     }
     return $result;
 }
 /**
  * Get result from cache or read from php file
  *
  * @param string $file path to file and filename
  * @param string $key template file ident
  * @param ServiceLocatorInterface $sl
  */
 protected function getFileAsConfig($dir, $key, $sl)
 {
     $result = array();
     foreach (scandir($dir) as $file) {
         if ('.' != $file && '..' != $file) {
             $file = Name::get($file);
             $result['app/templates/' . $file] = ucfirst($file);
         }
     }
     return $result;
 }
 /**
  *
  * @param string $newName
  * @param string $type
  */
 public function setNewName($newName, $type = 'file')
 {
     $this->newName = $newName;
     if ('file' == $type) {
         $this->ext = '.' . Extension::get($newName);
         $newName = Name::get($newName);
     }
     $this->validNewName = $this->filterFsNames($newName);
 }
 /**
  *
  * @param unknown $filename
  * @return Ambigous <string, mixed>
  */
 public function fileName($filename)
 {
     return \ContentinumComponents\File\Name::get($filename);
 }