forked from jgmullor/AzureDistributionBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,74 @@ | |||
<?php | |||
/** | |||
* WindowsAzure TaskDemoBundle | |||
* | |||
* LICENSE | |||
* | |||
* This source file is subject to the MIT license that is bundled | |||
* with this package in the file LICENSE.txt. | |||
* If you did not receive a copy of the license and are unable to | |||
* obtain it through the world-wide-web, please send an email | |||
* to kontakt@beberlei.de so I can send you a copy immediately. | |||
*/ | |||
|
|||
namespace WindowsAzure\DistributionBundle\DependencyInjection\CompilerPass; | |||
|
|||
use Symfony\Component\DependencyInjection\ContainerBuilder; | |||
use Symfony\Component\DependencyInjection\Definition; | |||
use Symfony\Component\DependencyInjection\Reference; | |||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | |||
|
|||
/** | |||
* This will end up in the DoctrineBundle some day, but for now we have to | |||
* register the sharding manager here in an extra compiler pass. | |||
*/ | |||
class ShardingPass implements CompilerPassInterface | |||
{ | |||
public function process(ContainerBuilder $container) | |||
{ | |||
if ( ! $container->hasParameter('windows_azure_distribution.sharding')) { | |||
return; | |||
} | |||
|
|||
$shards = $container->getParameter('windows_azure_distribution.sharding'); | |||
|
|||
foreach ($shards as $connectionName => $options) { | |||
$this->registerShard($connectionName, $options, $container); | |||
} | |||
} | |||
|
|||
private function registerShard($connectionName, $options, $container) | |||
{ | |||
$id = 'doctrine.dbal.' . $connectionName . '_connection'; | |||
$shardId = 'windows_azure_task_demo.' . $connectionName . '_shard_manager'; | |||
|
|||
if ( ! $container->hasDefinition($id)) { | |||
throw new \InvalidArgumentException("No connection " . $connectionName . " found for federations."); | |||
} | |||
|
|||
$def = $container->findDefinition($id); | |||
$args = $def->getArguments(); | |||
|
|||
if ( ! isset($args[0]['driver']) || strpos($args[0]['driver'], 'sqlsrv') === false) { | |||
throw new \InvalidArgumentException("Sharding only possible with sqlsrv driver."); | |||
} | |||
|
|||
$args[0]['sharding'] = array( | |||
'federationName' => $options['federationName'], | |||
'distributionKey' => $options['distributionKey'], | |||
'distributionType' => $options['distributionType'], | |||
'filteringEnabled' => $options['filteringEnabled'], | |||
); | |||
|
|||
$def->setArguments($args); | |||
|
|||
$shardDef = new Definition('Doctrine\Shards\DBAL\SQLAzure\SQLAzureShardManager'); | |||
$shardDef->addArgument(new Reference($id)); | |||
$container->setDefinition($shardId, $shardDef); | |||
|
|||
if ($connection == 'default') { | |||
$container->setAlias('windows_azure_task_demo.shard_manager', $shardId); | |||
} | |||
} | |||
} | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
# Blob Storage | |||
|
|||
The Windows Azure Distribution Bundle comes with support for accessing Windows Blob Storage. | |||
This can be done using the [Azure Blob Storage](http://github.com/beberlei/aure-blob-storage) library. | |||
This library is a dependency that you have install. | |||
|
|||
You can configure blob storages from the config.yml (or config_azure.yml): | |||
|
|||
windows_azure_distribution: | |||
blob_storage: | |||
test: | |||
accountName: myacc | |||
accountKey: key | |||
test_with_stream: | |||
accountName: myacc2 | |||
accountKey: key2 | |||
stream: azure | |||
|
|||
There is not yet a mechanism to fallback to a local API if you dont want to hit | |||
blob storage during development, so you need to put the details into config.yml | |||
so it works in development. | |||
|
|||
With this configuration you can access the blob storage accounts from your | |||
controllers (or any services) using the storage registry service: | |||
|
|||
<?php | |||
namespace Vendor\AppBundle\Controller; | |||
|
|||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
|
|||
class MyController extends Controller | |||
{ | |||
public function indexAction() | |||
{ | |||
$registry = $this->container->get('windows_azure_distribution.storage_registry'); | |||
$client = $registry->get('test'); | |||
$client2 = $registry->get('test2'); | |||
|
|||
$streamFile = 'azure://container/test.jpg'; | |||
$data = file_get_contents($streamFile); | |||
} | |||
} | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
# Table Service | |||
|
|||
Note: Only works with Doctrine Common 2.2 | |||
|
|||
The Windows Azure Distribution bundle comes with support for accessing Windows Table Storage. | |||
This is done in combination with the [Doctrine KeyValueStore](http://github.com/doctrine/KeyValueStore) | |||
project. | |||
|
|||
You can configure the table manager with: | |||
|
|||
windows_azure_distribution: | |||
table: | |||
account: "acc" | |||
key: "key" | |||
|
|||
If you configured the manager and installed the Doctrine Key Value Store project you can access the | |||
table manager with: | |||
|
|||
<?php | |||
namespace Vendor\AppBundle\Controller; | |||
|
|||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |||
|
|||
class MyController extends Controller | |||
{ | |||
public function indexAction() | |||
{ | |||
$manager = $this->container->get('windows_azure_distribution.table.manager'); | |||
} | |||
} | |||
|
|||
Table entities can be any objects in your project, no additional configuration is necessary. Just |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters