Misc fixes
* Updated build scripts to handle gitless environments a little better * PDO shell plugin improvements * More tests
This commit is contained in:
		@@ -6,6 +6,7 @@ use Spark\Commands\Command;
 | 
			
		||||
use SparkPlug;
 | 
			
		||||
use SparkPlug\Com\Noccy\ApiClient\Api\Method;
 | 
			
		||||
use SparkPlug\Com\Noccy\ApiClient\ApiClientPlugin;
 | 
			
		||||
use SparkPlug\Com\Noccy\ApiClient\Log\RequestData;
 | 
			
		||||
use SparkPlug\Com\Noccy\ApiClient\Request\RequestBuilder;
 | 
			
		||||
use Symfony\Component\Console\Helper\Table;
 | 
			
		||||
use Symfony\Component\Console\Input\InputArgument;
 | 
			
		||||
@@ -29,7 +30,17 @@ class ApiLogsCommand extends Command
 | 
			
		||||
        /** @var ApiClientPlugin */
 | 
			
		||||
        $plugin = get_plugin('com.noccy.apiclient');
 | 
			
		||||
 | 
			
		||||
        $iter = $plugin->getLogIterator("default");
 | 
			
		||||
 | 
			
		||||
        foreach ($iter as $index=>$log) {
 | 
			
		||||
            $this->dumpLog($log, $index, $output);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return Command::SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function dumpLog(array $log, int $index, OutputInterface $output)
 | 
			
		||||
    {
 | 
			
		||||
        $output->writeln("<comment>#{$index}</> <options=bold>{$log['request']['info']['query']}</> (<info>{$log['method']}</>) ".strlen($log['response']['body'])."b");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ namespace SparkPlug\Com\Noccy\ApiClient;
 | 
			
		||||
 | 
			
		||||
use SparkPlug;
 | 
			
		||||
use SparkPlug\Com\Noccy\ApiClient\Log\RequestLog;
 | 
			
		||||
use SparkPlug\Com\Noccy\ApiClient\Log\LogIterator;
 | 
			
		||||
 | 
			
		||||
class ApiClientPlugin extends SparkPlug
 | 
			
		||||
{
 | 
			
		||||
@@ -113,6 +114,14 @@ class ApiClientPlugin extends SparkPlug
 | 
			
		||||
        $log = new RequestLog($logsDir.$name.".json");
 | 
			
		||||
        return $log;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getLogIterator(string $name): LogIterator
 | 
			
		||||
    {
 | 
			
		||||
        $env = get_environment();
 | 
			
		||||
        $logsDir = $env->getConfigDirectory() . "/api/logs/";
 | 
			
		||||
        $iter = new LogIterator($logsDir.$name.".json");
 | 
			
		||||
        return $iter;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
register_plugin("com.noccy.apiclient", new ApiClientPlugin);
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ namespace SparkPlug\Com\Noccy\Pdo\Shell\Shell;
 | 
			
		||||
 | 
			
		||||
use SparkPlug\Com\Noccy\Pdo\PdoResource;
 | 
			
		||||
use Spark\Commands\Command;
 | 
			
		||||
use Spark\SparkApplication;
 | 
			
		||||
use Symfony\Component\Console\Helper\Table;
 | 
			
		||||
use Symfony\Component\Console\Helper\TableSeparator;
 | 
			
		||||
use Symfony\Component\Console\Input\InputArgument;
 | 
			
		||||
@@ -178,6 +179,9 @@ class PdoShell {
 | 
			
		||||
            $query = $json['query']??'?';
 | 
			
		||||
            $res = $json['result']??[];
 | 
			
		||||
        } else {
 | 
			
		||||
            if (!$this->lastQuery) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            $query = $this->lastQuery['query'];
 | 
			
		||||
            $res = $this->lastQuery['result'];
 | 
			
		||||
        }
 | 
			
		||||
@@ -223,6 +227,25 @@ class PdoShell {
 | 
			
		||||
    private function doSelectCommand(array $args)
 | 
			
		||||
    {
 | 
			
		||||
        $name = array_shift($args);
 | 
			
		||||
 | 
			
		||||
        if (!$name) {
 | 
			
		||||
            $app = SparkApplication::$instance;
 | 
			
		||||
            $resources = $app->getResourceManager();
 | 
			
		||||
            
 | 
			
		||||
            $named = $resources->getAllNamedResources();
 | 
			
		||||
            foreach ($named as $name=>$resource) {
 | 
			
		||||
                if (!($resource instanceof PdoResource)) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                $this->output->writeln(
 | 
			
		||||
                    sprintf(" <comment>%s</><info>%s</>", ($name==$this->resource?"*":" "), $name)
 | 
			
		||||
                );
 | 
			
		||||
            }
 | 
			
		||||
            return;
 | 
			
		||||
    
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        $res = get_resource($name);
 | 
			
		||||
        if ($res instanceof PdoResource) {
 | 
			
		||||
            $this->db = $res;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user