protected function execute(InputInterface $input, OutputInterface $output)
 {
     $questionHelper = $this->getHelper('question');
     if (!is_dir($this->directory)) {
         $question = new ConfirmationQuestion(sprintf('Migration directory <info>%s</info> does not exist, dou you want to create it? [n] ', $this->directory), false);
         if (!$questionHelper->ask($input, $output, $question)) {
             return;
         }
         Filesystem::createDirectory($this->directory);
     }
     if (!is_writable($this->directory)) {
         $output->writeln(sprintf('<error>Migration directory %s is not writable</error>', $this->directory));
         return;
     }
     $date = new \DateTime('@' . time());
     $date->setTimezone(new \DateTimeZone('UTC'));
     $class = 'Version' . $date->format('YmdHis');
     $file = $class . '.php';
     $tpl = ['###CLASS###' => $class, '###DATE###' => $date->format('Y-m-d H:i:s') . ' UTC'];
     $code = strtr(file_get_contents(__DIR__ . '/MigrationTemplate.txt'), $tpl);
     $target = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $this->directory . '/' . $file);
     $question = new ConfirmationQuestion(sprintf('Generate migration <info>%s</info>? [y] ', $target), true);
     if (!$questionHelper->ask($input, $output, $question)) {
         return;
     }
     if (false === file_put_contents($target, $code)) {
         $output->writeln(sprintf('<error>Failed to write migration %s to disk.</error>', $target));
         return;
     }
     $output->writeln(sprintf('  Migration <info>%s</info> generated.', $target));
 }
 public function __construct($directory, $autoCreate = false, $compressionLevel = 1)
 {
     if (is_dir($directory)) {
         $this->directory = realpath($directory);
     } else {
         if (!$autoCreate) {
             throw new \InvalidArgumentException(sprintf('Session storage directory not found: "%s"', $directory));
         }
         $this->directory = Filesystem::createDirectory($directory);
     }
     $this->compressionLevel = min(9, max(0, (int) $compressionLevel));
 }
示例#3
0
 public function __construct(KernelInterface $kernel, $timeout = 8)
 {
     $this->contextName = $kernel->getContextName();
     $this->kernel = $kernel;
     $this->timeout = (int) $timeout;
     $dir = Filesystem::createDirectory($kernel->getCacheDirectory() . DIRECTORY_SEPARATOR . $this->contextName);
     $this->file = $dir . DIRECTORY_SEPARATOR . 'cache.php';
     $this->lockFile = $dir . DIRECTORY_SEPARATOR . 'cache.lock';
     if (is_file($this->file)) {
         if (filemtime($this->file) < time() - $this->timeout) {
             $this->needsCheck = true;
         }
         $this->cached = (array) (require $this->file);
     } else {
         $this->modified = true;
         $this->cached = [];
     }
     $this->expired = !is_file($this->file) || filemtime($this->file) < time() - $this->timeout;
 }
 public function create(Configuration $config)
 {
     $cachePath = $config->getString('cachePath', NULL);
     $createFolder = $config->getBoolean('createFolder', false);
     if ($cachePath !== NULL) {
         if (!is_dir($cachePath)) {
             if (!$createFolder) {
                 throw new \RuntimeException(sprintf('Cache directory not found: "%s"', $cachePath));
             }
             $cachePath = Filesystem::createDirectory($cachePath);
         }
         if (!is_readable($cachePath)) {
             throw new \RuntimeException(sprintf('Cache directory not readable: "%s"', $cachePath));
         }
         if (!is_writable($cachePath)) {
             throw new \RuntimeException(sprintf('Cache directory not writable: "%s"', $cachePath));
         }
     }
     return new ExpressViewFactory($cachePath, $this->logger);
 }
示例#5
0
文件: Kernel.php 项目: koolkode/k2
 /**
  * Create the DI container instance.
  * 
  * @param ScopeLoader $scopes
  * @return ContainerInterface
  */
 protected function createContainer(ContainerModuleLoader $loader, ScopeLoader $scopes)
 {
     $contextCachePath = $this->cacheDirectory . DIRECTORY_SEPARATOR . $this->contextName;
     $cacheFile = $contextCachePath . DIRECTORY_SEPARATOR . 'container.php';
     $containerTypeName = __NAMESPACE__ . '\\CompiledContainer';
     $proxyPath = Filesystem::createDirectory($contextCachePath . DIRECTORY_SEPARATOR . 'scoped');
     $scopedProxies = [];
     foreach ($scopes as $scope) {
         foreach ($scope->getProxyTypeNames() as $typeName) {
             $scopedProxies[] = $typeName;
         }
     }
     if (!is_file($cacheFile) || $this->cache->isModified()) {
         $builder = $this->createContainerBuilder();
         foreach ($this->komponents as $komponent) {
             $komponent->build($builder);
         }
         foreach ($loader as $module) {
             $module->build($builder);
         }
         $this->build($builder);
         if ($this->isInstrumentationEnabled()) {
             $manager = $this->getManifest();
         } else {
             $manager = new ReflectionTypeInfoManager();
         }
         $compiler = new ContainerCompiler($manager, $containerTypeName);
         $code = $compiler->compile($builder, $proxyPath, $scopedProxies);
         Filesystem::writeFile($cacheFile, $code);
     }
     require_once $cacheFile;
     return new $containerTypeName($this->getContainerParams());
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $renderers = $this->view->getRenderers(function ($renderer) {
         return $renderer instanceof ExpressViewRenderer;
     });
     if (empty($renderers)) {
         throw new \RuntimeException(sprintf('Express view renderer not found'));
     }
     $dir = $input->getOption('dir');
     if ($dir === NULL) {
         $dir = 'resource/schema';
     }
     if (!preg_match("'^/|(?:[^:\\\\/]+://)|(?:[a-z]:[\\\\/])'i", $dir)) {
         $dir = $this->directory . '/' . $dir;
     }
     $dir = Filesystem::normalizePath($dir);
     if (!is_dir($dir)) {
         $questionHelper = $this->getHelper('question');
         $question = new ConfirmationQuestion(sprintf('Schema directory <info>%s</info> does not exist, dou you want to create it? [n] ', $dir), false);
         if (!$questionHelper->ask($input, $output, $question)) {
             return;
         }
         Filesystem::createDirectory($dir);
     }
     $renderer = array_pop($renderers);
     $namespace = $input->getArgument('namespace');
     $catalogFile = $dir . '/catalog.xml';
     $xml = new \DOMDocument('1.0', 'UTF-8');
     $xml->preserveWhiteSpace = false;
     $xml->formatOutput = true;
     if (is_file($catalogFile)) {
         $xml->load($catalogFile);
         $catalogElement = $xml->documentElement;
     } else {
         $catalogElement = $xml->appendChild($xml->createElementNS(self::NS_CATALOG, 'c:catalog'));
         $catalogElement->appendChild($xml->createAttribute('prefer'))->appendChild($xml->createTextNode('public'));
     }
     $xpath = new \DOMXPath($xml);
     $xpath->registerNamespace('c', self::NS_CATALOG);
     $count = 0;
     $skipped = 0;
     foreach ($renderer->generateXmlSchemaBuilders() as $builder) {
         if (!$builder instanceof HelperXmlSchemaBuilder) {
             continue;
         }
         $ns = $builder->getNamespace();
         if ($namespace != $ns) {
             continue;
         }
         $code = (string) $builder;
         $file = sprintf('%s/%s.xsd', $dir, str_replace(':', '-', $ns));
         if (!is_file($file) || md5_file($file) !== md5($code)) {
             $count++;
             Filesystem::writeFile($file, $code);
             $output->writeln('');
             $output->writeln(sprintf('<info>%s</info>', basename($file)));
             $output->writeln(sprintf('  Generated XML-Schema for namespace <comment>%s</comment>.', $ns));
         } else {
             $skipped++;
         }
         $found = false;
         foreach ($xpath->query("/c:catalog/c:uri[@name='" . $ns . "']") as $el) {
             $found = $el ? true : false;
         }
         if (!$found) {
             $uriElement = $catalogElement->appendChild($xml->createElementNS(self::NS_CATALOG, 'c:uri'));
             $uriElement->appendChild($xml->createAttribute('name'))->appendChild($xml->createTextNode($ns));
             $uriElement->appendChild($xml->createAttribute('uri'))->appendChild($xml->createTextNode(str_replace(':', '-', $ns) . '.xsd'));
         }
     }
     $output->writeln('');
     $output->writeln(sprintf('Created <info>%u</info> schema files in directory <comment>%s</comment>', $count, $dir));
     Filesystem::writeFile($catalogFile, $xml->saveXML());
 }
示例#7
0
 public function getContainerParams()
 {
     $params = parent::getContainerParams();
     $params['kernel.path.data'] = Filesystem::createDirectory($this->directory . DIRECTORY_SEPARATOR . 'data');
     foreach ($this->testLoader->findRules() as $rule) {
         $params = array_merge($params, (array) $rule->loadContainerParams());
     }
     return array_merge($params, (array) $this->testLoader->loadContainerParams());
 }
示例#8
0
 protected function buildResource(ContainerBuilder $builder)
 {
     $builder->bind(ResourcePublisherInterface::class)->scoped(new Singleton())->to(function (KernelInterface $kernel) {
         if (PHP_SAPI == 'cli') {
             return new DomainResourcePublisher('//test.me/');
         }
         $env = $kernel->getEnvironment();
         return new DomainResourcePublisher(sprintf('//%s%s/', $env->getHost(), rtrim('/' . $env->getBaseUri()->getPath())));
     })->initialize(function (ResourcePublisherInterface $publisher, KernelInterface $kernel) {
         foreach ($kernel->getConfiguration()->getConfig('KoolKode.Http.Komponent.Resource.blacklist') as $pattern) {
             $publisher->addBlacklistPattern($pattern);
         }
     });
     $builder->bind(ResourceDeliveryMiddleware::class)->marked(new Middleware(PHP_INT_MAX - 1000));
     $builder->bind(PipelineManagerInterface::class)->scoped(new ApplicationScoped())->to(PipelineManager::class);
     $builder->bind(PipelineController::class)->marked(new Dispatchable('/_pipeline/{identifier}-{hash}', '_pipeline'))->initialize(function (PipelineController $controller, Configuration $config) {
         $dir = $config->get('cachePath', NULL);
         if ($dir !== NULL) {
             if (!is_dir($dir)) {
                 Filesystem::createDirectory($dir);
             }
             $controller->setCachePath($dir);
         }
     });
     $builder->bind(ResourceExpressionExtension::class)->marked(new ExpressionExtension());
 }
示例#9
0
 public function createCollection(ResourceInterface $parent, $name)
 {
     if (!$parent instanceof FilesystemDirectory) {
         throw new \InvalidArgumentException(sprintf('Parent collection "%s" must be a filesystem directory', $parent->getPath()));
     }
     $name = $this->sanitizeResourceName($name);
     $target = $parent->getFileInfo()->getPathname() . DIRECTORY_SEPARATOR . $name;
     if (file_exists($target)) {
         throw new \RuntimeException(sprintf('Unable to overwrite directory: %s', $target));
     }
     $target = Filesystem::createDirectory($target);
     return new FilesystemDirectory($parent->getPath() . '/' . $name, new \SplFileInfo($target), $this);
 }
示例#10
0
 protected function setupRootDirectory()
 {
     $dir = Filesystem::createDirectory(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'k2' . DIRECTORY_SEPARATOR . UUID::createRandom());
     // TODO: Directory is not being removed when console is terminated using CRTL+C kill signal...
     register_shutdown_function(function () use($dir) {
         if (is_dir($dir)) {
             @Filesystem::removeDirectory($dir);
         }
     });
     return $dir;
 }