├── .gitignore ├── src └── fg │ └── Bambam │ ├── Config │ ├── ConfigInterface.php │ └── Config.php │ ├── Base │ ├── Controller.php │ └── View.php │ ├── Exception │ └── ThemeException.php │ ├── Service │ └── AbstractService.php │ └── Bambam.php └── composer.json /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | .idea -------------------------------------------------------------------------------- /src/fg/Bambam/Config/ConfigInterface.php: -------------------------------------------------------------------------------- 1 | container = $container; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fg/bambam-core", 3 | "description": "Bambam blog system core", 4 | "license": "MIT License", 5 | "authors": [ 6 | { 7 | "name": "Fatih GÜRSOY", 8 | "email": "fatihgursoy@ymail.com" 9 | } 10 | ], 11 | "require": { 12 | "php": ">=5.3.3", 13 | "slim/slim": "2.6.2", 14 | "slimcontroller/slimcontroller": "0.4.3", 15 | "petrgrishin/array-access": "~2.0", 16 | "symfony/yaml": "2.6.7" 17 | }, 18 | "autoload": { 19 | "psr-0": { 20 | "Bambam" : "src/fg" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/fg/Bambam/Base/View.php: -------------------------------------------------------------------------------- 1 | setThemePath($themePath); 17 | 18 | return $this; 19 | } 20 | 21 | private function setThemePath($themePath) 22 | { 23 | if (! is_dir(APP_BASE_PATH . '/themes/' . $themePath)) { 24 | throw new ThemeException('Theme folder is not defined.'); 25 | } 26 | 27 | $this->themePath = $themePath; 28 | $this->setTemplatesDirectory(APP_BASE_PATH . '/themes/' . $themePath); 29 | } 30 | 31 | public function getThemePath() 32 | { 33 | return $this->themePath; 34 | } 35 | } -------------------------------------------------------------------------------- /src/fg/Bambam/Config/Config.php: -------------------------------------------------------------------------------- 1 | values = ArrayAccess::create($values); 18 | $this->configPath = $configPath; 19 | } 20 | 21 | public static function fromYaml($configPath) { 22 | if (!empty($configPath) && file_exists($configPath)) { 23 | $file = file_get_contents($configPath); 24 | $fileParams = Yaml::parse($file); 25 | if (is_array($fileParams)) { 26 | return new static($fileParams, $configPath); 27 | }else throw new \RuntimeException(sprintf('File \'%s\' must be valid YML!', $configPath)); 28 | }else throw new \InvalidArgumentException(sprintf('Config path \'%s\' must be a file!', $configPath)); 29 | } 30 | 31 | public static function fromPhp($configPath) { 32 | if (!empty($configPath) && file_exists($configPath)) { 33 | $fileParams = require($configPath); 34 | if (is_array($fileParams)) { 35 | return new static($fileParams, $configPath); 36 | }else throw new \RuntimeException(sprintf('File \'%s\' must be valid PhpArray Format!'), $configPath); 37 | }else throw new \InvalidArgumentException(sprintf('Config path \'%s\' must be a file!', $configPath)); 38 | } 39 | 40 | public function getConfigPath() { 41 | return $this->configPath; 42 | } 43 | 44 | public function getValues() { 45 | return $this->values; 46 | } 47 | } -------------------------------------------------------------------------------- /src/fg/Bambam/Bambam.php: -------------------------------------------------------------------------------- 1 | app = $app; 18 | $this->config = new Config($config); 19 | $this->init(); 20 | } 21 | 22 | public function init() 23 | { 24 | $this->initServices(); 25 | $this->setApplicationRoute(); 26 | } 27 | 28 | private function initServices() 29 | { 30 | try { 31 | $serviceConfig = $this->config->getValues()->getValue('services'); 32 | 33 | foreach ($serviceConfig as $key => $service) { 34 | if (isset($service['class']) && !empty($service['class']) && class_exists($service['class'])) { 35 | $type = (isset($service['type']) && $service['type'] == 'singleton') ? 'singleton' : 'closure'; 36 | if ($type == 'singleton') { 37 | $this->app->container->singleton($key, function() use ($service) { 38 | return new $service['class']($this->app->container, $service); 39 | }); 40 | } 41 | } 42 | } 43 | 44 | } catch(ArrayAccessException $e) { 45 | 46 | } 47 | } 48 | 49 | private function setApplicationRoute() { 50 | try { 51 | $cleanRoutes = []; 52 | $routeConfig = $this->config->getValues()->getValue('routes'); 53 | foreach ($routeConfig as $route) { 54 | $cleanRoutes[$route['route']] = $route['action']; 55 | } 56 | $this->app->addRoutes($cleanRoutes); 57 | } catch (ArrayAccessException $e) { 58 | 59 | } catch (\Exception $e) { 60 | 61 | } 62 | } 63 | 64 | public function run() { 65 | $this->app->run(); 66 | } 67 | 68 | /** 69 | * @return string 70 | */ 71 | public function getVersion() 72 | { 73 | return $this->version; 74 | } 75 | } --------------------------------------------------------------------------------