Beispiel #1
0
 /**
  * Creates a file and puts the text in it; if the file exists, the content is overwritten.
  * @param string $path
  * @param string $text 
  */
 static function CreateWithText($path, $text)
 {
     $dir = Path::Directory($path);
     if (!Folder::Exists($dir)) {
         Folder::Create($dir);
     }
     file_put_contents($path, $text);
 }
 private function PrepareTargetFolder()
 {
     if (Folder::Exists($this->targetFolder)) {
         Folder::Delete($this->targetFolder);
     }
     Folder::Create($this->targetFolder, 0777);
     if (!Folder::Exists($this->targetFolder)) {
         throw new \Exception('TargetFolder not found and could not be created');
     }
     //TODO: !!Clear Folder!!
 }
Beispiel #3
0
 /**
  * Gets all modules in a bundle
  * @param string $bundleName
  * @param ModuleLocation $location Backend or frontend
  * @return string[] Returns the module names
  */
 static function Modules($bundleName, ModuleLocation $location)
 {
     $result = array();
     $modulesFolder = Path::Combine(self::BundleFolder($bundleName), 'Modules');
     $folder = Path::Combine($modulesFolder, (string) $location);
     $files = Folder::GetFiles($folder);
     foreach ($files as $file) {
         $result[] = Path::RemoveExtension($file);
     }
     return $result;
 }
Beispiel #4
0
 /**
  * Gets the module templates
  * @param FrontendModule $module The frontend module
  * @return string[] Returns the template files 
  */
 protected function ModuleTemplates($module)
 {
     $folder = PathUtil::ModuleCustomTemplatesFolder($module);
     if (!Folder::Exists($folder)) {
         return array();
     }
     $templates = Folder::GetFiles($folder);
     $result = array();
     foreach ($templates as $template) {
         if (Path::Extension($template) == 'phtml') {
             $result[] = Path::RemoveExtension($template);
         }
     }
     return $result;
 }
 /**
  * Checks if the file given in the value doesn't exist yet
  * @param string $value The value to check
  * @return boolean True id check passed
  */
 public function Check($value)
 {
     $this->error = '';
     if ($this->currentFile && $value == $this->currentFile) {
         return true;
     }
     if (!Folder::Exists($this->folder)) {
         return true;
     }
     $files = Folder::GetFiles($this->folder);
     if ($this->fileExtension) {
         $value = Path::AddExtension($value, $this->fileExtension);
     }
     if (in_array($value, $files)) {
         $this->error = self::ExistsInFolder;
     }
     return $this->error == '';
 }
Beispiel #6
0
 /**
  * Saves the template into the given file name
  */
 protected function OnSuccess()
 {
     $newTemplate = $this->Value('Name');
     $action = Action::Create();
     if ($this->template) {
         $action = Action::Update();
         $this->UpdateUsages($newTemplate);
         $oldFile = $this->CalcFile($this->template);
         if (File::Exists($oldFile)) {
             File::Delete($oldFile);
         }
     }
     $logger = new Logger(self::Guard()->GetUser());
     $logger->ReportTemplateAction($this->module->MyType(), $newTemplate, $action);
     if (!Folder::Exists($this->folder)) {
         Folder::Create($this->folder);
     }
     File::CreateWithText($this->CalcFile($newTemplate), $this->Value('Contents', false));
     Response::Redirect($this->BackLink());
 }
Beispiel #7
0
 /**
  * Adds the template select field
  * @param FrontendModule $module The module for template selection
  */
 protected final function AddTemplateField()
 {
     $name = 'Template';
     $field = new Select($name, (string) $this->Content()->GetTemplate());
     $field->AddOption('', Trans("Core.ContentForm.{$name}.Default"));
     $folder = PathUtil::ModuleCustomTemplatesFolder($this->FrontendModule());
     if (Folder::Exists($folder)) {
         $files = Folder::GetFiles($folder);
         foreach ($files as $file) {
             $value = Path::FilenameNoExtension($file);
             $field->AddOption($value, $value);
         }
     }
     $this->AddField($field, false, Trans("Core.ContentForm.{$name}"));
 }
 /**
  * 
  * @return string
  * @throws \Exception Raises exception if engine is not supported
  */
 private function FindEngineFolder()
 {
     $bundle = $this->manifest->BundleName();
     $sqlFolder = PathUtil::InstallationSqlFolder($bundle);
     if (!Folder::Exists($sqlFolder) || Folder::IsEmpty($sqlFolder)) {
         return '';
     }
     $engine = (string) $this->connection->Engine();
     $engineFolder = Path::Combine($sqlFolder, $engine);
     if (!Folder::Exists($engineFolder)) {
         throw new \Exception("Bundle {$bundle} doesn't support your database engine '{$engine}'");
     }
     return $engineFolder;
 }