Overview

Namespaces

  • Cz
    • InnuDb
      • Adapters

Classes

  • Cz\InnuDb\Adapters\JsonAdapter
  • Cz\InnuDb\Collection
  • Cz\InnuDb\InnuDb
  • Cz\InnuDb\Loader

Exceptions

  • Cz\InnuDb\CollectionException
  • Cz\InnuDb\InnuDbException
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 
<?php
    /**
     * CzProject Innu DB
     *
     * @author      Jan Pecha, <janpecha@email.cz>
     */

    namespace Cz\InnuDb;
    use Nette;

    class Loader
    {
        protected $adapters = array(
            'php' => 'Nette\Config\Adapters\PhpAdapter',
            'ini' => 'Nette\Config\Adapters\IniAdapter',
            'neon' => 'Nette\Config\Adapters\NeonAdapter',
            'json' => 'Cz\InnuDb\Adapters\JsonAdapter',
        );



        /**
         * Inspired by Nette Framework
         * @param   string
         * @return  mixed
         */
        public function load($file)
        {
            if(!is_file($file) || !is_readable($file))
            {
                throw new Nette\FileNotFoundException("File '$file' is missing or is not readable.");
            }

            return $this->getAdapter($file)->load($file);
        }



        /**
         * Method from Nette Framework
         * @author  David Grudl, Nette Foundation, Nette Community
         * @param   string
         * @param   mixed
         * @return  void
         */
        public function save($file, $data)
        {
            if(file_put_contents($file, $this->getAdapter($file)->dump($data)) === FALSE)
            {
                throw new Nette\IOException("Cannot write file '$file'.");
            }
        }



        /**
         * Method from Nette Framework
         * @author  David Grudl, Nette Foundation, Nette Community
         * @param   string
         * @param   string|Nette\Config\IAdapter
         * @return  Loader  provides a fluent interface
         */
        public function addAdapter($extension, $adapter)
        {
            $this->adapters[strtolower($extension)] = $adapter;
            return $this;
        }



        /**
         * Method from Nette Framework
         * @author  David Grudl, Nette Foundation, Nette Community
         * @param   string
         * @return  Nette\Config\IAdapter
         */
        private function getAdapter($file)
        {
            $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));

            if(!isset($this->adapters[$extension]))
            {
                throw new Nette\InvalidArgumentException("Unknown file extension '$file'.");
            }

            return is_object($this->adapters[$extension]) ? $this->adapters[$extension] : new $this->adapters[$extension];
        }
    }

czproject/innudb master API documentation API documentation generated by ApiGen