/** Redifine this function instead of default constructor */ function init() { $this->getLogger(); // Verify Licensing //$this->licenseCheck('atk4'); // send headers, no caching $this->sendHeaders(); $this->cleanMagicQuotes(); parent::init(); /** In addition to default initialization, set up logger and template */ $this->initializeTemplate(); if (get_class($this) == 'App_Web') { $this->setConfig(array('url_postfix' => '.php', 'url_prefix' => '')); } }
/** * init * * @return [type] [description] */ public function init() { parent::init(); try { // Extra 24-hour protection parent::init(); $this->logger = $this->add('Logger'); $this->add('Controller_PageManager')->parseRequestedURL(); // It's recommended that you use versioning inside your API, // for example http://api.example.com/v1/user // // This way version is accessible anywhere from $this->app->version list($this->version, $junk) = explode('_', $this->page, 2); // Add-ons may define additional endpoints for your API, but // you must activate them explicitly. $this->pathfinder->base_location->defineContents(array('endpoint' => 'endpoint')); } catch (Exception $e) { $this->caughtException($e); } }
<?php include 'vendor/autoload.php'; $app = new App_CLI(); //$app->pathfinder->addRelativeLocation(['php','shared/lib']); try { $app->add('Logger'); $app->pathfinder->base_location->addRelativeLocation('shared', ['php' => 'lib', 'addons' => 'addons']); if (PHP_SAPI !== 'cli' || !empty($_SERVER['REMOTE_ADDR'])) { throw new Exception('Execute from command-line only'); } $options = getopt("k:rha:n:", ['key:', 'reset', 'help', 'addr:', 'name:']); if (isset($options['h']) || isset($options['help'])) { echo <<<EOF Usage: php bootstrap.php [-k <key> -i <ip> [-n <name>]] [-r] [-h] -k, --key <file> -a, --addr <addr> -n, --name <name> Read private key from file and add it as default host. <addr> must be also specified. If you omit the name, addr will be used. -r, --reset Reset user information -h, --help
function test_add9_hook($t) { $result = "FAIL"; $app = new App_CLI(); $app->addHook('beforeObjectInit', function () use(&$result) { $result = "OK"; }); $t = $app->add('MyObject'); return $result; }
/** * Output string into error file. * * @param string $error error * @param string $msg msg * * @obsolete */ public function logError($error, $msg = '') { if (is_object($error)) { // we got exception object obviously $error = $error->getMessage(); } $this->app->getLogger()->logLine($msg . ' ' . $error . "\n", null, 'error'); }