/** * @param array $argv * @return int exit code */ public function handle(array $argv) { try { $Options = $this->parseParams($argv); if (empty($argv[1])) { throw new \InvalidArgumentException("No action specified"); } $action = $argv[1]; if (!isset($this->registry[$action])) { throw new \InvalidArgumentException("Unknown action '{$action}'"); } $Handler = $this->registry[$action]; $Formatter = $this->createFormatter($Options); $Ctx = new Ctx(); if (count($argv) > 2) { for ($i = 2; $i < count($argv); $i++) { $Ctx->addFile($argv[$i]); } } $callback_invoked = false; if (isset($this->callbacks[$action])) { call_user_func_array($this->callbacks[$action], [$Ctx, $Options]); $callback_invoked = true; } if (!$Ctx->getFiles() && !$callback_invoked) { throw new \RuntimeException("No files to execute"); } return $Handler->handle($Formatter, $Ctx); } catch (\Exception $Error) { fwrite(STDERR, 'Error: ' . $Error->getMessage() . PHP_EOL); $this->printUsage(); return 1; } }
public function test_getById() { $obm = Ctx::instance()->getObjectManager(); /** @var $repo IWarehouse */ $repo = $obm->get(IWarehouse::class); $data = $repo->getById(1); return; }
/** * @inheritdoc */ protected function handleInternal(Ctx $Ctx) { $this->Formatter->getOptions()->toggleSniff(true); $has_unformatted = false; $has_error = false; foreach ($Ctx->getFiles() as $file_spec) { $file = $file_spec; if (strpos($file_spec, ':') !== false) { list($file, ) = explode(':', $file); } $initial = file_get_contents($file); if (false === $initial) { $this->error($file . ": Failed to get content"); } else { $Result = $this->Formatter->formatFile($file_spec); if ($Error = $Result->getError()) { $this->error($file . ":" . $Error->getMessage()); } else { if ($Result->wasFormatted()) { $this->printIssues($Result); $tmp = tempnam(sys_get_temp_dir(), "phpcf"); if (false === $tmp) { $this->error($file . ': failed to create tmp file for diff'); continue; } if (false === file_put_contents($tmp, $Result->getContent())) { $this->error($file . ': failed to write content to tmp'); unlink($tmp); continue; } $cmd = $this->diff_cmd . " " . escapeshellarg($file) . " " . escapeshellarg($tmp); if (null !== $this->cdiff_cmd) { $cmd .= " | " . $this->cdiff_cmd; } system($cmd); unlink($tmp); } else { $this->message("{$file}: is OK"); } } } } return $has_error || $has_unformatted ? 1 : 0; }
/** * @inheritdoc */ protected function handleInternal(Ctx $Ctx) { $has_errors = false; foreach ($Ctx->getFiles() as $file) { $Result = $this->Formatter->formatFile($file); $file = $Result->getFile(); if ($Error = $Result->getError()) { $this->error("{$file}: " . $Error->getMessage()); } else { if ($Result->wasFormatted()) { if (!file_put_contents($file, $Result->getContent())) { $this->error($file . ': failed to save new content'); } else { $this->message("{$file} formatted successfully"); } } else { $this->message("{$file} does not need formatting"); } } } return $has_errors ? 1 : 0; }
/** * @inheritdoc */ protected function handleInternal(Ctx $Ctx) { $has_unformatted = false; $has_error = false; $Options = $this->Formatter->getOptions(); $Options->toggleSniff(true); foreach ($Ctx->getFiles() as $file) { $Result = $this->Formatter->formatFile($file); $file = $Result->getFile(); if ($Error = $Result->getError()) { $this->error($file . ":" . $Error->getMessage()); } else { if ($Result->wasFormatted()) { $has_unformatted = true; $this->printIssues($Result); } else { if (!$Options->isQuiet()) { $this->message($file . ' does not need formatting'); } } } } return $has_error || $has_unformatted ? 1 : 0; }
/** * 请求单例 */ public static function getInstance($config = null) { if (is_null(self::$_instance) || isset(self::$_instance)) { self::$_instance = new self($config); } return self::$_instance; }