.gitignore000064400000000326144761607160006551 0ustar00/vendor/ /tests/ composer.lock /config.json /app/* !/app/.htaccess !/app/INSTRUCTIONS.txt cache/* !cache/smarty cache/smarty/* !cache/smarty/cache !cache/smarty/compiled cache/smarty/cache/* cache/smarty/compiled/*.htaccess000064400000000570144761607160006360 0ustar00 Require all denied Require all denied Require all denied Require all denied Require all denied Require all denied README.md000064400000000007144761607160006034 0ustar00# dhfw app/.htaccess000064400000000015144761607160007132 0ustar00Deny from allapp/INSTRUCTIONS.txt000064400000001114144761607160010042 0ustar00\baseNamespace is configured in config.json defaults to \FWAPP If you change the baseNamespace, be sure to update composer.json for autoloading Directory structure and namespace structure should follow modulename/ -- Namespace: \baseNamespace\modulename Module.php views/ -- Namespace: \baseNamespace\modulename\views ListView.php Detail.php ... actions/ -- Namespace: \baseNamespace\modulename\actions SomeAction.php ... templates/ ListView.tpl Detail.tpl ... composer.json000064400000001123144761607160007277 0ustar00{ "name": "boru/dhfw", "autoload": { "psr-4": { "boru\\dhfw\\": "src/", "FWAPP\\": "app/" } }, "authors": [ { "name": "Daniel Hayes", "email": "dhayes@boruapps.com" } ], "require": { "boru/dhutils": "*", "boru/dhdb": "*", "boru/dhcli": "*", "boru/dhapi": "*", "boru/dhprocess": "*", "smarty/smarty": "^3" }, "repositories": [ { "type": "composer", "url": "https://satis.boruapps.com" } ] } index.php000064400000000000144761607160006366 0ustar00init.php000064400000000250144761607160006231 0ustar00__DIR__]));public/.htaccess000064400000000467144761607160007643 0ustar00 RewriteEngine On RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule .+ - [L] #RewriteRule ^(.+)/?$ index.php?PATH=$1&%{QUERY_STRING} [L] RewriteRule ^(.+)/?$ index.php?APIREQ=$1&%{QUERY_STRING} [L] public/css/.htaccess000064400000000121144761607160010416 0ustar00Require all denied Require all granted public/img/.htaccess000064400000000156144761607160010412 0ustar00Require all denied Require all granted public/index.php000064400000000132144761607160007652 0ustar00 Require all granted scripts/install.php000064400000002327144761607160010432 0ustar00"DHFW Install Script", "description"=>"Setupa and install DHFW", "script"=>"php -f ".$file->path()." " ]); $dhcli->command( dhCLI::makeCommand([ "command"=>"install", "description"=>"Install DHFW", "opts"=>[ Option::flag( "f", "force" , "Force install"), Option::option("d", "directory", "Directory to install to",true,["default"=>$rootDir]), ], "callback"=>function($result) { $force = isset($result["options"]["force"]) ? $result["options"]["force"] : false; try { Setup::install($result["options"]["directory"],$force); } catch (Exception $e) { echo "Error with install script..\n".$e->getMessage()."\n"; } }, ]) ); $dhcli->process($argv);src/.htaccess000064400000000015144761607160007141 0ustar00Deny from allsrc/AppRouter.php000064400000013316144761607160010005 0ustar00vars = $api->getArgs(); $this->args = new Container($api->getRequest()->body()); $this->parseVars($this->vars); header("Content-Type: application/json"); echo json_encode($this->args,JSON_PRETTY_PRINT); echo "\n\n"; echo json_encode($this->vars,JSON_PRETTY_PRINT); echo "\n\n"; if($this->getModule() !== false) { print_r($this->getModule()->getInfo()); } exit(); } public function get($key,$default=null) { return $this->args->get($key,$default); } public function getVar($key,$default=null) { return $this->vars->get($key,$default); } public function header($key,$default=null) { return $this->api->header($key,$default); } public function getModule() { if(is_null($this->module)) { if(($className = $this->getClassName("Module")) !== false) { $this->module = new $className(); } else { $this->module = new \boru\dhfw\app\basemodule\Module(); } } return $this->module; } public function getView() { if(is_null($this->view)) { if(($className = $this->getClassName("views\\".$this->viewName)) !== false) { $this->module = new $className(); } else { $this->view = new \boru\dhfw\app\basemodule\views\NotFound(); } } return $this->view; } public function getAction() { if(is_null($this->action)) { if(($className = $this->getClassName("actions\\".$this->viewName)) !== false) { $this->module = new $className(); } else { $this->action = new \boru\dhfw\app\basemodule\actions\NotFound(); } } return $this->action; } private function parseVars($vars) { $this->moduleName = $vars->get( "module", null); $this->viewName = $vars->get( "view", null); $this->actionName = $vars->get( "action", null); $this->recordId = $vars->get( "id", null); } private function parseArgs($args=[]) { $this->moduleName = dhGlobal::getVal($args, "module", null); $this->viewName = dhGlobal::getVal($args, "view", null); $this->actionName = dhGlobal::getVal($args, "action", null); $this->recordId = dhGlobal::getVal($args, "id", null); } public function getArgs() { return $this->args; } public function getModuleName() { return $this->moduleName; } public function getViewName() { return $this->viewName; } public function getActionName() { return $this->actionName; } public function getRecordId() { return $this->recordId; } private static $classNameFallbackOrder = [ "{APPNS}\\{MODULE}", "\\boru\\dhfw\\app\\{MODULE}", "{APPNS}\\basemodule", "\\boru\\dhfw\\app\\basemodule", ]; public function getClassName($part=null) { $appns = self::getBaseNS(); $module = $this->moduleName; foreach(static::$classNameFallbackOrder as $classNames) { $className = str_replace("{APPNS}",$appns,$classNames); $className = str_replace("{MODULE}",$module,$className); if(!is_null($part)) { $className .= "\\".$part; } echo "Checking $className\n"; if(class_exists($className)) { return $className; } } return false; } public static function setBaseNS($baseNS) { self::$baseNS = $baseNS; } public static function getBaseNS() { return self::$baseNS; } public static function launch($baseNS=null) { if(is_null($baseNS)) { $baseNS = DHFW::getConfig("baseNamespace","\\FWAPP"); } self::setBaseNS($baseNS); $router = new Router(); $router->add(new Route("mod/id/action", "/{module}/{id}/a/{action}", ["GET","POST"], ["\\boru\\dhfw\\AppRouter","process"])); $router->add(new Route("mod/id/view", "/{module}/{id}/{view}", ["GET","POST"], ["\\boru\\dhfw\\AppRouter","process"])); $router->add(new Route("mod/action", "/{module}/a/{action}", ["GET","POST"], ["\\boru\\dhfw\\AppRouter","process"])); $router->add(new Route("mod/view", "/{module}/{view}", ["GET","POST"], ["\\boru\\dhfw\\AppRouter","process"])); $router->add(new Route("mod", "/{module}", ["GET","POST"], ["\\boru\\dhfw\\AppRouter","process"])); $router->add(new Route("default", "/", ["GET","POST"], ["\\boru\\dhfw\\AppRouter","process"])); $request = API::requestFromGlobals(); $api = new API($request,$router); $response = $api->process(); $response->emit(true); } }src/DHFW.php000064400000004441144761607160006613 0ustar00__DIR__.'/../']); } else { $rootDirectory == Directory::fromInput($rootDirectory); } if(!($rootDirectory instanceof Directory)) { throw new \Exception("DHFW::init() requires a Directory object"); } static::$rootDir = $rootDirectory; static::$config = Config::fromFile(static::dir("config.json")); } // Config shortcuts /** * Get a config value by dot notation, or the entire config array. Returns $default if not found * @param string $key * @param mixed $default * @return mixed */ public static function getConfig($key=null,$default=null) { return static::$config->get($key,$default); } /** * Set a config value by dot notation * @param mixed $key * @param mixed $value * @return Config */ public static function setConfig($key,$value) { return static::$config->set($key,$value); } /** * Save the config file * @return Config */ public static function saveConfig() { return static::$config->save(); } /** * Get the config object * @return Config */ public static function config() { return static::$config; } /** * Get the root directory path string, or a path relative to the root directory * @param mixed $path * @return string */ public static function dir($path=null) { return static::$rootDir->path($path); } public static function install($directory=null,$force=false) { //make sure we're running from cli and not a webserver if(php_sapi_name() !== "cli") { throw new \Exception("DHFW::install() must be run from the command line"); } Setup::install($directory,$force); } }src/FindDir.php000064400000002436144761607160007404 0ustar00 "", "siteName" => "", "baseNamespace" => "\\FWAPP", "db"=>[ "dbtype" => "mysql", "host" => "", "user" => "", "pass" => "", "name" => "" ], ]; public static function checkConfig($configFile) { $config = Config::fromFile($configFile); $updated=false; foreach(static::$defaultConfig as $key=>$value) { if(!$config->has($key)) { $config->set($key,$value); $updated=true; } } if($updated) { $config->save(); } } }src/app/basemodule/Module.php000064400000000317144761607160012206 0ustar00"id", "createdTime"=>"created", "updatedTime"=>"updated", ]; /** * If true, the module will use the table above to store data, otherwise no data will be stored/expected * @var bool */ protected static $isRecordModule = true; /** * The default view to use for this module * @var string */ protected static $defaultView = "ListView"; protected static $hasInit = false; protected static $reflectionClass; public static function initModule() { if(static::$hasInit) { return; } Directory::fromPathString(static::getModuleDirectory(),true,["scan"=>false]); Directory::fromPathString(static::getTemplateDirectory(),true,["scan"=>false]); Directory::fromPathString(static::getViewDirectory(),true,["scan"=>false]); Directory::fromPathString(static::getActionDirectory(),true,["scan"=>false]); static::$hasInit = true; } public static function getModuleDirectory() { static::initModule(); return \boru\dhfw\DHFW::dir("app/".strtolower(static::$moduleName)); } public static function getTemplateDirectory() { return static::getModuleDirectory()."/templates"; } public static function getViewDirectory() { return static::getModuleDirectory()."/views"; } public static function getActionDirectory() { return static::getModuleDirectory()."/actions"; } /** * Get the ReflectionClass for this module * @return ReflectionClass<$this> */ public static function reflectionClass() { if(is_null(static::$reflectionClass)) { static::$reflectionClass = new \ReflectionClass(new static()); } return static::$reflectionClass; } public static function getNamespace() { return static::reflectionClass()->getNamespaceName(); } public static function getNamespacedClassName() { return static::getNamespace()."\\Module"; } public static function getView($viewName) { $className = static::getNamespace()."\\views\\".$viewName; $fallback = "\\FWAPP\\core\\views\\".$viewName; if(class_exists($className)) { return new $className(); } elseif(class_exists($fallback)) { return new $fallback(); }else { return new \FWAPP\core\views\NotFound(); } } public static function getAction($actionName) { $className = static::getNamespace()."\\actions\\".$actionName; $fallback = "\\FWAPP\\core\\actions\\".$actionName; if(class_exists($className)) { return new $className(); } elseif(class_exists($fallback)) { return new $fallback(); }else { return new \FWAPP\core\actions\NotFound(); } } public function getInfo() { return [ "name"=>static::$moduleName, "table"=>static::$moduleTable, "fields"=>static::$defaultFieldNames, "isRecordModule"=>static::$isRecordModule, "defaultView"=>static::$defaultView, "namespace"=>static::getNamespace(), "viewNamespace"=>static::getNamespace()."\\views", "actionNamespace"=>static::getNamespace()."\\actions", "namespaceClass"=>static::getNamespacedClassName(), ]; } }src/base/BaseView.php000064400000000075144761607160010501 0ustar00file = new File(["path"=>$fileopt,"create"=>true]); } else { $this->file = $fileopt; } $this->prettyJson = dhGlobal::getVal($options,"prettyJson",$this->prettyJson); $this->sort = dhGlobal::getVal($options,"sort",$this->sort); $this->load(); } public function load() { $content = $this->file->content(["json"=>true]); $this->data = []; if(is_array($content) && !empty($content)) { if($this->sort) { ksort($this->data); } foreach($content as $k=>$v) { $this->set($k,$v); } } return $this; } public function save() { if($this->sort) { ksort($this->data); } if($this->prettyJson) { $this->file->write(json_encode($this,JSON_PRETTY_PRINT)); } else { $this->file->write(json_encode($this)); } return $this; } public function has($key) { $test = $this->get($key,"ZZ--NOTFOUND--ZZ"); return $test !== "ZZ--NOTFOUND--ZZ"; } /** * Shortcut to create an instance from a file * @param string|File $file * @return ConfigFile */ public static function fromFile($file) { return new static(["file"=>$file,"prettyJson"=>true]); } }src/util/FWSmarty.php000064400000003766144761607160010565 0ustar00 "{fw}/app", "configDir" => "{fw}/smarty", "compileDir" => "{fw}/cache/smarty/compiled", "cacheDir" => "{fw}/cache/smarty/cache", "caching" => \Smarty::CACHING_OFF, ]; public static function createInstance($options=[]) { static::applyOptions($options); $smarty = new \Smarty(); $smarty->setTemplateDir( static::templateDir() ); $smarty->setConfigDir( static::configDir() ); $smarty->setCompileDir( static::compileDir() ); $smarty->setCacheDir( static::cacheDir() ); $smarty->caching = static::$options["caching"]; } public static function instance($force=false) { if(!static::$smarty || $force) { static::createInstance(); } return static::$smarty; } public static function templateDir() { return static::applyFwDir(static::$options["templateDir"]); } public static function configDir() { return static::applyFwDir(static::$options["configDir"]); } public static function compileDir() { return static::applyFwDir(static::$options["compileDir"]); } public static function cacheDir() { return static::applyFwDir(static::$options["cacheDir"]); } public static function setOption($key,$value) { static::$options[$key] = $value; } public static function applyOptions($options) { if(is_array($options) && !empty($options )) { foreach($options as $key=>$value) { if(isset(static::$options[$key])) { static::$options[$key] = $value; } } } } private static function applyFwDir($path) { return str_replace("{fw}/",DHFW::dir(),$path); } }src/viewer/Viewer.php000064400000000075144761607160010624 0ustar00