/** * Migration generator. * * @param string $name Name string. * @param mixed $params Migration parameters. * * @return void */ public static function migration($name, $params) { if (is_array($params)) { $params = array_merge($params, array_slice(func_get_args(), 2)); } else { $params = array_slice(func_get_args(), 1); } $migration_name = strtolower($name) . '_' . time(); $tpl_vars = array('migration_name' => self::getMigrationName($migration_name), 'name' => explode('_', $name), 'fields' => array_map(function ($item) { return explode(':', $item); }, $params)); $path = Core\Config()->paths('root') . 'db' . DIRECTORY_SEPARATOR . 'migrations' . DIRECTORY_SEPARATOR; $result = self::parseTemplate('migration', $tpl_vars); Helpers\File::putContents($path . $migration_name . '.php', $result); }
static function setAndSaveConfigFile($file, $namespace, $value, $environment = null) { $phppos = strrpos($file, ".php"); $load_name = substr($file, 0, $phppos ? $phppos : strlen($file)); $file_name = $phppos ? $file : $file . '.php'; $env = $environment == null ? Config::getEnvironment() : $environment; $reader = Config::getLoader(); $path = $reader->getPath(null); $data = $reader->load($env, $load_name); if ($namespace == null) { $data = $value; } else { array_set($data, $namespace, $value); } $new_data = "<?php return " . var_export($data, true) . ";"; File::put($path . '/' . $file_name, $new_data); return $new_data; }
/** * Deletes all related file to an attachment. * * @param Base\Model $resource Currently processed resource. * @param string $attachment Attachment file name. * @param string $name Name of the file. * * @access private * @static * * @return void */ private static function deleteThumbnails(Base\Model $resource, $attachment, $name) { $_storage_path = $resource->attachmentsStoragePath($attachment); foreach (self::$attachments[$attachment]['thumbnails'] as $thumbnail) { try { if (file_exists($_storage_path . "{$thumbnail['size']}-{$name}")) { Helpers\File::delete($_storage_path . "{$thumbnail['size']}-{$name}"); } } catch (\Exception $e) { var_log($e->getMessage()); } } }
/** * Copies a directory to another destination, recursively. * * @param string $from Full or relative path to directory. * @param string $to Full or relative path to destination directory. * * @uses File::getFullPath To format path to file. * @uses self::create To create a directory. * @uses self::copy To recursively copy subdirectories. * @uses File::copy To copy files to the destination. * * @return boolean If the directory and its contents were copied successfully. */ public static function copy($from, $to) { $from = File::getFullPath($from); /* Create destination directory. */ $copied = self::create($to); /* Open a directory handle. */ $handle = opendir($from); /* Read entries from the directory handle. */ while (($entry = readdir($handle)) !== false) { /* Skip directory handles for current and previous directories. */ if ($entry == '.' || $entry == '..') { continue; } /* Check whether the current entry is a directory and is not a symbolic link */ if (is_dir($from . DIRECTORY_SEPARATOR . $entry) && !is_link($from)) { $copied = self::copy($from . DIRECTORY_SEPARATOR . $entry, $to . DIRECTORY_SEPARATOR . $entry); } else { $copied = File::copy($from . DIRECTORY_SEPARATOR . $entry, $to . DIRECTORY_SEPARATOR . $entry); } } /* Close directory handle */ closedir($handle); return $copied; }
/** * @covers Core\Helpers\File::delete */ public function testDeletingFile() { $this->assertTrue(File::delete($this->baseName)); }
/** * Removes a key-value pair. * * @param string $key Cache key. * * @return boolean */ public function remove($key) { $file = self::storagePath() . self::generateName($key); try { return File::delete($file); } catch (\Exception $e) { var_log($e->getMessage()); return false; } }