当前位置: 首页>>代码示例>>PHP>>正文


PHP Assert::keyExists方法代码示例

本文整理汇总了PHP中Puli\Manager\Assert\Assert::keyExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Assert::keyExists方法的具体用法?PHP Assert::keyExists怎么用?PHP Assert::keyExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Puli\Manager\Assert\Assert的用法示例。


在下文中一共展示了Assert::keyExists方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateNewInstance

 /**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
     $options = array_replace_recursive(self::$defaultOptions, $options);
     if (!isset($options['path'])) {
         $options['path'] = $targetMethod->getClass()->getDirectory() . '/path-mappings.json';
     }
     Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
     Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
     Assert::boolean($options['optimize'], 'The "optimize" option should be a boolean. Got: %s');
     Assert::isArray($options['change-stream'], 'The "change-stream" option should be an array. Got: %s');
     $path = Path::makeAbsolute($options['path'], $options['root-dir']);
     $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
     $relBaseDir = Path::makeRelative($options['root-dir'], $targetMethod->getClass()->getDirectory());
     $escPath = '__DIR__.' . var_export('/' . $relPath, true);
     $escBaseDir = $relBaseDir ? '__DIR__.' . var_export('/' . $relBaseDir, true) : '__DIR__';
     if ($options['optimize']) {
         $streamGenerator = $generatorRegistry->getServiceGenerator(GeneratorRegistry::CHANGE_STREAM, $options['change-stream']['type']);
         $streamOptions = $options['change-stream'];
         $streamOptions['root-dir'] = $options['root-dir'];
         $streamGenerator->generateNewInstance('stream', $targetMethod, $generatorRegistry, $streamOptions);
         $targetMethod->getClass()->addImport(new Import('Puli\\Repository\\OptimizedJsonRepository'));
         $targetMethod->addBody(sprintf('$%s = new OptimizedJsonRepository(%s, %s, false, $stream);', $varName, $escPath, $escBaseDir));
     } else {
         $targetMethod->getClass()->addImport(new Import('Puli\\Repository\\JsonRepository'));
         $targetMethod->addBody(sprintf('$%s = new JsonRepository(%s, %s, true);', $varName, $escPath, $escBaseDir));
     }
 }
开发者ID:xabbuh,项目名称:manager,代码行数:31,代码来源:JsonRepositoryGenerator.php

示例2: generateNewInstance

    /**
     * {@inheritdoc}
     */
    public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
    {
        Assert::keyExists($options, 'rootDir', 'The "rootDir" option is missing.');
        $options = array_replace(self::$defaultOptions, $options);
        if (!isset($options['path'])) {
            $options['path'] = $targetMethod->getClass()->getDirectory() . '/repository';
        }
        Assert::string($options['path'], 'The "path" option should be a string. Got: %s');
        Assert::string($options['rootDir'], 'The "rootDir" option should be a string. Got: %s');
        Assert::boolean($options['symlink'], 'The "symlink" option should be a boolean. Got: %s');
        $path = Path::makeAbsolute($options['path'], $options['rootDir']);
        $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
        $escPath = $relPath ? '__DIR__.' . var_export('/' . $relPath, true) : '__DIR__';
        if ($relPath) {
            $targetMethod->addBody(<<<EOF
if (!file_exists({$escPath})) {
    mkdir({$escPath}, 0777, true);
}

EOF
);
        }
        $targetMethod->getClass()->addImport(new Import('Puli\\Repository\\FilesystemRepository'));
        $targetMethod->addBody(sprintf('$%s = new FilesystemRepository(%s, %s);', $varName, $escPath, var_export($options['symlink'], true)));
    }
开发者ID:niklongstone,项目名称:manager,代码行数:28,代码来源:FilesystemRepositoryGenerator.php

示例3: generateNewInstance

 /**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
     $options = array_replace(self::$defaultOptions, $options);
     Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
     Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
     Assert::boolean($options['serialize-strings'], 'The "serialize-strings" option should be a boolean. Got: %s');
     Assert::boolean($options['serialize-arrays'], 'The "serialize-arrays" option should be a boolean. Got: %s');
     Assert::boolean($options['escape-slash'], 'The "escape-slash" option should be a boolean. Got: %s');
     Assert::boolean($options['pretty-print'], 'The "pretty-print" option should be a boolean. Got: %s');
     $path = Path::makeAbsolute($options['path'], $options['root-dir']);
     $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
     $flags = array();
     if (!$options['serialize-strings']) {
         $flags[] = 'JsonFileStore::NO_SERIALIZE_STRINGS';
     }
     if (!$options['serialize-arrays']) {
         $flags[] = 'JsonFileStore::NO_SERIALIZE_ARRAYS';
     }
     if (!$options['serialize-arrays']) {
         $flags[] = 'JsonFileStore::NO_ESCAPE_SLASH';
     }
     if ($options['pretty-print']) {
         $flags[] = 'JsonFileStore::PRETTY_PRINT';
     }
     $targetMethod->getClass()->addImport(new Import('Webmozart\\KeyValueStore\\JsonFileStore'));
     $targetMethod->addBody(sprintf('$%s = new JsonFileStore(%s%s%s);', $varName, $flags ? "\n    " : '', '__DIR__.' . var_export('/' . $relPath, true), $flags ? ",\n    " . implode("\n        | ", $flags) . "\n" : ''));
 }
开发者ID:xabbuh,项目名称:manager,代码行数:31,代码来源:JsonFileStoreGenerator.php

示例4: generateNewInstance

 /**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'rootDir', 'The "rootDir" option is missing.');
     $options = array_replace(self::$defaultOptions, $options);
     $path = Path::makeAbsolute($options['path'], $options['rootDir']);
     $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
     $targetMethod->getClass()->addImport(new Import('Webmozart\\KeyValueStore\\JsonFileStore'));
     $targetMethod->addBody(sprintf('$%s = new JsonFileStore(%s, %s);', $varName, '__DIR__.' . var_export('/' . $relPath, true), $options['cache'] ? 'true' : 'false'));
 }
开发者ID:niklongstone,项目名称:manager,代码行数:12,代码来源:JsonFileStoreGenerator.php

示例5: generateNewInstance

 /**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'rootDir', 'The "rootDir" option is missing.');
     $options = array_replace_recursive(self::$defaultOptions, $options);
     $kvsGenerator = $generatorRegistry->getServiceGenerator(GeneratorRegistry::KEY_VALUE_STORE, $options['store']['type']);
     $kvsOptions = $options['store'];
     $kvsOptions['rootDir'] = $options['rootDir'];
     $kvsGenerator->generateNewInstance('store', $targetMethod, $generatorRegistry, $kvsOptions);
     $targetMethod->getClass()->addImport(new Import('Puli\\Discovery\\KeyValueStoreDiscovery'));
     $targetMethod->addBody('$' . $varName . ' = new KeyValueStoreDiscovery($repo, $store);');
 }
开发者ID:niklongstone,项目名称:manager,代码行数:14,代码来源:KeyValueStoreDiscoveryGenerator.php

示例6: generateNewInstance

 /**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'rootDir', 'The "rootDir" option is missing.');
     $options = array_replace_recursive(self::$defaultOptions, $options);
     $kvsGenerator = $generatorRegistry->getServiceGenerator(GeneratorRegistry::KEY_VALUE_STORE, $options['store']['type']);
     $kvsOptions = $options['store'];
     $kvsOptions['rootDir'] = $options['rootDir'];
     $kvsGenerator->generateNewInstance('store', $targetMethod, $generatorRegistry, $kvsOptions);
     $className = ($options['optimize'] ? 'Optimized' : '') . 'PathMappingRepository';
     $targetMethod->getClass()->addImport(new Import('Puli\\Repository\\' . $className));
     $targetMethod->addBody(sprintf('$%s = new %s($store);', $varName, $className));
 }
开发者ID:kormik,项目名称:manager,代码行数:15,代码来源:PathMappingRepositoryGenerator.php

示例7: generateNewInstance

 /**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
     if (!isset($options['path'])) {
         $options['path'] = $targetMethod->getClass()->getDirectory() . '/change-stream.json';
     }
     Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
     Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
     $path = Path::makeAbsolute($options['path'], $options['root-dir']);
     $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
     $escPath = '__DIR__.' . var_export('/' . $relPath, true);
     $targetMethod->getClass()->addImport(new Import('Puli\\Repository\\ChangeStream\\JsonChangeStream'));
     $targetMethod->addBody(sprintf('$%s = new JsonChangeStream(%s);', $varName, $escPath));
 }
开发者ID:xabbuh,项目名称:manager,代码行数:17,代码来源:JsonChangeStreamGenerator.php

示例8: generateNewInstance

 /**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
     if (!isset($options['path'])) {
         $options['path'] = $targetMethod->getClass()->getDirectory() . '/bindings.json';
     }
     Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
     Assert::stringNotEmpty($options['path'], 'The "path" option should be a non-empty string. Got: %s');
     $path = Path::makeAbsolute($options['path'], $options['root-dir']);
     $relPath = Path::makeRelative($path, $targetMethod->getClass()->getDirectory());
     $escPath = '__DIR__.' . var_export('/' . $relPath, true);
     $targetMethod->getClass()->addImport(new Import('Puli\\Discovery\\JsonDiscovery'));
     $targetMethod->getClass()->addImport(new Import('Puli\\Discovery\\Binding\\Initializer\\ResourceBindingInitializer'));
     $targetMethod->addBody(sprintf("\$%s = new JsonDiscovery(%s, array(\n    new ResourceBindingInitializer(\$repo),\n));", $varName, $escPath));
 }
开发者ID:xabbuh,项目名称:manager,代码行数:18,代码来源:JsonDiscoveryGenerator.php

示例9: generateNewInstance

 /**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
     $options = array_replace_recursive(self::$defaultOptions, $options);
     Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
     Assert::isArray($options['store'], 'The "store" option should be an array. Got: %s');
     if (!isset($options['store']['path'])) {
         $options['store']['path'] = $targetMethod->getClass()->getDirectory() . '/change-stream.json';
     }
     $kvsGenerator = $generatorRegistry->getServiceGenerator(GeneratorRegistry::KEY_VALUE_STORE, $options['store']['type']);
     $kvsOptions = $options['store'];
     $kvsOptions['root-dir'] = $options['root-dir'];
     $kvsGenerator->generateNewInstance('store', $targetMethod, $generatorRegistry, $kvsOptions);
     $targetMethod->getClass()->addImport(new Import('Puli\\Repository\\ChangeStream\\KeyValueStoreChangeStream'));
     $targetMethod->addBody(sprintf('$%s = new KeyValueStoreChangeStream($store);', $varName));
 }
开发者ID:sensorario,项目名称:manager,代码行数:19,代码来源:KeyValueStoreChangeStreamGenerator.php

示例10: generateNewInstance

 /**
  * {@inheritdoc}
  */
 public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
 {
     Assert::keyExists($options, 'root-dir', 'The "root-dir" option is missing.');
     $options = array_replace_recursive(self::$defaultOptions, $options);
     Assert::stringNotEmpty($options['root-dir'], 'The "root-dir" option should be a non-empty string. Got: %s');
     Assert::isArray($options['store'], 'The "store" option should be an array. Got: %s');
     if (!isset($options['store']['path'])) {
         $options['store']['path'] = $targetMethod->getClass()->getDirectory() . '/bindings.json';
     }
     $kvsGenerator = $generatorRegistry->getServiceGenerator(GeneratorRegistry::KEY_VALUE_STORE, $options['store']['type']);
     $kvsOptions = $options['store'];
     $kvsOptions['root-dir'] = $options['root-dir'];
     $kvsGenerator->generateNewInstance('store', $targetMethod, $generatorRegistry, $kvsOptions);
     $targetMethod->getClass()->addImport(new Import('Puli\\Discovery\\KeyValueStoreDiscovery'));
     $targetMethod->getClass()->addImport(new Import('Puli\\Discovery\\Binding\\Initializer\\ResourceBindingInitializer'));
     $targetMethod->addBody(sprintf("\$%s = new KeyValueStoreDiscovery(\$store, array(\n    new ResourceBindingInitializer(\$repo),\n));", $varName));
 }
开发者ID:xabbuh,项目名称:manager,代码行数:20,代码来源:KeyValueStoreDiscoveryGenerator.php

示例11: generateNewInstance

    /**
     * {@inheritdoc}
     */
    public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
    {
        Assert::keyExists($options, 'bucket', 'The "bucket" option is missing.');
        $options = array_replace(self::$defaultOptions, $options);
        Assert::string($options['bucket'], 'The bucket must be a string. Got: %s');
        Assert::string($options['host'], 'The host must be a string. Got: %s');
        Assert::integer($options['port'], 'The port must be an integer. Got: %s');
        $escBucket = var_export($options['bucket'], true);
        $escHost = var_export($options['host'], true);
        $escPort = var_export($options['port'], true);
        $targetMethod->getClass()->addImports(array(new Import('Basho\\Riak\\Riak'), new Import('Webmozart\\KeyValueStore\\RiakStore')));
        $targetMethod->addBody(<<<EOF
\$client = new Riak({$escHost}, {$escPort});
\${$varName} = new RiakStore({$escBucket}, \$client);
EOF
);
    }
开发者ID:niklongstone,项目名称:manager,代码行数:20,代码来源:RiakStoreGenerator.php


注:本文中的Puli\Manager\Assert\Assert::keyExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。