function run() { $this->dmx = new \DmxHttp\Controller\DMXPost(); $this->dmx->addDevice(new Spot(6)); $this->dmx->addDevice(new Spot(12)); $this->dmx->addDevice(new Spot(18)); $this->dmx->addDevice(new Spot(24)); $this->dmx->addDevice(new Spot(30)); $this->dmx->addDevice(new Spot(36)); $this->dmx->addDevice(new Spot(42)); $this->dmx->addDevice(new Spot(48)); $this->dmx->addDevice(new Scanner(300)); $this->dmx->addDevice(new Scanner(305)); $this->dmx->addDevice(new Scanner(310)); $this->dmx->addDevice(new Scanner(314)); $console = new \Symfony\Component\Console\Application(); $console->register("ls")->setDefinition(array())->setDescription("list devices")->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array('Start Channel', 'Type', 'status')); foreach ($this->dmx->getDevices() as $device) { $table->addRow([$device->getStartChannel(), get_class($device), '[' . implode(',', $device->getChannels()) . ']']); } $table->render(); }); $console->register("run")->setDefinition(array(new InputArgument('device', InputArgument::REQUIRED, 'start channel of a device'), new InputArgument('method', InputArgument::REQUIRED, 'method'), new InputArgument('args', InputArgument::IS_ARRAY, 'arguments')))->setDescription("set command")->setCode(function (InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { $device = null; foreach ($this->dmx->getDevices() as $_device) { if ($_device->getStartChannel() == $input->getArgument("device")) { $device = $_device; break; } } if ($device === null) { $output->writeln("<error>can't find device</error>"); return 1; } $method = $input->getArgument("method"); $args = $input->getArgument("args"); call_user_func_array([$device, $method], $args); $this->dmx->send(); }); $console->run(); }
require_once __DIR__ . '/../vendor/autoload.php'; $console = new \Symfony\Component\Console\Application(); //$console->add(new Cotya\TideGauge\Console\Analyze()); $flatten_spans = function (&$spans) { $result = []; foreach ($spans as $span) { if (!isset($result[$span['a']['title']])) { $result[$span['a']['title']] = [$span['a']['title'], max($span['e']) - min($span['b']), count($span['b'])]; } else { $result[$span['a']['title']][1] += max($span['e']) - min($span['b']); $result[$span['a']['title']][2] += count($span['b']); } } return $result; }; $console->register('analyze')->setDefinition(array())->setDescription('Displays the files in the given directory')->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) use($flatten_spans) { $file = __DIR__ . '/../local/trace_17186.json'; $file = __DIR__ . '/../local/trace_17717.json'; $trace = json_decode(file_get_contents($file), true); $appInfo = array_shift($trace['spans']); $output->writeln('App run info:'); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setRows(array(array('id', $trace['id']), array('TransactionName', $trace['tx']), array('PHP Version:', $appInfo['a']['php']), array('title:', $appInfo['a']['title']))); $table->render(); $output->writeln('App Summary:'); $table = new \Symfony\Component\Console\Helper\Table($output); $tableStyleRightAligned = new \Symfony\Component\Console\Helper\TableStyle(); $tableStyleRightAligned->setPadType(STR_PAD_LEFT); $table->setColumnStyle(1, $tableStyleRightAligned); $table->setRows(array(array('compile count:', $appInfo['a']['cct'] ?? ''), array('compile Wall Time:', $appInfo['a']['cwt'] ?? ''), array('compile CPU Time:', $appInfo['a']['cpu']), array('Garbage Collection Runs:', $appInfo['a']['gc'] ?? ''), array('Garbage Collected:', $appInfo['a']['gcc'] ?? ''))); $table->render();
public function run($args = array()) { $defaults = array('proxy' => array('auto' => true, 'path' => LITHIUM_APP_PATH . '/resources/tmp/cache/Doctrine/Proxies', 'namespace' => 'Doctrine\\Proxies'), 'useModelDriver' => true, 'mapping' => array('class' => null, 'path' => LITHIUM_APP_PATH . '/models'), 'configuration' => null, 'eventManager' => null); if ($this->request->params['action'] != 'run') { $args = $this->request->argv; } // Check if we need to add the migration configuration file $migrationCommand = false; $migrationConfig = true; $migration = false; $conn = Connections::get($this->connection); $conn->_config = $conn->_config + $defaults; $i = 0; foreach ($args as &$arg) { if (strstr($arg, 'migrations:')) { $migrationCommand = true; } if (strstr($arg, 'migrations')) { $migration = true; } if (strstr($arg, '--configuration=')) { $migrationConfig = false; } if (strstr($arg, '--connection')) { unset($args[$i]); } $i++; } if ($migrationCommand && $migrationConfig) { $args[] = '--configuration=' . LITHIUM_APP_PATH . '/config/migrations.yml'; } $input = new \Symfony\Component\Console\Input\ArgvInput($args); if (!$conn || !$conn instanceof \app\extensions\data\source\Doctrine) { $error = "Error: Could not get Doctrine proxy object from Connections, using"; $error .= " configuration '{$this->connection}'. Please add the connection or choose"; $error .= " an alternate configuration using the `--connection` flag."; $this->error($error); return; } /* * New Doctrine ORM Configuration * TODO: load multiple drivers [Annotations, YAML & XML] * */ $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache()); //Annotation Driver $driver = $config->newDefaultAnnotationDriver(array(LITHIUM_APP_PATH . '/models')); $config->setMetadataDriverImpl($driver); //Proxy configuration $config->setProxyDir($conn->_config['proxy']['path']); $config->setProxyNamespace($conn->_config['proxy']['namespace']); //EntityManager $em = \Doctrine\ORM\EntityManager::create($conn->_config, $config); $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em), 'dialog' => new \Symfony\Component\Console\Helper\DialogHelper())); //CLI $cli = new \Symfony\Component\Console\Application('Doctrine Command Line Interface', \Doctrine\Common\Version::VERSION); $cli->setCatchExceptions(true); $cli->register('doctrine'); $cli->setHelperSet($helperSet); $cli->addCommands(array(new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand())); // If command called is a doctrine migration command if ($migration) { $cli->addCommands(array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand())); } $cli->run($input); }