/** * log constructor * * @param $message * @param string $file * @return self */ public function __construct($message, $file = 'logs.txt') { $file = fopen(storage_dir() . "logs/" . $file, 'a'); if (fwrite($file, $message . "\n")) { $result = true; } else { $result = false; } return $result; }
public static function getManager($driver = null) { if (!static::$manager) { if (!$driver) { $driver = \Slim\Slim::getInstance()->config('cache'); } if ($driver == "filesystem") { $config = array('files' => new Filesystem(), 'config' => array('cache.driver' => 'file', 'cache.path' => storage_dir() . '/cache')); } else { if ($driver == "database") { $config = array('db' => \DLModel::getConnectionResolver(), 'encrypter' => Encrypter::getInstance(), 'config' => array('cache.default' => 'database', 'cache.prefix' => '', 'cache.stores.database' => array('driver' => 'database', 'connection' => 'default', 'table' => 'cache'))); } } $container = new ConfigContainer($config); static::$manager = new CacheManager($container); } return static::$manager; }
public function afterCreate() { // Generate commandline (full-access) $this->keys()->create(array('type' => AppKey::TYPE_CLI)); // Generate browser key (client-side) $this->keys()->create(array('type' => AppKey::TYPE_BROWSER)); // Generate device key (client-side) $this->keys()->create(array('type' => AppKey::TYPE_DEVICE)); // Generate server key (server-side) $this->keys()->create(array('type' => AppKey::TYPE_SERVER)); // Create storage directory for this app $storage_dir = storage_dir(true, $this->_id); // maybe we're on a readonly filesystem if (!file_exists($storage_dir) && is_writable(dirname($storage_dir))) { mkdir($storage_dir, 0777, true); file_put_contents($storage_dir . 'logs.txt', ''); } }
public function call() { $app = $this->app; $app_key = Context::getKey(); // // TODO: need a way to enable/disable logs for production use // // Log all queries $dispatcher = \Hook\Model\Collection::getEventDispatcher(); $dispatcher->listen('illuminate.query', function ($query, $bindings, $time, $name) use(&$app) { $data = compact('bindings', 'time', 'name'); // Format binding data for sql insertion foreach ($bindings as $i => $binding) { if ($binding instanceof \DateTime) { $bindings[$i] = $binding->format('\'Y-m-d H:i:s\''); } else { if (is_string($binding)) { $bindings[$i] = "'{$binding}'"; } } } // Insert bindings into query $query = str_replace(array('%', '?'), array('%%', '%s'), $query); $query = vsprintf($query, $bindings); \Logger::debug($query); }); if (!$app->request->isOptions() && $app_key) { // set application log writer for this app $log_file = storage_dir() . 'logs.txt'; $app->log->setWriter(new LogWriter($log_file)); // disable log if storage directory doesn't exists. // maybe we're on a readonly filesystem $app->log->setEnabled(is_writable($log_file)); if (strpos($app->request->getPath(), "/apps/") === false) { $app->log->info($app->request->getIp() . ' - [' . date('d-m-Y H:i:s') . '] ' . $app->request->getMethod() . ' ' . $app->request->getResourceUri()); $app->log->info('Params: ' . json_encode($app->request->params())); } } return $this->next->call(); }
public function deploy() { set_time_limit(0); $statuses = array(); // application configs $configs = Input::get('config', array()); $configs['security'] = Input::get('security', array()); // Flush cache on deployment Cache\Cache::flush(); // Migrate and keep schema cache $collections_migrated = 0; foreach (Input::get('schema', array()) as $collection => $config) { if (Schema\Builder::getInstance()->migrate(Model\App::collection($collection)->getModel(), $config)) { $collections_migrated += 1; } } $statuses['schema'] = $collections_migrated; // do we have write permission on this server? if (is_writable(storage_dir())) { $statuses['config'] = Config::deploy($configs); $statuses['schedule'] = Model\ScheduledTask::deploy(Input::get('schedule', array())); // install composer packages $statuses['packages'] = Package\Manager::install(Input::get('packages', array())); } else { $error_message = array('error' => 'without write permissions'); $statuses['error'] = "Without write permissions. Ignoring 'config', 'schedule' and 'packages'."; } // modules $statuses['modules'] = Model\Module::deploy(Input::get('modules', array())); return $statuses; }
} require __DIR__ . '/../src/bootstrap/connection.php'; Hook\Http\Router::setInstance($app); // // Ensure that tests will run against an valid fresh app // if (Hook\Model\AppKey::count() == 0) { $app->environment->offsetSet('PATH_INFO', '/apps'); $app->environment->offsetSet('slim.request.form_hash', array('app' => array('name' => 'testing'))); $app_controller = new Hook\Controllers\ApplicationController(); $app_controller->create(); } // Force application key for testing Hook\Application\Context::setTablePrefix(''); Hook\Application\Context::setKey(Hook\Model\AppKey::with('app')->first()); $app->log->setWriter(new Hook\Logger\LogWriter(storage_dir() . '/logs.txt')); class TestCase extends PHPUnit_Framework_TestCase { } class HTTP_TestCase extends PHPUnit_Framework_TestCase { // protected $base_url = 'http://localhost/index.php/'; // protected $base_url = 'http://localhost/index.php/'; protected $base_url = 'http://hook.dev/public/index.php/'; protected $app_keys = array(); protected $app_key = array(); // protected $base_url = 'http://dl-api.dev/index.php/'; public function setUp() { $this->useApp('default'); parent::setUp();
public function realpath($file) { return realpath(storage_dir(true) . $file->name); }
/** * Restore a database table * * @return bool */ public static function restore() { $file = new FileHandler(storage_dir() . 'backups/' . static::$table . ".json", 'r'); $result = null; foreach (json_decode($file->read()) as $data) { if (self::insert((array) $data)) { $result = true; } else { $result = false; break; } } return $result; }
/** * storage_url * @return string */ function storage_url() { return public_url(storage_dir(false)); }
protected static function createComposerJson($packages) { $composer_json = str_replace("\\/", '/', json_encode(array('config' => array('vendor-dir' => self::VENDOR_DIR), 'require' => $packages, 'repositories' => array(array('type' => 'pear', 'url' => 'http://pear.php.net')), 'preferred-install' => 'dist'))); return file_put_contents(storage_dir() . 'composer.json', $composer_json); }
/** * Clear garbage files inside storage. * * @param $folder * @var $filename * @return boolean */ private function clear($folder) { $container = storage_dir() . $folder; $handle = new DirectoryIterator($container); foreach ($handle as $file) { if ($file->getFilename() == '.' || $file->getFilename() == '..') { continue; } if (is_file("{$container}/{$file->getFilename()}")) { unlink("{$container}/{$file->getFilename()}"); } } return true; }
protected function getRootCertificationAuthority() { $filename = storage_dir() . '/' . md5('entrust_2048_ca') . '.cer'; if (!file_exists($filename)) { file_put_contents($filename, file_get_contents('https://www.entrust.net/downloads/binary/entrust_2048_ca.cer')); } return realpath($filename); }
} // // Setup default date format // Use a string representing an RFC2822 or ISO 8601 date // http://tools.ietf.org/html/rfc2822#page-14 // \Carbon\Carbon::setToStringFormat('Y-m-d\\TH:i:sP'); // Setup paginator $connection->setPaginator(new Hook\Pagination\Environment()); // Setup Schema Grammar // $connection->setSchemaGrammar(); // Setup cache manager $connection->setCacheManager(function () { $cache_driver = Router::config('cache'); if ($cache_driver == "filesystem") { $config = array('files' => new \Illuminate\Filesystem\Filesystem(), 'config' => array('cache.driver' => 'file', 'cache.path' => storage_dir() . '/cache')); } else { if ($cache_driver == "database") { $config = array('db' => \DLModel::getConnectionResolver(), 'encrypter' => Hook\Security\Encryption\Encrypter::getInstance(), 'config' => array('cache.driver' => 'database', 'cache.connection' => 'default', 'cache.table' => 'cache', 'cache.prefix' => '')); } } return new Illuminate\Cache\CacheManager($config); }); // // TODO: Create `hook migrate` command. // -------------------------------------- // // // Try to create schema. // Ignore NoSQL databases. //
public static function getConfigPath() { return storage_dir() . 'config.php'; }