Skip to content

Commit

Permalink
Rewrite with support for the latest PHP SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Apr 6, 2018
1 parent cf0fe07 commit 66d3e22
Show file tree
Hide file tree
Showing 27 changed files with 577 additions and 386 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab

[.travis.yml]
indent_size = 2
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.php diff=php

/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs export-ignore
/phpunit.xml.dist export-ignore
16 changes: 16 additions & 0 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#### 1. Which version of `kreait/firebase-php` and `kreait/firebase-bundle` are you using?

*You can use `composer show kreait/firebase-bundle` and `composer show kreait/firebase-bundle`
to see the installed version in the `versions` line.*

#### 2. Which version of PHP are you using?

*You can use `php -v` on the system the issue occurs on to get the PHP version.*

#### 3. What's the issue?

*Please don't just copy and paste a PHP exception trace.*

#### 4. Code that lead to the issue

*Please use [syntax highlighted code blocks](https://help.github.com/articles/creating-and-highlighting-code-blocks/) with code that can be used to reproduce the issue.*
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/build/
/vendor/
composer.lock
/build
/vendor

/.php_cs.cache
/composer.lock
/phpunit.xml
17 changes: 17 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude(['build', 'vendor'])
->in(__DIR__);

return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRules([
'@Symfony' => true,
'header_comment' => ['header' => ''],
'phpdoc_align' => false,
'phpdoc_order' => true,
'ordered_imports' => true,
'array_syntax' => ['syntax' => 'short'],
])
->setFinder($finder);
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php

php:
- 7.0
- 7.1

sudo: false

install: travis_retry composer update

script:
- vendor/bin/phpunit
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## Unreleased

* Initial release with support for `kreait/firebase-php` ^4.0

## 0.5 - 2015-12-07

* Updated dependencies to add support for PHPUnit and Symfony 3.0.
Expand Down
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
82 changes: 34 additions & 48 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,68 +1,54 @@
<?php

namespace Kreait\FirebaseBundle\DependencyInjection;
declare(strict_types=1);

namespace Kreait\Firebase\Symfony\Bundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
* @var string
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('kreait_firebase');
private $name;

$rootNode->children()
->append($this->addConnectionsNode());

return $treeBuilder;
public function __construct(string $name)
{
$this->name = $name;
}

/**
* {@inheritdoc}
*/
public function addConnectionsNode()
public function getConfigTreeBuilder()
{
$builder = new TreeBuilder();
$node = $builder->root('connections');

$node
->isRequired()
->requiresAtLeastOneElement()
->useAttributeAsKey('connection')
->prototype('array')
->children()
->scalarNode('scheme')->defaultValue('https')->end()
->scalarNode('host')->isRequired()->end()
->scalarNode('secret')->end()
->append($this->addReferencesNode())
$root = $builder->root($this->name);

$root
->fixXmlConfig('project')
->children()
->arrayNode('projects')
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('credentials')
->info('Path to the Google Service Account credentials file for this project.')
->example('%kernel.project_dir%/config/credentials.json')
->end()
->scalarNode('public')
->defaultTrue()
->info('If set to false, the service and its alias can only be used via dependency injection')
->end()
->scalarNode('database_uri')
->example('https://my-project.firebaseio.com')
->info('You can find the database URI in the project settings in the Firebase console')
->end()
->scalarNode('alias')->end()
->end()
->end()
->end()
->end();

return $node;
}

/**
* {@inheritdoc}
*/
public function addReferencesNode()
{
$builder = new TreeBuilder();
$node = $builder->root('references');

$node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('scalar');

return $node;
return $builder;
}
}
37 changes: 37 additions & 0 deletions DependencyInjection/Factory/ProjectFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Kreait\Firebase\Symfony\Bundle\DependencyInjection\Factory;

use Kreait\Firebase;
use Kreait\Firebase\Factory;

class ProjectFactory
{
/**
* @var Factory
*/
private $firebaseFactory;

public function __construct(Factory $firebaseFactory)
{
$this->firebaseFactory = $firebaseFactory;
}

public function create(array $config = []): Firebase
{
$factory = clone $this->firebaseFactory; // Ensure a new instance

if ($config['credentials'] ?? null) {
$serviceAccount = Firebase\ServiceAccount::fromValue($config['credentials']);
$factory = $factory->withServiceAccount($serviceAccount);
}

if ($config['database_uri'] ?? null) {
$factory = $this->firebaseFactory->withDatabaseUri($config['database_uri']);
}

return $factory->create();
}
}
56 changes: 56 additions & 0 deletions DependencyInjection/FirebaseExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace Kreait\Firebase\Symfony\Bundle\DependencyInjection;

use Kreait\Firebase;
use Kreait\Firebase\Symfony\Bundle\DependencyInjection\Factory\ProjectFactory;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;

class FirebaseExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('firebase.xml');

foreach ($config['projects'] ?? [] as $projectName => $projectConfiguration) {
$this->processProjectConfiguration($projectName, $projectConfiguration, $container);
}
}

private function processProjectConfiguration($name, array $config, ContainerBuilder $container)
{
$projectServiceId = sprintf('%s.%s', $this->getAlias(), $name);
$isPublic = $config['public'];

$container->register($projectServiceId, Firebase::class)
->setFactory([new Reference(ProjectFactory::class), 'create'])
->addArgument($config)
->setPublic($isPublic);

if ($config['alias'] ?? null) {
$alias = $container->setAlias($config['alias'], $projectServiceId);
$alias->setPublic($isPublic);
}
}

public function getAlias()
{
return 'kreait_firebase';
}

public function getConfiguration(array $config, ContainerBuilder $container)
{
return new Configuration($this->getAlias());
}
}
Loading

0 comments on commit 66d3e22

Please sign in to comment.