<?php require_once __DIR__ . '/../vendor/autoload.php'; use Tipsy\Tipsy; Tipsy::config('../config/*.ini'); Tipsy::config('../config/*.yml'); Tipsy::config(['path' => __DIR__ . '/../']); if (getenv('DATABASE_URL')) { Tipsy::config(['db' => ['url' => getenv('DATABASE_URL')]]); // CLEARDB_DATABASE_URL } // define routes here for anything that uses route params Tipsy::router()->when('api/user/:id', '\\App\\Controller\\Api\\User')->when('auth/:service', '\\App\\Controller\\Auth')->when('/\\.scss$/i', '\\App\\Controller\\Scss'); // initilize config from database, config files, and env variables Tipsy::service('cfgr', '\\App\\Cfgr'); Tipsy::service('Mail', '\\App\\Mail'); Tipsy::service('User', '\\App\\User'); //echo Tipsy::service('cfgr')->get('auth-facebook-key'); //echo Tipsy::service('cfgr')->set('auth-facebook-key', 'test'); // simple session management using redis Tipsy::middleware('Session', ['run' => function () { $redis = getenv('REDIS_URL'); if ($redis) { $client = new \Predis\Client($redis); $handler = new App\Session($client); session_set_save_handler($handler); } session_start(); }, 'user' => function () { return $_SESSION['user'] ? $this->tipsy()->service('User')->load($_SESSION['user']) : null; }]);
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Tipsy\Tipsy; Tipsy::config('../config/*.ini'); Tipsy::run(); Tipsy::router()->when('api/user/:id', '\\App\\Controller\\Api\\User');
require_once $controller; } return true; }, false); $controller = function ($Request) { $find = function ($page, &$controller, &$posiblePage) { $pageClass = explode('/', $page); \Tipsy\MVC\Find::find($pageClass, $controller, $posiblePage); }; $find($Request->path(), $controller, $posiblePage); if (!isset($controller) || !file_exists($controller)) { $find('home', $controller, $posiblePage); } require_once $controller; $possibleClass = explode('/', substr($posiblePage, 0, strpos($posiblePage, '.'))); $fullPageNext = '\\App\\Controller'; foreach ($possibleClass as $class) { if (!$class) { continue; } $fullPageNext .= '\\' . ucfirst($class); if (class_exists($fullPageNext, false)) { $c = new $fullPageNext(['tipsy' => $this->tipsy()]); if (method_exists($fullPageNext, 'init')) { $c->init(); } } } }; \Tipsy\Tipsy::router()->when('-tipsy-mvc-', $controller)->otherwise($controller);
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Tipsy\Tipsy; Tipsy::router()->post('hook', function ($Params, $Request) { $package = $_ENV['PACKAGE_NAME'] ? $_ENV['PACKAGE_NAME'] : ($this->tipsy()->config()['update']['package'] ? $this->tipsy()->config()['update']['package'] : $Request->repository['full_name']); $email = $_ENV['GITHUB_EMAIL'] ? $_ENV['GITHUB_EMAIL'] : $this->tipsy()->config()['update']['email']; $name = $_ENV['GITHUB_NAME'] ? $_ENV['GITHUB_NAME'] : $this->tipsy()->config()['update']['name']; $key = $_ENV['WEBHOOK_SECRET'] ? $_ENV['WEBHOOK_SECRET'] : $this->tipsy()->config()['update']['secret']; if (!$package) { echo "No PACKAGE_NAME.\n"; $error = true; } if (!$email) { echo "No GITHUB_EMAIL.\n"; $error = true; } if (!$name) { echo "No GITHUB_NAME.\n"; $error = true; } if (!$key) { echo "No WEBHOOK_SECRET.\n"; $error = true; } $sig = hash_hmac('sha1', $Request->content(), $key, false); if ('sha1=' . $sig != $Request->headers()['X-Hub-Signature']) { echo "Invalid WEBHOOK_SECRET.\n"; $error = true; } if ($error) {
<?php require_once __DIR__ . '/bootstrap.php'; use Tipsy\Tipsy; Tipsy::service('Product', '\\Tipsy\\Doctrine\\Resource\\Product'); Tipsy::router()->post('product', function ($Product, $Request) { $p = $Product->create([name => $Request->name]); if ($p->id) { header('Location: /product/' . $p->id); } })->get('product/:id', function ($Product, $Params, $View) { $p = $Product->load($Params->id); if ($p) { $View->display('product', [product => $p]); } else { http_response_code(404); } })->otherwise(function ($Db, $Product, $View) { $View->display('home'); return; /** * if you are more familiar with using doctrine specific code you can do so like below **/ $p = new \Tipsy\Doctrine\Resource\Product(); $p->setName('test1'); $Db->entityManager()->persist($p); echo $p->getId(); $s = $Db->query('select * from products where name=?', ['test1']); $s->execute(); while ($row = $s->fetch(PDO::FETCH_OBJ)) { print_r($row);