/** * Constructor */ public function __construct($data = array()) { if ($this->limit === null) { $config = new Config(); $this->limit = $config->getConfig('application/display_limit'); $thisClass = get_class($this); $thisClass = str_replace("App\\Model\\", "", $thisClass); $this->config = $config->readConfigFile('conf.d/table/' . $thisClass . '.yml'); $this->table = $this->config['name']; $this->thisClass = $thisClass; $primaryKeys = array(); foreach ($this->config['columns'] as $k => $v) { if (isset($v['primary_key']) && $v['primary_key'] === true) { $primaryKeys[] = $k; } } if (count($primaryKeys) > 1) { $this->primaryKey = $primaryKeys; } else { $this->primaryKey = $primaryKeys[0]; } } $this->db = new Database(); foreach ($data as $obj => $value) { if (array_key_exists($obj, $this->config['columns'])) { $objName = 'set' . $this->underscoreToCamelCase($obj, true); $this->{$objName}($value); } } }
function __construct() { if ($this->defaultController === null) { $config = new Config(); $defaultRoute = $config->getConfig('application/defaultRoute'); $arrayRoute = explode('/', $defaultRoute); $this->defaultController = $arrayRoute[0]; $this->defaultMethod = $arrayRoute[1]; } if (isset($_SERVER['QUERY_STRING'])) { $this->pathRoute($_SERVER['QUERY_STRING']); } else { $this->defaultRoute(); } }
public function __construct() { if ($this->dsn === null) { $config = new Config(); $dbConfig = $config->getConfig('database'); $this->databaseType = $dbConfig['type']; $this->databaseHost = $dbConfig['host']; $this->databaseUser = $dbConfig['user']; $this->databasePassword = $dbConfig['password']; $this->databasePort = $dbConfig['port']; $this->databaseName = $dbConfig['name']; $this->dsn = $this->databaseType . ":host=" . $this->databaseHost . ";port=" . $this->databasePort . ";dbname=" . $this->databaseName; } if ($this->pdo === null) { $this->connect(); } }
<?php /** * Transformatika Framework */ use Transformatika\Config\Config; use Transformatika\MVC\RouteDispatcher; Config::init(array('configExt' => 'yaml')); /* * Environment Setup */ if (Config::getConfig('env') === 'dev') { error_reporting(E_ALL); ini_set('display_errors', 'On'); } else { error_reporting(0); ini_set('display_errors', 'Off'); } /* * Initializing Propel ORM */ if (Config::getConfig('usePropel') == 'true' || Config::getConfig('usePropel') === true) { require_once 'propel.php'; } $router = new RouteDispatcher(Config::readConfigFile('routing.yaml')); $router->dispatch();
public function __construct() { if ($this->config === null) { $this->config = Config::getConfig(); } }
/** * Too many bugs!!! * may deleted soon!! * * @param [type] $data [description] * @param string $table [description] * @return [type] [description] */ public function responseFilter($data, $table = '') { /* suka lupa ini object nya propel */ if (is_object($data)) { $data = $data->toArray(); } if ($table === '' && empty(static::DEFAULT_TABLE)) { return $data; } elseif ($table === '' && !empty(static::DEFAULT_TABLE)) { $table = static::DEFAULT_TABLE; } $excludeFields = Config::getConfig('excludeFields'); if (!in_array($table, $excludeFields)) { return $data; } else { $tempData = $data; if (isset($tempData[0])) { // MULTIDIMENTIAL ARRAY foreach ($tempData as $k => $v) { foreach ($v as $index => $value) { if (is_array($value)) { $tempData[$k][$index] = $this->responseFilter($value, $index); } else { foreach ($excludeFields[$table] as $exKey => $exVal) { unset($tempData[$k][$exVal]); } } } } } else { // SINGLE ARRAY foreach ($tempData as $index => $value) { if (is_array($value)) { $tempData[$k][$index] = $this->responseFilter($value, $index); } else { foreach ($excludeFields[$table] as $exKey => $exVal) { unset($tempData[$k][$exVal]); } } } } return $tempData; } }
<?php /** * This file is used by phpunit * usage: vendor/bin/phpunit --bootstrap src/phpunit.php src/ */ define('DS', DIRECTORY_SEPARATOR); define('BASE_PATH', realpath(dirname(__FILE__) . DS . '..')); require_once BASE_PATH . DS . 'vendor' . DS . 'autoload.php'; \Transformatika\Config\Config::init(array('configExt' => 'yaml')); if (\Transformatika\Config\Config::getConfig('usePropel') == 'true' || \Transformatika\Config\Config::getConfig('usePropel') === true) { require_once dirname(__FILE__) . DS . 'propel.php'; }
public function dispatch() { $httpMethod = $this->request->getMethod(); $baseUrl = Config::getConfig('basePath'); $uri = $this->request->getUri()->getPath(); $uri = substr($uri, strlen($baseUrl)); $uri = empty($uri) ? '/' : $uri; if ($uri !== '/' && substr($uri, -1) == '/') { $uri = substr($uri, 0, -1); } $routeInfo = $this->dispatcher->dispatch($httpMethod, $uri); switch ($routeInfo[0]) { case \FastRoute\Dispatcher::NOT_FOUND: if (!empty($this->redirectUrl[404])) { header('location: ' . $this->redirectUrl[404]); } else { header('HTTP/1.1 404 Not Found'); header('Content-Type: text/plain'); echo "HTTP/1.1 404 Not Found\n"; echo "Content-Type: text/plain\n"; echo "\n"; echo "Page Not Found"; echo "\n"; } exit; break; case \FastRoute\Dispatcher::METHOD_NOT_ALLOWED: if (!empty($this->redirectUrl[405])) { header('location: ' . $this->redirectUrl[405]); } else { header('HTTP/1.1 405 Method Not Allowed'); header('Content-Type: text/plain'); echo "HTTP/1.1 405 Method Not Allowed\n"; echo "Content-Type: text/plain\n"; echo "\n"; echo "Method Not Allowed"; echo "\n"; } exit; break; case \FastRoute\Dispatcher::FOUND: if (null !== $this->middleWare && class_exists($this->middleWare)) { $md = new $this->middleWare(); $md($this->request); } foreach ($routeInfo[2] as $k => $v) { $this->request = $this->request->withAttribute($k, $v); } $explodeController = explode('#', $routeInfo[1]); $actionClass = $explodeController[0]; $controller = new $actionClass(); $data = $controller($explodeController[1], $this->request); $defaultResponse = Config::getConfig('response'); $responseArray = ['json' => 'application/json', 'html' => 'text/html', 'text' => 'text/plain']; if (!isset($data['headers']) || !isset($data['headers']['Content-Type'])) { $data['headers']['Content-Type'] = $responseArray[$defaultResponse]; } if ($data['headers']['Content-Type'] === 'application/json') { foreach ($data['headers'] as $hKey => $hVal) { header($hKey . ":" . $hVal); } echo json_encode($data); } else { if (isset($data['redirect']) && $data['redirect'] === true) { if (!isset($data['headers']['location'])) { throw new \Exception("Invalid headers. Headers location must be set", 1); } else { header('location:' . $data['headers']['location']); } } else { if (!isset($data['template'])) { throw new \Exception("Template Configuration Not Found", 1); } foreach ($data['headers'] as $hKey => $hVal) { header($hKey . ":" . $hVal); } $controller->display($data['template'], $data); } } break; } }