Overview

Namespaces

  • GLFramework
    • Cache
    • Controller
    • DaMa
      • Manipulators
    • Database
    • HTTP
    • Mail
    • Middleware
    • Model
    • Module
    • Tests
    • Upload
    • Utils
  • None

Classes

  • GLFramework\Bootstrap
  • GLFramework\Cache\Cache
  • GLFramework\Cache\MemcachedCache
  • GLFramework\Cache\MemoryCache
  • GLFramework\Controller
  • GLFramework\Controller\AdminController
  • GLFramework\Controller\APIController
  • GLFramework\Controller\AuthController
  • GLFramework\Controller\ErrorController
  • GLFramework\Controller\ExceptionController
  • GLFramework\DaMa\Association
  • GLFramework\DaMa\DataManipulation
  • GLFramework\DaMa\Manipulator
  • GLFramework\DaMa\Manipulators\CSVManipulator
  • GLFramework\DaMa\Manipulators\ManipulatorCore
  • GLFramework\DaMa\Manipulators\XLSManipulator
  • GLFramework\DaMa\Manipulators\XLSXManipulator
  • GLFramework\Database\Connection
  • GLFramework\Database\MySQLConnection
  • GLFramework\DatabaseManager
  • GLFramework\DBStructure
  • GLFramework\Events
  • GLFramework\Filesystem
  • GLFramework\HTTP\API
  • GLFramework\Log
  • GLFramework\Mail
  • GLFramework\Mail\Mail
  • GLFramework\Mail\MailSystem
  • GLFramework\Mail\PHPMailer
  • GLFramework\MailView
  • GLFramework\Middleware\APIAuthorizationMiddleware
  • GLFramework\Middleware\ControllerMiddleware
  • GLFramework\Model
  • GLFramework\Model\Page
  • GLFramework\Model\User
  • GLFramework\Model\UserPage
  • GLFramework\ModelResult
  • GLFramework\Module\Module
  • GLFramework\Module\ModuleManager
  • GLFramework\Request
  • GLFramework\Response
  • GLFramework\Tests\DatabaseTestCase
  • GLFramework\Tests\TestCase
  • GLFramework\Upload\Upload
  • GLFramework\Upload\Uploads
  • GLFramework\Utils\DataTablesManager
  • GLFramework\Versions
  • GLFramework\View

Interfaces

  • GLFramework\Middleware

Functions

  • array_merge_recursive_ex
  • e
  • file_get_php_classes
  • fix_date
  • fix_date_format
  • fix_decimal
  • fix_url
  • get
  • get_php_classes
  • http_response_code
  • instance_method
  • is_module_enabled
  • now
  • post
  • print_array
  • print_brief_debug
  • print_debug
  • random_str
  • reArrayFiles
  • reArrayPost
  • today
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /**
  3:  * Created by PhpStorm.
  4:  * User: manus
  5:  * Date: 29/03/16
  6:  * Time: 12:00
  7:  */
  8: 
  9: namespace GLFramework;
 10: 
 11: 
 12: use TijsVerkoyen\CssToInlineStyles\Exception;
 13: 
 14: class Filesystem
 15: {
 16: 
 17:     private $file;
 18: 
 19:     private $pfile;
 20:     /**
 21:      * Generara un gestor de archivos
 22:      * @param $file
 23:      */
 24:     public function __construct($file = null)
 25:     {
 26:         $this->file = $file;
 27:     }
 28: 
 29:     /**
 30:      * Solicita un nuevo archivo con ese nombre y extension, si no se indica un nombre, se genera
 31:      * uno de forma aleatoria.
 32:      * @param null $filename
 33:      * @param string $extension
 34:      * @return Filesystem
 35:      */
 36:     public function allocate($filename = null, $extension = ".rnd")
 37:     {
 38:         if($filename == null)
 39:             $filename = sha1(time() . "_" . microtime(true));
 40:         $file = new Filesystem("{$filename}{$extension}"); //$this->getStorage() . "/{$filename}{$extension}";
 41:         $file->touch();
 42:         return $file;
 43:     }
 44: 
 45:     private function getStorage()
 46:     {
 47:         $folder = $this->getFilesystemFolder();
 48:         if(!is_dir($folder))
 49:         {
 50: 
 51:             if(!mkdir($folder, 0777, true))
 52:             {
 53:                 throw new Exception("Can not create Filesystem folder: '" . $folder . "'. Please verify permissions.");
 54:             }
 55:         }
 56: 
 57:         return $folder;
 58:     }
 59: 
 60:     /**
 61:      * Obtiene la ruta al directorio donde se almacenan los archivos
 62:      * @return string
 63:      */
 64:     public function getFilesystemFolder()
 65:     {
 66: 
 67:         $config = Bootstrap::getSingleton()->getConfig();
 68:         if(isset($config['app']['filesystem']))
 69:         {
 70:             return $config['app']['filesystem'];
 71:         }
 72:         return "filesystem";
 73:     }
 74: 
 75:     /**
 76:      * Obtiene la ruta relativa al archivo
 77:      * @return string
 78:      * @throws Exception
 79:      */
 80:     public function getFilePath()
 81:     {
 82:         return $this->getStorage() . "/" . $this->file;
 83:     }
 84: 
 85:     /**
 86:      * Obtiene la rut absoluta al archivo
 87:      * @return string
 88:      * @throws Exception
 89:      */
 90:     public function getAbsolutePath()
 91:     {
 92:         return realpath($this->getStorage()) . "/" . $this->file;
 93:     }
 94: 
 95:     /**
 96:      * Crea el archivo vacio
 97:      * @return bool
 98:      */
 99:     public function touch()
100:     {
101:         return touch($this->getAbsolutePath());
102:     }
103: 
104:     /**
105:      * Devuelve true si existe el archivo
106:      * @return bool
107:      */
108:     public function exists()
109:     {
110:         return file_exists($this->getAbsolutePath());
111:     }
112: 
113:     /**
114:      * Obtiene una url accesible por el navegador
115:      * @return string
116:      */
117:     public function url()
118:     {
119:         $scheme = "http://";
120:         if($_SERVER['HTTPS']) $scheme = "https://";
121:         return $scheme . $_SERVER['HTTP_HOST'] . "/" . $this->getFilePath();
122:     }
123: 
124:     /**
125:      * Abrir un archivo, devuelve el puntero al archio
126:      * @param string $mode
127:      * @return resource
128:      */
129:     public function open($mode = "rw")
130:     {
131:         return ($this->pfile = fopen($this->getAbsolutePath(), $mode));
132:     }
133: 
134:     /**
135:      * Cierra el Ășltimo puntero abiero
136:      * @return bool
137:      */
138:     public function close()
139:     {
140:         return fclose($this->pfile);
141:     }
142: 
143:     /**
144:      * Leer el contenido del archivo. No se requiere ejecutar open() ni close()
145:      * @return string
146:      */
147:     public function read()
148:     {
149:         return file_get_contents($this->getAbsolutePath());
150:     }
151: 
152:     /**
153:      * Escribir el contenido al archivo. No se requiere ejecutar open() ni close()
154:      * @param $content
155:      * @return int
156:      */
157:     public function write($content)
158:     {
159:         return file_put_contents($this->getAbsolutePath(), $content);
160:     }
161: 
162: }
API documentation generated by ApiGen