Skip to content

Commit 1759b3f

Browse files
committed
Merge branch 'release/v0.0.5'
2 parents 90b2f24 + e7e42fa commit 1759b3f

File tree

6 files changed

+1260
-108
lines changed

6 files changed

+1260
-108
lines changed

Collection/GitElephantRepositoryCollection.php

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<?php
2-
/**
3-
* User: matteo
4-
* Date: 20/01/12
5-
* Time: 21.49
6-
*
7-
* Just for fun...
8-
*/
92

103
namespace Cypress\GitElephantBundle\Collection;
114

125
use GitElephant\Repository;
136

7+
/**
8+
* Class GitElephantRepositoryCollection
9+
*
10+
* @category Collection
11+
* @package Cypress\GitElephantBundle\Collection
12+
* @author Matteo Giachino <https://github.com/matteosister>
13+
*/
1414
class GitElephantRepositoryCollection implements \ArrayAccess, \Iterator, \Countable
1515
{
1616
/**
@@ -33,12 +33,13 @@ class GitElephantRepositoryCollection implements \ArrayAccess, \Iterator, \Count
3333
* )
3434
*
3535
* @param array $repositories an array of repository classes
36+
* @param null $binary
3637
*/
3738
public function __construct($repositories, $binary = null)
3839
{
39-
$this->position = 0;
40+
$this->position = 0;
4041

41-
foreach($repositories as $name => $path) {
42+
foreach ($repositories as $name => $path) {
4243
$repository = new Repository($path, $binary);
4344
$repository->setName($name);
4445
$this->repositories[] = $repository;
@@ -50,16 +51,17 @@ public function __construct($repositories, $binary = null)
5051
*
5152
* @param string $name the repository name
5253
*
53-
* @return \GitElephant\Repository $repository
54+
* @return Repository $repository
5455
*/
5556
public function get($name)
5657
{
57-
foreach($this->repositories as $repository)
58-
{
58+
/** @var Repository $repository */
59+
foreach ($this->repositories as $repository) {
5960
if ($repository->getName() == $name) {
6061
return $repository;
6162
}
6263
}
64+
6365
return null;
6466
}
6567

Collector/GitElephantDataCollector.php

+35-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
<?php
2-
/**
3-
* User: matteo
4-
* Date: 19/01/12
5-
* Time: 21.07
6-
*
7-
* Just for fun...
8-
*/
92

103
namespace Cypress\GitElephantBundle\Collector;
114

@@ -14,11 +7,23 @@
147
use Symfony\Component\HttpFoundation\Response;
158
use GitElephant\Repository;
169

10+
/**
11+
* Class GitElephantDataCollector
12+
*
13+
* @category Collector
14+
* @package Cypress\GitElephantBundle\Collector
15+
* @author Matteo Giachino <https://github.com/matteosister>
16+
*/
1717
class GitElephantDataCollector extends DataCollector
1818
{
1919
private $repository;
2020
private $enabled;
2121

22+
/**
23+
* Constructor
24+
*
25+
* @param $path
26+
*/
2227
public function __construct($path)
2328
{
2429
if ($path == false) {
@@ -29,24 +34,46 @@ public function __construct($path)
2934
}
3035
}
3136

37+
/**
38+
* Collect
39+
*
40+
* @param Request $request
41+
* @param Response $response
42+
* @param \Exception $exception
43+
*/
3244
public function collect(Request $request, Response $response, \Exception $exception = null)
3345
{
3446
$this->data = array(
3547
'repository' => $this->repository !== null ? $this->repository : null,
36-
'enabled' => $this->enabled
48+
'enabled' => $this->enabled
3749
);
3850
}
3951

52+
/**
53+
* Get repository
54+
*
55+
* @return mixed
56+
*/
4057
public function getRepository()
4158
{
4259
return $this->data['repository'];
4360
}
4461

62+
/**
63+
* Get enabled
64+
*
65+
* @return mixed
66+
*/
4567
public function getEnabled()
4668
{
4769
return $this->data['enabled'];
4870
}
4971

72+
/**
73+
* Get name
74+
*
75+
* @return string
76+
*/
5077
public function getName()
5178
{
5279
return 'git_elephant';

Command/TagCommand.php

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace Cypress\GitElephantBundle\Command;
4+
5+
use Cypress\GitElephantBundle\Collection\GitElephantRepositoryCollection;
6+
use GitElephant\Repository;
7+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Input\InputOption;
11+
use Symfony\Component\Console\Output\Output;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
use Symfony\Component\Console\Helper\ProgressHelper;
14+
15+
/**
16+
* Class TagCommand
17+
*
18+
* @category Command
19+
* @package Cypress\GitElephantBundle\Command
20+
* @author David Romaní <[email protected]>
21+
*/
22+
class TagCommand extends ContainerAwareCommand
23+
{
24+
/**
25+
* Tag command configuration
26+
*/
27+
protected function configure()
28+
{
29+
$this->setName('cypress:git:tag')
30+
->setDefinition(
31+
array(
32+
new InputArgument(
33+
'tag',
34+
InputArgument::REQUIRED,
35+
'Tag title'
36+
),
37+
new InputArgument(
38+
'comment',
39+
InputArgument::OPTIONAL,
40+
'Tag comment'
41+
),
42+
)
43+
)
44+
->setDescription('Tag current commit and push to remote repository')
45+
->addOption(
46+
'no-push',
47+
null,
48+
InputOption::VALUE_NONE,
49+
'If set, the task won\'t push tag to remote repository'
50+
)
51+
->addOption(
52+
'all',
53+
null,
54+
InputOption::VALUE_NONE,
55+
'If set, will tag all repositories'
56+
)
57+
->setHelp(
58+
<<<EOT
59+
<info>cypress:git:tag</info> command will tag your current commit and (optionally) push to remote repository. Only apply fisrt repository, use --all option to apply all repositories.
60+
EOT
61+
);
62+
}
63+
64+
/**
65+
* Execute tag command
66+
*
67+
* @param InputInterface $input
68+
* @param OutputInterface $output
69+
*
70+
* @throws \Exception
71+
* @return int|null|void
72+
*/
73+
protected function execute(InputInterface $input, OutputInterface $output)
74+
{
75+
// Welcome
76+
$output->writeln(
77+
'<info>Welcome to the Cypress GitElephantBundle tag command.</info>'
78+
);
79+
if ($input->getOption('no-push')) {
80+
$output->writeln(
81+
'<comment>--no-push option enabled (this option disable push tag to remote repository)</comment>'
82+
);
83+
}
84+
85+
/** @var GitElephantRepositoryCollection $rc */
86+
$rc = $this->getContainer()->get('git_repositories');
87+
88+
if ($rc->count() == 0) {
89+
throw new \Exception('Must have at least one Git repository. See https://github.com/matteosister/GitElephantBundle#how-to-use');
90+
}
91+
92+
/** @var Repository $repository */
93+
foreach ($rc as $key => $repository) {
94+
if ($key == 0 || $key > 0 && $input->getOption('all')) {
95+
$repository->createTag($input->getArgument('tag'), null, $input->getArgument('comment') ? $input->getArgument('comment') : null);
96+
if (!$input->getOption('no-push')) {
97+
$repository->push();
98+
}
99+
$output->writeln('Set tag ' . $input->getArgument('tag') . ' to repository ' . $repository->getName() . (!$input->getOption('no-push') ? ' and push.' : ''));
100+
}
101+
}
102+
}
103+
}

README.md

+54-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Watch a [simple live example](http://gitelephant.cypresslab.net/GitElephant) of
1212
How to install
1313
--------------
1414

15-
**Method 1 - deps file**
15+
**Method 1 - deps file (for Symfony 2.1 and below)**
1616

1717
- Add the GitElephant library and the bundle itself in the deps file
1818

@@ -26,25 +26,41 @@ How to install
2626
git=git://github.com/matteosister/GitElephantBundle.git
2727
target=/bundles/Cypress/GitElephantBundle
2828

29-
- register the two namespaces in the autoload.php file
29+
- Register the two namespaces in the autoload.php file
3030

3131
*app/autoload.php*
3232

3333
``` php
34-
<?php
3534
$loader->registerNamespaces(array(
3635
// ...other namespaces
3736
'GitElephant' => __DIR__.'/../vendor/git-elephant/src',
3837
'Cypress' => __DIR__.'/../vendor/bundles',
3938
));
4039
```
4140

42-
- register the bundle in the kernel file
41+
**Method 2 - composer (recommended)**
42+
43+
- Add the following line to the `composer.json` file:
44+
45+
``` json
46+
{
47+
"require": {
48+
"cypresslab/gitelephant-bundle": "dev-master"
49+
}
50+
}
51+
```
52+
53+
- Execute composer update command
54+
55+
``` bash
56+
$ composer update
57+
```
58+
59+
- Register the bundle in the kernel file
4360

4461
*app/AppKernel.php*
4562

4663
``` php
47-
<?php
4864
class AppKernel extends Kernel
4965
{
5066
public function registerBundles()
@@ -59,7 +75,28 @@ class AppKernel extends Kernel
5975
}
6076
```
6177

62-
**Method 2 - submodules**
78+
>Is recommended to register this bundle only in development environment for safety reasons.
79+
80+
``` php
81+
class AppKernel extends Kernel
82+
{
83+
public function registerBundles()
84+
{
85+
$bundles = array(
86+
// ...other bundles
87+
);
88+
89+
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
90+
// ...other development and testing bundles
91+
$bundles[] = new Cypress\GitElephantBundle\CypressGitElephantBundle();
92+
}
93+
94+
return $bundles;
95+
}
96+
}
97+
```
98+
99+
**Method 3 - submodules**
63100

64101
You can also manage the two git repositories with git and submodules. It could be a mess if you don't know what you do, but I personally prefer this way
65102

@@ -103,7 +140,6 @@ Now, inside your controllers, you can easily access the GitElephant library with
103140
The repository path could also be a bare repository (useful for web servers). But without a checked out copy you won't be able to modify the repository state. You will be able to show the repository, but not, for example, create a new commit
104141

105142
``` php
106-
<?php
107143
class AwesomeController extends Controller
108144
{
109145
/**
@@ -146,6 +182,17 @@ Add this to your **dev** configuration file *app/config/config_dev.yml*
146182

147183
If you use git with Symfony2, with the above configuration, you can see directly from the browser the branch you are in. Click on the icon and you get a list of the last 10 commits for the branch you are in.
148184

185+
Available console commands
186+
--------------------------
187+
188+
**cypress:git:tag**
189+
190+
This command is useful to tag current commit and push to remote repository.
191+
192+
``` bash
193+
$ php app/console cypress:git:tag [--no-push] [--all] tag [comment]
194+
```
195+
149196
Example
150197
-------
151198

composer.json

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
],
1515
"require": {
1616
"php": ">=5.3.2",
17+
"symfony/config": "~2.3",
18+
"symfony/console": "~2.3",
19+
"symfony/dependency-injection": "~2.3",
20+
"symfony/framework-bundle": "~2.3",
21+
"symfony/http-foundation": "~2.3",
22+
"symfony/http-kernel": "~2.3",
1723
"cypresslab/gitelephant": "*"
1824
},
1925
"autoload": {

0 commit comments

Comments
 (0)