Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function registerBundles()
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new Butenko\HomeBundle\ButenkoHomeBundle(),
);

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
Expand Down
1 change: 1 addition & 0 deletions app/config/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: "@ButenkoHomeBundle/Resources/config/services.xml"}

framework:
#esi: ~
Expand Down
4 changes: 4 additions & 0 deletions app/config/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
butenko_home:
resource: "@ButenkoHomeBundle/Resources/config/routing.yml"
prefix: /

4 changes: 2 additions & 2 deletions app/config/routing_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ _main:
resource: routing.yml

# AcmeDemoBundle routes (to be removed)
_acme_demo:
resource: "@AcmeDemoBundle/Resources/config/routing.yml"
#_acme_demo:
# resource: "@AcmeDemoBundle/Resources/config/routing.yml"
9 changes: 9 additions & 0 deletions src/Butenko/HomeBundle/ButenkoHomeBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Butenko\HomeBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class ButenkoHomeBundle extends Bundle
{
}
31 changes: 31 additions & 0 deletions src/Butenko/HomeBundle/Controller/DefaultController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Butenko\HomeBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DefaultController extends Controller
{
public function indexAction()
{
$result = $this->container
->get("my_service")
->simpleTask();
$fileExists = $this->container
->get("my_service")
->returnFilesystem()
->exists('/var/www/index.html');

$session = $this->container
->get('my_another_service')
->getSession();

$metaDataBag = $session->getMetadataBag();

return $this->render('ButenkoHomeBundle:Default:index.html.twig', array(
'result' => $result,
'filesystem' => $fileExists,
'metadatabag' => $metaDataBag
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Butenko\HomeBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class ButenkoHomeExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
29 changes: 29 additions & 0 deletions src/Butenko/HomeBundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Butenko\HomeBundle\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}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('butenko_home');

// Here you should define the parameters that are allowed to
// configure your bundle. See the documentation linked above for
// more information on that topic.

return $treeBuilder;
}
}
3 changes: 3 additions & 0 deletions src/Butenko/HomeBundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
butenko_home:
pattern: /
defaults: { _controller: ButenkoHomeBundle:Default:index }
36 changes: 36 additions & 0 deletions src/Butenko/HomeBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">


<parameters>
<parameter key="my_service.class">Butenko\HomeBundle\Service\MyService</parameter>
<parameter key="my_name">Jesus</parameter>
<parameter key="my_filesystem.class">Symfony\Component\Filesystem\Filesystem</parameter>
<parameter key="my_another_service.class">Butenko\HomeBundle\Service\MyAnotherService</parameter>
<parameter key="my_session.class">Symfony\Component\HttpFoundation\Session\Session</parameter>

</parameters>

<services>
<service id="my_filesystem" class="%my_filesystem.class%">
</service>

<service id="my_service" class="%my_service.class%">
<argument>%my_name%</argument>
<argument type="service" id="my_filesystem"></argument>
</service>

<service id="my_session" class="%my_session.class%">
</service>

<service id="my_another_service" class="%my_another_service.class%">
<call method="setSession">
<argument type="service" id="my_session"/>
</call>
</service>
</services>

</container>
7 changes: 7 additions & 0 deletions src/Butenko/HomeBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
# butenko_home.example.class: Butenko\HomeBundle\Example

services:
# butenko_home.example:
# class: %butenko_home.example.class%
# arguments: [@service_id, "plain_value", %parameter%]
12 changes: 12 additions & 0 deletions src/Butenko/HomeBundle/Resources/views/Default/index.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<p>1. Simple service that returns value of its parameter</p>
<p>This is {{ result }}!</p>

<p>2. Symfony's service Symfony\Component\Filesystem\Filesystem was injected via constructor</p>
<p>we can say that /var/www/index.html exists: {{ filesystem }}</p>

<p>3. Symfony's Symfony\Component\HttpFoundation\Session\Session was injected via setter</p>
<p>Something called metaDataBag's storageKey: {{ metadatabag.storageKey }}</p>

</br>
</br>
<p>Work on this task is still in progress...</p>
26 changes: 26 additions & 0 deletions src/Butenko/HomeBundle/Service/MyAnotherService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: kanni
* Date: 11/27/13
* Time: 10:07 PM
*/

namespace Butenko\HomeBundle\Service;

use Symfony\Component\HttpFoundation\Session\Session;

class MyAnotherService
{
private $session;

public function setSession(Session $session)
{
$this->session = $session;
}

public function getSession()
{
return $this->session;
}
}
34 changes: 34 additions & 0 deletions src/Butenko/HomeBundle/Service/MyService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* Created by PhpStorm.
* User: kanni
* Date: 11/27/13
* Time: 10:07 PM
*/

namespace Butenko\HomeBundle\Service;

use Symfony\Component\Filesystem\Filesystem;

class MyService
{
private $name;

private $filesystem;

public function __construct($name, Filesystem $filesystem)
{
$this->name = $name;
$this->filesystem = $filesystem;
}

public function simpleTask()
{
return 'Simple result of my fisrt service, '.$this->name;
}

public function returnFilesystem()
{
return $this->filesystem;
}
}
17 changes: 17 additions & 0 deletions src/Butenko/HomeBundle/Tests/Controller/DefaultControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Butenko\HomeBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DefaultControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();

$crawler = $client->request('GET', '/hello/Fabien');

$this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0);
}
}
8 changes: 4 additions & 4 deletions web/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
DirectoryIndex app_dev.php

<IfModule mod_rewrite.c>
RewriteEngine On
Expand All @@ -30,23 +30,23 @@ DirectoryIndex app.php
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteRule ^app_dev\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]

# Rewrite all other queries to the front controller.
RewriteRule .? %{ENV:BASE}/app.php [L]
RewriteRule .? %{ENV:BASE}/app_dev.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the start page to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
RedirectMatch 302 ^/$ /app_dev.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>