/** * Execute the console command. * * @return mixed */ public function handle() { // if ($classname = $this->argument('name')) { $classname = ucfirst($classname); $template = $this->getTemplateDir() . $this->templateName; if (file_exists($template)) { if (file_exists(WebServiceCore::getWebServiceDirectory())) { $text = str_replace($this->mergeCode, $classname, file_get_contents($template)); $path = WebServiceCore::getWebServiceDirectory() . $classname . $this->suffix . $this->ext; if (!file_exists($path)) { if (false == file_put_contents($path, $text)) { $this->error('Can\'t write file to ' . WebServiceCore::getWebServiceDirectory() . $path); } else { chmod($path, 0766); $this->info($classname . ' WebService class created.'); } } else { $this->error($classname . ' already exist.'); } } else { $this->error('WebService class directory not found ' . WebServiceCore::getWebServiceDirectory()); } } else { $this->error('WebService class template not found ' . $template); } } else { $this->error('No classname provided.'); } }
/** * Validate authorization header * @return boolean */ public function validateAuthHeader() { if (!isset($_SERVER['HTTP_AUTHORIZATION'])) { return false; } $token = str_replace(config('system.authorization_prefix'), '', $_SERVER['HTTP_AUTHORIZATION']); if ($token) { $user = ModelFactory::getInstance('UserSessions')->with(['user' => function ($query) { $query->select('id'); }])->where('session_string', '=', trim($token))->first(['id', 'user_pk_id']); if (!$user || !isset($user->user)) { return false; } WebService::$userId = $user->user_pk_id; } return true; }