Documentation

On this page

Download full book (text)

# **Appendix A: Minimum Project Files — The Smallest Running SartajPhp App** > **Try it:** This whole documentation project IS a minimum app plus examples. > Strip everything except the files below and `http://localhost/SartajPhpDoc/` > still serves the default Index. --- ## **A.1 Required vs Optional** | File / folder | Role | Required? | |---------------|------|-----------| | `start.php` | Boot: paths + `$libVersion` → loads `res/Score/{lib}/global/start.php` | **Yes** | | `comp.php` | Project settings: `$debugMode`, `$dbEnginePath`, `$db`, `$masterf`, secrets | **Yes** | | `prerun.php` | `SphpPreRun::onstart()` before every Gate | Yes (typical) | | `cachelist.php` | `addCacheList` registry (may be empty `<?php`) | Present (can be empty) | | `masters/` | Master layout (`*.mast.php`) | Yes for HTML pages | | `cache/` | Engine cache, sessions, `Sphp_errorLog.txt` | As needed | | `vendor/sartajphp/sartajphp/` | The framework | **Yes** | | `reg.php` + `apps/` | Your Gates | **Optional** | | `db/` | SQL design files (`db_index.php`) | If you use a database | | `plugin/`, `uploads/` | Plugins / user files | As needed | Without any project Gate, the framework serves the shared `vendor/.../res/Slib/apps/Index.gate.php`. Adding `reg.php` + `apps/` replaces that with your app — which is exactly the moment "template" becomes "project". ## **A.2 start.php (tested, this project)** ```php <?php $sharedPath = "./vendor/sartajphp/sartajphp"; $resourceUrl = "./vendor/sartajphp/sartajphp/res"; $libVersion = "SphpLatest"; $slibVersion = "Slib"; // not editable start if(!defined("START_PATH")){ define("START_PATH", __DIR__); } // ... argv parsing (generated) ... $resourcePath = $sharedPath . "/res"; include_once("{$resourcePath}/Score/{$libVersion}/global/start.php"); $globalapp = startSartajPhpEngine(); if($globalapp != ""){ require_once($globalapp); SphpBase::engine()->execute(true); } // not editable end ``` Only the four variables at top are yours: where the framework lives, its URL, and which library version to boot (`SphpLatest` in this project). ## **A.3 comp.php Essentials (tested)** ```php <?php $cmpId = "demo"; // component/app id stored in rows (spcmpId) $cmpName = "SartajPHP Demo"; $SESSION_PATH = './cache/ses'; $debugMode = 2; // Chapter 19 $admUser = 'admin'; // super-admin login (Chapter 14) $admPass = '...'; // keep OUT of public repos $dbUser = "root"; $dbPass = "mypass"; $dbEnginePath = __DIR__ . "/apps/examples/engines/SqlitePdoEngine.php,Sphp\Lib\SqlitePdoEngine"; $db = PROJ_PATH . "/db/spanel.db"; // SQLite file (or MySQL name) $projectUrl = ""; // sub-folder under webroot, e.g. "/SartajPhpDoc" if($projectUrl != ""){ $projectUrl .= "/" . basename(__DIR__); } $masterf = "masters/default/master.mast.php"; // guest master $mebmasterf = "masters/default/master.mast.php"; // member master function getWelcome(){ /* role landing — Chapter 14 */ } ``` `$dbEnginePath` is `file.php,Class\Name` — the engine swap of Chapter 12 is literally this one line. `$projectUrl` is why every URL in this book uses `getGateUrl()`/`getEventUrl()` instead of hard-coded `/`. ## **A.4 prerun.php (tested)** Runs before every Gate — the place for headers and session-level switches: ```php <?php class SphpPreRun extends Sphp\core\SphpPreRunP{ public function onstart(){ $passtoken = "abc"; if(\SphpBase::sphpRequest()->session("edtmode") == $passtoken){ \SphpBase::sphpSettings()->blnEditMode = true; // Chapter 19 }else if(\SphpBase::sphpRequest()->request("edtmode") == $passtoken){ \SphpBase::sphpRequest()->session("edtmode",$passtoken); \SphpBase::sphpSettings()->blnEditMode = true; } } } ``` ## **A.5 reg.php + One Gate (tested pattern)** ```php <?php registerGate("index", __DIR__ . "/apps/Index.gate.php"); registerGate("blog", __DIR__ . "/apps/examples/Blog.gate.php"); // permlist form (Chapter 14): // registerGate("mydocs", __DIR__."/apps/MyDocs.gate.php", "", "My Docs", // array(["add","Add"],["delete","Delete"])); ``` Plus the fallback auto-register (this project's `reg.php` tail): an unregistered `foo.html` maps to `apps/foo.gate.php` if the file exists. ```php <?php // apps/Hello.gate.php — the smallest Gate use Sphp\Gates\BasicGate; class Hello extends BasicGate { public function onstart() { global $masterf; $this->setMasterFile($masterf); } public function page_new() { $this->setFrontFile(new \Sphp\Tools\FrontFile('hello')); // fronts/hello.front } } ``` ## **A.6 Boot Flow** ```mermaid flowchart TD start[start.php] --> eng[Engine boots] eng --> comp[comp.php] eng --> prerun[prerun.php onstart] eng --> cache[cachelist.php] eng --> reg{reg.php?} reg -->|yes| apps[apps/*.gate.php] reg -->|no| slib[Slib default Index] apps --> master[masters + fronts render] slib --> master ``` ## **A.7 Run It** Apache sub-folder (this book's setup): copy the minimum files under the webroot, set `$projectUrl`, open `http://localhost/SartajPhpDoc/`. SphpServer: ```bat sphpdesk\sphpserver\sphpserver-win.exe --proj .\ --port 8000 --host 127.0.0.1 ``` CLI (Chapter 21): ```bat php -f start.php -- --gate index ``` --- **Previous:** [Chapter 23 — Component Internals](chapter23.md) · **Next:** [Appendix B — Working With AI Agents](appendixB.md)