Imported code from old repository

This commit is contained in:
2022-11-22 15:46:36 +01:00
parent 976fdc0199
commit 77cf9e05f1
91 changed files with 18969 additions and 2 deletions
+57
View File
@@ -0,0 +1,57 @@
<?php
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
namespace CloudObjects\PhpMAE\Commands;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use CloudObjects\PhpMAE\ClassValidator;
class ClassValidateCommand extends AbstractObjectCommand {
protected function configure() {
$this->setName('class:validate')
->setAliases([ 'validate', 'v' ])
->setDescription('Validates a class for the phpMAE.')
->addArgument('coid', InputArgument::REQUIRED, 'The COID of the object.')
->addOption('watch', null, InputOption::VALUE_NONE, 'Keep watching for changes of the file and revalidate automatically.');
}
protected function execute(InputInterface $input, OutputInterface $output) {
$this->parse($input->getArgument('coid'));
$this->assertRDF();
if (!in_array('coid://phpmae.dev/Class', $this->rdfTypes)
&& !in_array('coid://phpmae.dev/HTTPInvokableClass', $this->rdfTypes))
throw new \Exception("Object does not have a valid class type.");
$this->assertPHPExists();
// Running validator
$validator = new ClassValidator;
try {
$validator->validate(file_get_contents($this->phpFileName),
$this->coid, $this->getAdditionalTypes());
$output->writeln("Validated successfully.");
} catch (\Exception $e) {
$output->writeln('<error>'.get_class($e).'</error> '.$e->getMessage());
}
if ($input->getOption('watch')) {
$cmd = $this;
$this->watchPHPFile($output, function() use ($validator, $cmd, $output) {
try {
$validator->validate(file_get_contents($cmd->phpFileName),
$this->coid, $this->getAdditionalTypes());
$output->writeln("Validated successfully.");
} catch (\Exception $e) {
$output->writeln('<error>'.get_class($e).'</error> '.$e->getMessage());
}
});
}
}
}