Overview

Namespaces

  • App
    • Components
    • Interfaces
    • Lib
      • Files
      • Forms
        • Controls
      • Html
      • Repair
      • Statics
    • Model
    • Modules
      • BaseModule
        • Presenters
      • PartnersModule
        • Presenters
      • ProductModule
        • Presenters
      • SaleModule
        • Model
        • Presenters
      • SettingsModule
        • Model
        • Presenters
      • StoreModule
        • Model
        • Presenters
    • Presenters
    • Router
  • PHP

Classes

  • DateTime
  • SplFileInfo

Interfaces

  • ArrayAccess
  • Countable
  • Exception
  • Iterator
  • Traversable
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Download
  1: <?php
  2: 
  3: /**
  4:  * Project sberp
  5:  *
  6:  * @file Files 
  7:  * @author Jaromír Polášek
  8:  * @version 0.2.1
  9:  * Encoding UTF-8
 10:  */
 11: 
 12: namespace App\Lib\Files;
 13: 
 14: use Nette,
 15:     Nette\Utils\Finder,
 16:     Nette\Utils\Arrays,
 17:     Nette\Utils\FileSystem;
 18: 
 19: /**
 20:  * Třída pro vyhledávání souboru. Vytváří pole, které uchovává informace o nalezených souborech
 21:  * Je li vytvořena, není potřeba ji vytvářet znovu. stačí přidávat další soubory
 22:  * Zdroje: 
 23:  * @link http://php.net/SplFileInfo
 24:  * @link http://api.nette.org/2.2.7/Nette.Utils.FileSystem.html
 25:  * @link http://doc.nette.org/cs/2.2/arrays
 26:  */
 27: class Files extends Finder {
 28: 
 29:     /** Pole nalezaných souborů
 30:      * @var array */
 31:     private $source = array();
 32: 
 33:     /**
 34:      * Konstruktor s parametry je předá setSource
 35:      * @param string $dir
 36:      * @param string $mask
 37:      */
 38:     public function __construct($dir = null, $mask = null) {
 39:     (!is_null($dir)) ? $this->setSource($dir, $mask) : $this->source = null;
 40:     }
 41: 
 42:     /**
 43:      * Vrací pole Object SplFileInfo
 44:      * @return array (SplFileInfo)
 45:      */
 46:     public function getSource() {
 47:     return $this->source;
 48:     }
 49: 
 50:     /**
 51:      * Přidá do pole objektů SplFileInfo další nalezené objekty v adresáři $dir
 52:      * @param string $dir
 53:      * @param string $mask
 54:      */
 55:     public function setSource($dir, $mask) {
 56:     foreach (Finder::findFiles($mask)->in($dir) as $name => $info) {
 57:         $this->source[$name] = $info;
 58:     }
 59:     }
 60: 
 61:     /**     
 62:      * Uloží soubor na disk. Vrací kódy: 0==OK,1==IOError,2==cesta/zapisovatelnost, 3==špatný argument 
 63:      * @deprecated since version 0.7.1.FORM
 64:      * @param string $name
 65:      * @param string $data
 66:      * @param integer $mode
 67:      * @return integer (0,1,2,3)
 68:      */
 69:     public function save($name, $data, $mode = null) {
 70:     try {
 71:         return $this->write((Arrays::get($this->source, $name)), $data, $mode);
 72:     } catch (Nette\InvalidArgumentException $e) {
 73:         return 3;
 74:     }
 75:     }
 76: 
 77:     /**     
 78:      * Uloží soubor na disk. Vrací kódy: 0==OK,1==IOError,2==cesta/zapisovatelnost 
 79:      * @deprecated since version 0.7.1.FORM
 80:      * @param \SplFileInfo $SplFileInfo
 81:      * @param string $data
 82:      * @param integer $mode
 83:      * @return integer (0,1,2)
 84:      */
 85:     private function write($SplFileInfo, $data, $mode = null) {
 86:     (!is_null($mode))? : $mode = 0600;
 87:     $path = $SplFileInfo::getRealPath;
 88:     if (FileSystem::absolute($path) && $SplFileInfo::isWritable) {
 89:         try {
 90:         Filesystem::write($path, $data, 0640);
 91:         } catch (IOException $e) {
 92:         //Nette\DirectoryNotFoundException, Nette\FileNotFoundException
 93:         return 1;
 94:         }
 95:         return 0;
 96:     }return 2;
 97:     }
 98: 
 99: }
100: 
sberp API API documentation generated by ApiGen