['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); if ($resource === false) { return false; } $stdout = \stream_get_contents($pipes[1]); $stderr = \stream_get_contents($pipes[2]); foreach ($pipes as $pipe) { \fclose($pipe); } return \proc_close($resource) !== 127; } /** * Run command * * @param string $cmd Command to run * * @return string * * @throws \Exception * * @since 1.0.0 */ protected function run(string $cmd) : string { $cmd = 'cd ' . \escapeshellarg(\dirname(self::$bin)) . ' && ' . \basename(self::$bin) . ' ' . $cmd; $pipes = []; $desc = [ 1 => ['pipe', 'w'], 2 => ['pipe', 'w'], ]; $resource = \proc_open($cmd, $desc, $pipes, __DIR__, null); if ($resource === false) { return ''; } $stdout = \stream_get_contents($pipes[1]); $stderr = \stream_get_contents($pipes[2]); foreach ($pipes as $pipe) { \fclose($pipe); } $status = \proc_close($resource); if ($status === -1) { throw new \Exception((string) $stderr); } return $stdout === false ? '' : \trim($stdout); } /** * Create task * * @param TaskAbstract $task Task to create * * @return void * * @since 1.0.0 */ abstract public function create(TaskAbstract $task) : void; /** * Update task * * @param TaskAbstract $task Task to update * * @return void * * @since 1.0.0 */ abstract public function update(TaskAbstract $task) : void; /** * Delete task by name * * @param string $name Task name * * @return void * * @since 1.0.0 */ abstract public function deleteByName(string $name) : void; /** * Delete task * * @param TaskAbstract $task Task to delete * * @return void * * @since 1.0.0 */ abstract public function delete(TaskAbstract $task) : void; /** * Normalize run result for easier parsing * * @param string $raw Raw command output * * @return string Normalized string for parsing * * @since 1.0.0 */ protected function normalize(string $raw) : string { return \str_replace("\r\n", "\n", $raw); } /** * Get all jobs/tasks by name * * @param string $name Name of the job * @param bool $exact Name has to be exact * * @return array * * @since 1.0.0 */ abstract public function getAllByName(string $name, bool $exact = true) : array; }