/**
     * {@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)));
    }
Ejemplo n.º 2
0
 /**
  * Adds an attribute to the name.
  *
  * @param string $name  The attribute name. Must start with a letter and
  *                      contain letters, digits and hyphens only.
  * @param string $value The attribute value. Any non-empty string is
  *                      allowed.
  *
  * @see merge()
  */
 public function add($name, $value)
 {
     Assert::string($name, 'The attribute name must be a string. Got: %s');
     Assert::notEmpty($name, 'The attribute name must not be empty.');
     Assert::startsWithLetter($name, 'The attribute name %s must start with a letter.');
     Assert::true((bool) preg_match('~^[a-zA-Z][a-zA-Z0-9\\-]*$~', $name), sprintf('The attribute name must contain letters, numbers and hyphens only. Got: "%s"', $name));
     Assert::string($value, 'The attribute value must be a string. Got: %s');
     $this->attributes[$name] = $value;
 }
Ejemplo n.º 3
0
 /**
  * Creates the mapping.
  *
  * @param string $glob       A glob for resources in the repository.
  * @param string $targetName The name of the install target.
  * @param string $webPath    The web path of the resource in the install
  *                           target.
  * @param Uuid   $uuid       The UUID of the mapping.
  */
 public function __construct($glob, $targetName, $webPath, Uuid $uuid = null)
 {
     Assert::stringNotEmpty($glob, 'The glob must be a non-empty string. Got: %s');
     Assert::stringNotEmpty($targetName, 'The target name must be a non-empty string. Got: %s');
     Assert::string($webPath, 'The web path must be a string. Got: %s');
     $this->uuid = $uuid ?: Uuid::uuid4();
     $this->glob = $glob;
     $this->targetName = $targetName;
     $this->webPath = '/' . trim($webPath, '/');
 }
Ejemplo n.º 4
0
 /**
  * Creates the mapping.
  *
  * @param string $glob       A glob for resources in the repository.
  * @param string $serverName The name of the asset server.
  * @param string $serverPath The path of the resource in the document root
  *                           of the server.
  * @param Uuid   $uuid       The UUID of the mapping.
  */
 public function __construct($glob, $serverName, $serverPath, Uuid $uuid = null)
 {
     Assert::stringNotEmpty($glob, 'The glob must be a non-empty string. Got: %s');
     Assert::stringNotEmpty($serverName, 'The server name must be a non-empty string. Got: %s');
     Assert::string($serverPath, 'The public path must be a string. Got: %s');
     $this->uuid = $uuid ?: Uuid::uuid4();
     $this->glob = $glob;
     $this->serverName = $serverName;
     $this->serverPath = '/' . trim($serverPath, '/');
 }
    /**
     * {@inheritdoc}
     */
    public function generateNewInstance($varName, Method $targetMethod, GeneratorRegistry $generatorRegistry, array $options = array())
    {
        $options = array_replace(self::$defaultOptions, $options);
        Assert::string($options['host'], 'The host must be a string. Got: %s');
        Assert::integer($options['port'], 'The port must be an integer. Got: %s');
        $escHost = var_export($options['host'], true);
        $escPort = var_export($options['port'], true);
        $targetMethod->getClass()->addImports(array(new Import('Redis'), new Import('Webmozart\\KeyValueStore\\PhpRedisStore')));
        $targetMethod->addBody(<<<EOF
\$client = new Redis();
\$client->connect({$escHost}, {$escPort});
\${$varName} = new PhpRedisStore(\$client);
EOF
);
    }
Ejemplo n.º 6
0
    /**
     * {@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
);
    }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function getBindingType($typeName, $packageName)
 {
     Assert::string($typeName, 'The type name must be a string. Got: %s');
     Assert::string($packageName, 'The package name must be a string. Got: %s');
     $this->assertPackagesLoaded();
     if (!$this->typeDescriptors->contains($typeName, $packageName)) {
         throw NoSuchTypeException::forTypeName($typeName);
     }
     return $this->typeDescriptors->get($typeName, $packageName);
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function getTypeDescriptor($typeName, $moduleName)
 {
     Assert::string($typeName, 'The type name must be a string. Got: %s');
     Assert::string($moduleName, 'The module name must be a string. Got: %s');
     $this->assertModulesLoaded();
     if (!$this->typeDescriptors->contains($typeName, $moduleName)) {
         throw NoSuchTypeException::forTypeName($typeName);
     }
     return $this->typeDescriptors->get($typeName, $moduleName);
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function hasPathMapping($repositoryPath, $packageName)
 {
     Assert::string($repositoryPath, 'The repository path must be a string. Got: %s');
     Assert::string($packageName, 'The package name must be a string. Got: %s');
     $this->assertMappingsLoaded();
     return $this->mappings->contains($repositoryPath, $packageName);
 }
Ejemplo n.º 10
0
 /**
  * {@inheritdoc}
  */
 public function hasModule($name)
 {
     Assert::string($name, 'The module name must be a string. Got: %s');
     $this->assertModulesLoaded();
     return $this->modules->contains($name);
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function hasPackage($name)
 {
     Assert::string($name, 'The package name must be a string. Got: %s');
     $this->assertPackagesLoaded();
     return $this->packages->contains($name);
 }
Ejemplo n.º 12
0
 /**
  * Sets the version of the module file.
  *
  * @param string $version The module file version.
  */
 public function setVersion($version)
 {
     Assert::string($version, 'The module file version must be a string. Got: %s');
     Assert::regex($version, '~^\\d\\.\\d$~', 'The module file version must have the format "<digit>.<digit>". Got: %s</digit>');
     $this->version = $version;
 }