public function __construct() { if (defined('PHPFOX_NO_APPS')) { return; } $base = PHPFOX_DIR_SITE . 'Apps/'; foreach (scandir($base) as $app) { if ($app == '.' || $app == '..') { continue; } $path = $base . $app . '/'; if (!file_exists($path . 'app.lock')) { continue; } $data = json_decode(file_get_contents($path . 'app.json')); $data->path = $path; if (isset($data->routes)) { self::$routes = array_merge(self::$routes, (array) $data->routes); } $this->_apps[$data->id] = $data; \Core\Route\Controller::$active = $data->path; \Core\Route\Controller::$activeId = $data->id; $vendor = $data->path . 'vendor/autoload.php'; if (file_exists($vendor)) { require_once $vendor; } if (file_exists($data->path . 'start.php')) { require_once $data->path . 'start.php'; } } // d($this->_apps); exit; }
public function get($id = null) { $request = CoreApp::getRequest(); $selectTable = QueryBase::tableizeModelName($this->modelClass); $parsedResources = $this->parseResources($request->getResourceArray()); $queryBase = new QueryBase($this->modelClass); $constraint = new Constraints(); if (empty($id)) { $resourceArray = $request->getResourceArray(); $id = $resourceArray[count($resourceArray) - 1]; } $queryBase->Select(); if (!empty($parsedResources['joins'])) { $joinsArray = array_map("core\\Inflector::tableize", $parsedResources['joins']); $queryBase->Join($joinsArray); } $constraint->term("{$selectTable}" . ".id", "=", $id); if (!empty($parsedResources['constraints'])) { foreach ($parsedResources['constraints'] as $kv) { $table = Inflector::tableize($kv->resource) . ".id"; $value = $kv->value; $constraint->andTerm($table, "=", $value); } } $queryBase->Where($constraint); $sql = $queryBase->getSelect(); $bindValues = $queryBase->getBindValues(); if ($this->query($sql, $bindValues)) { return $this->getResultsSet(); } return false; }
public function initTwig() { // incializar la libreria twig $loader = new \Twig_Loader_Filesystem(__DIR__ . '/../App/Views'); // establecer lel objeto twig de manera que desde los controladores se pueda acceder a el self::$twig = new \Twig_Environment($loader); //$this->twig = new \Twig_Environment($loader, array('debug' => true,'cache' => 'cache')); self::$twig->clearCacheFiles(); }
public function __construct($refresh = false) { if (defined('PHPFOX_NO_APPS')) { return; } $base = PHPFOX_DIR_SITE . 'Apps/'; if (!is_dir($base)) { return; } if (self::$_apps !== null && !$refresh) { return; } self::$_apps = []; foreach (scandir($base) as $app) { if ($app == '.' || $app == '..') { continue; } $path = $base . $app . '/'; if (!file_exists($path . 'app.lock')) { continue; } $jsonData = file_get_contents($path . 'app.json'); $jsonData = preg_replace_callback('/{{ ([a-zA-Z0-9_]+) }}/is', function ($matches) use($jsonData) { $_data = json_decode($jsonData); if (!isset($_data->{$matches[1]})) { return $matches[0]; } return $_data->{$matches[1]}; }, $jsonData); $data = json_decode($jsonData); $data->path = $path; if (isset($data->routes)) { foreach ((array) $data->routes as $key => $route) { $route = (array) $route; $route['id'] = $data->id; Route::$routes = array_merge(Route::$routes, [$key => $route]); } } self::$_apps[$data->id] = $data; \Core\Route\Controller::$active = $data->path; \Core\Route\Controller::$activeId = $data->id; $vendor = $data->path . 'vendor/autoload.php'; if (file_exists($vendor)) { require_once $vendor; } if (file_exists($data->path . 'start.php')) { $callback = (require_once $data->path . 'start.php'); if (is_callable($callback)) { $View = new \Core\View(); $View->loader()->addPath($data->path . 'views/', $data->id); call_user_func($callback, $this->get($data->id), $View->env()); } } } // d(self::$_apps); exit; }
/** * Provides basic support for error handling * * @param CoreApp $app * Parent Application * @param CoreAppError $e * Exception caught that caused the error to be processed * * @access public * @return void */ public function onError(CoreApp $app, CoreAppError $e) { $request = Request::getInstance(); $request->referrer = $request->resource; $request->resource = 'error'; if (file_exists($app->getPageFileLocation('action')) && file_exists($app->getPageFileLocation('response'))) { include $app->getPageFileLocation('action'); include $app->getPageFileLocation('response'); } else { $section_id = ''; $error_code = (int) $e->getCode(); $error_message = $e->getMessage(); switch ($error_code) { case 403: header('HTTP/1.1 403 Forbidden'); $error_message = ' 403 Forbidden'; break; case 404: header('HTTP/1.1 404 Not Found'); $error_message = '404 Not Found'; break; default: header('HTTP/1.1 500 Internal Server Error'); $error_message = '500 Internal Server Error '; $error_code = 500; break; } echo '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">' . "\n"; echo '<html>' . "\n"; echo '<head>' . "\n"; echo '<meta content="text/html; charset=UTF-8" '; echo 'http-equiv="content-type">' . "\n"; echo '<title>' . $error_message . '</title>' . "\n"; echo '</head>' . "\n"; echo '<body>' . "\n"; echo '<h1>' . $error_message . '</h1>' . "\n"; echo '</body>' . "\n"; echo '</html>' . "\n"; } }
/** * This method sets and returns an array of values to be used by the ORM. * It will filter API requests and DB requests, setting dependencies to be * handled by the Connectors for each. * * @param array $resourceArray * */ public function parseResources($resourceArray) { $rv = []; $resourcesIterator = new SimpleIterator($resourceArray); $current = $resourcesIterator->current(); while ($next = $resourcesIterator->next()) { $currentType = CoreApp::getResourceType($current); $nextType = CoreApp::getResourceType($next); $currentValid = $this->validateResource($current); if ($currentType == 'controller' && $currentValid) { $rv['joins'][] = $current; } if ($nextType == 'int' && $currentValid) { $rv['constraints'][] = (object) array("resource" => $current, "value" => $next); } $current = $next; } return $rv; }
public static function getAll($resources = null) { if (is_null($resources)) { $resources = CoreApp::getRequest()->getResources(); } $modelClass = self::setModelInstance(); $connector = self::setConnector($modelClass); if (is_null($connector)) { return $connector; } $models = []; $rs = $connector->getAll(); if (is_array($rs)) { foreach ($rs as $row) { $rowModel = self::setModelInstance(); $rowModel->setAttributes($row); $models[] = $rowModel; } } return $models; }
public function __construct() { if (defined('PHPFOX_NO_APPS')) { return; } $base = PHPFOX_DIR_SITE . 'Apps/'; if (!is_dir($base)) { return; } foreach (scandir($base) as $app) { if ($app == '.' || $app == '..') { continue; } $path = $base . $app . '/'; if (!file_exists($path . 'app.lock')) { continue; } $data = json_decode(file_get_contents($path . 'app.json')); $data->path = $path; if (isset($data->routes)) { self::$routes = array_merge(self::$routes, (array) $data->routes); } $this->_apps[$data->id] = $data; \Core\Route\Controller::$active = $data->path; \Core\Route\Controller::$activeId = $data->id; $vendor = $data->path . 'vendor/autoload.php'; if (file_exists($vendor)) { require_once $vendor; } if (file_exists($data->path . 'start.php')) { $callback = (require_once $data->path . 'start.php'); if (is_callable($callback)) { $View = new \Core\View(); $View->loader()->addPath($data->path . 'views/', $data->id); call_user_func($callback, $this->get($data->id), $View->env()); } } } // d($this->_apps); exit; }
private function prepareUpdate() { if (is_null($this->request->getRequestedIds($this->controllerName))) { CoreApp::issue("404"); } else { $this->loadModel(); $this->update(); } }
public function run() { DB::table('core_apps')->delete(); CoreApp::create(array('name' => 'Spinn Labs', 'package_name' => '7699aded6da716dbca47963fdee85c67', 'no_of_installation' => 4, 'owner_id' => 1, 'activated' => 1)); }