Vydělávej až 160.000 Kč měsíčně! Akreditované rekvalifikační kurzy s garancí práce od 0 Kč. Více informací.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

DIC

jedinečná instance

php

class Container
{
        private $parameters;
        private $services = array();

        function __construct(array $parameters)
        {
                $this->parameters = $parameters;
        }

        private function createConnection()
        {
                return new PDO(
                        "mysql:host={$this->parameters['host']};dbname={$this->parameters['db']}",
                        $this->parameters['user'],
                        $this->parameters['pass'],
                        $this->parameters['options']
                );
        }

        public function getConnection()
        {
                if (!isset($this->services['connection']))
                        $this->services['connection'] = $this->createConnection();
                return $this->services['connection'];
        }

        public function createGallery()
        {
                return new Gallery($this->getConnection());
        }

        private function __clone(){}

}

Neformátovaný

Přidáno: 4.12.2013
Expirace: Neuvedeno

Avatar
Autor: Milan Gallas
Aktivity