Skip to content
This repository was archived by the owner on Apr 12, 2020. It is now read-only.
/ git-bundle Public archive

Commit 5fc34ba

Browse files
author
alexandresalome
committed
bootstrap
0 parents  commit 5fc34ba

29 files changed

+2499
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor
2+
/composer.lock
3+

DataCollector/GitDataCollector.php

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace Gitonomy\Bundle\GitBundle\DataCollector;
4+
5+
use Symfony\Component\HttpFoundation\Request;
6+
use Symfony\Component\HttpFoundation\Response;
7+
8+
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
9+
10+
use Monolog\Handler\TestHandler;
11+
use Monolog\Logger;
12+
13+
use Gitonomy\Git\Repository;
14+
15+
class GitDataCollector extends DataCollector
16+
{
17+
protected $handlers = array();
18+
19+
public function collect(Request $request, Response $response, \Exception $exception = null)
20+
{
21+
$this->data = array();
22+
23+
foreach ($this->handlers as $name => $handler) {
24+
$this->data[$name] = $handler->getRecords();
25+
}
26+
}
27+
28+
public function getName()
29+
{
30+
return 'git';
31+
}
32+
33+
/**
34+
* Injects Logger inside the repository.
35+
*/
36+
public function addRepository(Repository $repository)
37+
{
38+
if (null !== $repository->getLogger()) {
39+
throw new \RuntimeException('A logger is already injected in repository.');
40+
}
41+
42+
$name = $repository->getGitDir();
43+
$logger = new Logger($name);
44+
$handler = new TestHandler();
45+
$logger->pushHandler($handler);
46+
47+
$this->handlers[$name] = $handler;
48+
49+
$repository->setLogger($logger);
50+
}
51+
52+
public function getCount($name = null)
53+
{
54+
$count = 0;
55+
56+
// How to count run commands
57+
$callback = function ($entry) {
58+
return preg_match('/^run command/', $entry['message']);
59+
};
60+
61+
if ($name) {
62+
return array_sum(array_map($callback, $this->data[$name]));
63+
}
64+
65+
foreach ($this->data as $channel) {
66+
$count += array_sum(array_map($callback, $channel));
67+
}
68+
69+
return $count;
70+
}
71+
72+
public function getDuration($name = null)
73+
{
74+
$count = 0;
75+
76+
// How to count duration
77+
$callback = function ($entry) {
78+
if (preg_match('/duration: ([\d.]+)ms$/', $entry['message'], $vars)) {
79+
return (float) $vars[1];
80+
}
81+
82+
return 0;
83+
};
84+
85+
if ($name) {
86+
return array_sum(array_map($callback, $this->data[$name]));
87+
}
88+
89+
foreach ($this->data as $channel) {
90+
$count += array_sum(array_map($callback, $channel));
91+
}
92+
93+
return $count;
94+
}
95+
96+
public function getData()
97+
{
98+
return null === $this->data ? array() : $this->data;
99+
}
100+
}

DependencyInjection/Configuration.php

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Gitonomy.
5+
*
6+
* (c) Alexandre Salomé <[email protected]>
7+
* (c) Julien DIDIER <[email protected]>
8+
*
9+
* This source file is subject to the GPL license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace Gitonomy\Bundle\GitBundle\DependencyInjection;
14+
15+
use Gitonomy\Bundle\GitBundle\Routing\AbstractGitUrlGenerator;
16+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17+
use Symfony\Component\Config\Definition\ConfigurationInterface;
18+
19+
/**
20+
* Configuration of the Gitonomy core bundle.
21+
*
22+
* @author Alexandre Salomé <[email protected]>
23+
*/
24+
class Configuration implements ConfigurationInterface
25+
{
26+
const DEFAULT_THEME = 'GitonomyGitBundle::default_theme.html.twig';
27+
28+
/**
29+
* @inheritdoc
30+
*/
31+
public function getConfigTreeBuilder()
32+
{
33+
$treeBuilder = new TreeBuilder();
34+
$rootNode = $treeBuilder->root('gitonomy_twig');
35+
36+
$current = $rootNode
37+
->children()
38+
->booleanNode('profiler')->defaultFalse()->end()
39+
->arrayNode('twig_extension')
40+
->beforeNormalization()
41+
->ifTrue()
42+
->then(function () { return array('enabled' => true); })
43+
->end()
44+
->addDefaultsIfNotSet()
45+
->children()
46+
->booleanNode('enabled')->defaultFalse()->end()
47+
->booleanNode('profiler')->defaultFalse()->end()
48+
->arrayNode('routes_names')
49+
->addDefaultsIfNotSet()
50+
->children()
51+
;
52+
53+
foreach (AbstractGitUrlGenerator::getRouteNames() as $name => $value) {
54+
$current->scalarNode($name)->defaultValue($value)->end();
55+
}
56+
57+
$current = $current
58+
->end()
59+
->end()
60+
->arrayNode('routes_args')
61+
->addDefaultsIfNotSet()
62+
->children()
63+
;
64+
65+
foreach (AbstractGitUrlGenerator::getRouteArgs() as $name => $value) {
66+
$current->scalarNode($name)->defaultValue($value)->end();
67+
}
68+
69+
$current
70+
->end()
71+
->end()
72+
->arrayNode('themes')
73+
->normalizeKeys(false)
74+
->useAttributeAsKey('key')
75+
->beforeNormalization()
76+
->always(function ($e) {
77+
if (!in_array(self::DEFAULT_THEME, $e)) {
78+
$e[] = self::DEFAULT_THEME;
79+
}
80+
81+
return $e;
82+
})
83+
->end()
84+
->defaultValue(array(self::DEFAULT_THEME))
85+
->prototype('scalar')
86+
->end()
87+
->end()
88+
->end()
89+
;
90+
91+
return $treeBuilder;
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Gitonomy.
5+
*
6+
* (c) Alexandre Salomé <[email protected]>
7+
* (c) Julien DIDIER <[email protected]>
8+
*
9+
* This source file is subject to the GPL license that is bundled
10+
* with this source code in the file LICENSE.
11+
*/
12+
13+
namespace Gitonomy\Bundle\GitBundle\DependencyInjection;
14+
15+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
18+
use Symfony\Component\Config\FileLocator;
19+
20+
/**
21+
* @author Alexandre Salomé <[email protected]>
22+
*/
23+
class GitonomyTwigExtension extends Extension
24+
{
25+
/**
26+
* @inheritdoc
27+
*/
28+
public function load(array $configs, ContainerBuilder $container)
29+
{
30+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
31+
//$loader->load('profiler.xml');
32+
33+
$configuration = new Configuration();
34+
$config = $this->processConfiguration($configuration, $configs);
35+
36+
if ($config['profiler']) {
37+
$loader->load('profiler.xml');
38+
}
39+
40+
if ($config['twig_extension']['enabled']) {
41+
$loader->load('routing.xml');
42+
$loader->load('twig.xml');
43+
44+
$container->setParameter('gitonomy_twig.themes', $config['twig_extension']['themes']);
45+
$container->setParameter('gitonomy_twig.url_generator.routes_names', $config['twig_extension']['routes_names']);
46+
$container->setParameter('gitonomy_twig.url_generator.routes_args', $config['twig_extension']['routes_args']);
47+
}
48+
}
49+
}

GitonomyGitBundle.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Gitonomy\Bundle\GitBundle;
4+
5+
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
7+
class GitonomyGitBundle extends Bundle
8+
{
9+
}

README.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
GitonomyGitBundle
2+
=================
3+
4+
This bundle provides git features for your twig-based application.
5+
6+
Please read `the documentation <Resources/doc/index.rst>`.

Resources/config/profiler.xml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="gitonomy_twig.git.data_collector.class">Gitonomy\Bundle\GitBundle\DataCollector\GitDataCollector</parameter>
9+
</parameters>
10+
11+
<services>
12+
<service id="gitonomy_twig.git.data_collector" class="%gitonomy_twig.git.data_collector.class%">
13+
<tag name="data_collector" id="git" template="GitonomyGitBundle:Profiler:git.html.twig" />
14+
</service>
15+
</services>
16+
</container>

Resources/config/routing.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="gitonomy_twig.url_generator.class">Gitonomy\Bundle\GitBundle\Routing\GitUrlGenerator</parameter>
9+
</parameters>
10+
<services>
11+
<service id="gitonomy_twig.url_generator" class="%gitonomy_twig.url_generator.class%" public="false">
12+
<argument type="service" id="router" />
13+
<argument>%gitonomy_twig.url_generator.routes_names%</argument>
14+
<argument>%gitonomy_twig.url_generator.routes_args%</argument>
15+
</service>
16+
</services>
17+
18+
</container>

Resources/config/twig.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="gitonomy_twig.twig.gitonomy.class">Gitonomy\Bundle\GitBundle\Twig\GitExtension</parameter>
9+
</parameters>
10+
<services>
11+
<service id="gitonomy_twig.git_extension" class="%gitonomy_twig.twig.gitonomy.class%" public="false">
12+
<tag name="twig.extension" />
13+
<argument type="service" id="gitonomy_twig.url_generator" />
14+
<argument>%gitonomy_twig.themes%</argument>
15+
</service>
16+
</services>
17+
18+
</container>

Resources/doc/index.rst

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Gitonomy GitBundle
2+
==================
3+
4+
GitonomyGitBundle gives you ability to easily render blocks about git:
5+
6+
* File diff
7+
* Commit informations
8+
* Graph logs
9+
* ...
10+
11+
Installation
12+
------------
13+
14+
* `Install the bundle in a Symfony2 application <install/symfony2.rst>`_
15+
* `Install in a boilerplate PHP application <install/raw.rst>`_
16+
17+
Usage
18+
-----
19+
20+
* `Render git blocks <usage/blocks.rst>`_
21+
* `Generate links <usage/links.rst>`_
22+
* `Extending blocks <usage/extend.rst>`_

Resources/doc/install/raw.rst

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Install in a boilerplate application
2+
------------------------------------
3+
4+
Not everybody is using Symfony2 framework and some people might
5+
need an integration of this bundle within a custom installation.
6+
7+
Gitonomy GitBundle gives you possibility to reuse Twig code
8+
without the bundle integration.
9+
10+
To do so, make sure you have enabled autoloading of bundle classes.
11+
12+
When it's done, add the extension to your Twig:
13+
14+
.. code-block:: php
15+
16+
use Gitonomy\Bundle\GitBundle\Twig\GitExtension;
17+
use Gitonomy\Bundle\GitBundle\Routing\GitUrlGeneratorInterface;
18+
use Symfony\Component\Routing\UrlGeneratorInterface;
19+
20+
$router instanceof UrlGeneratorInterface;
21+
22+
$generator = new GitUrlGenerator($router);
23+
$extension = new GitExtension($generator, array(
24+
'@GitonomyGitBundle/default_theme.html.twig'
25+
));
26+
27+
$twig->addExtension($extension);
28+
$twig->addPath('/path/to/Gitonomy/Bundle/GitBundle/Resources/views', '@GitonomyGitBundle');
29+

0 commit comments

Comments
 (0)