1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace FD3\DevOps;
- use \FilesystemIterator;
- class FileSystem {
- protected $path;
- function __construct ($path = "."){
- $this->path = $path;
- }
-
- function dirExists($mode = 0777, $recursive = true ){
- if(!is_dir($this->path)){
- mkdir($this->path, $mode, $recursive);
- }
- return $this;
- }
- function realPath(){
- return new FileSystem(realpath($this->path));
- }
- function file($name){
- $newpath = $this->path . "/". $name;
- return new FileObject(basename($newpath), new FileSystem(dirname($newpath)));
- }
- function getPath(){ return $this->path; }
- }
- use WriteiniFile\WriteiniFile;
- class FileObject{
- protected $fileName;
- protected $context;
- function __construct($fileName, FileSystem $fs = null){
- $this->fileName = $fileName;
- if(!$fs){
- $fs = new FileSystem(getcwd());
- }
- $this->context = $fs;
- }
- function getPath(){
- return $this->context->dirExists()->realpath()->getPath() . "/".$this->fileName;
- }
- function content($content){
- $full_path = $this->getPath();
- file_put_contents($full_path, $content);
- return $this;
- }
- function writeIniConfig($config){
- $f = new WriteiniFile($this->getPath());
- $f->create($config);
- $f->write();
- return $this;
- }
- }
|