AcmeMyExtension::getAlias()
use Symfony\C..\D..I..\ContainerBuilder as CB;
use Symfony\C..\Config\FileLocator;
use Symfony\C..\HttpKernel\D..I..\Extension;
use Symfony\..\D..I..\Loader\XmlFileLoader;
class AcmeMyExtension extends Extension
{
public function load(array $configs, CB $dic)
{
$configuration = new Configuration();
$config = $this->processConfiguration(
$configuration, $configs
);
$dir = __DIR__ . '/../Resources/config';
$locator = new FileLocator($dir);
$loader = new XmlFileLoader($dic, $locator);
$loader->load('services.xml');
foreach ($config as $key => $val) {
$dic->setParameter('acme_my.'.$key, $val);
}
}
}
use Symfony\C..\Config\Definition as Def;
class Configuration implements Def\ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new Def\Builder\TreeBuilder();
$treeBuilder->root('acme_my')
->children()
->scalarNode('host')
->isRequired()->cannotBeEmpty()->end()
->scalarNode('port')
->defaultValue(2000)->end()
->scalarNode('timeout')
->defaultValue(30000)->end()
->end()
;
return $treeBuilder;
}
}
repositories
directive to make composer aware of specific (closed source) repositories{
"name": "acme/my-bundle",
"type": "symfony-bundle",
"description": "This Bundle is an example",
"license": "MIT",
"authors": [
{
"name": "Duffy Duck",
"email": "diffy@acme.com"
}
],
"require": {
"php": ">=5.3.3",
"symfony/framework-bundle": "~2.3",
},
"autoload": {
"psr-4": { "Acme\\MyBundle": "" }
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
}
}
}
repositories
directive to make composer aware of specific (closed source) repositoriesuse Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class HomepageTest extends WebTestCase
{
public function testContents()
{
$client = $this->createClient();
$crawler = $client->request('GET', '/');
$s = $client->getResponse()->getStatusCode();
$this->assertEquals(200, $s);
$crawler->filter('h1:contains(Homepage)');
$this->assertCount(1, $count);
$crawler->filter('ul.menu_main li')
$this->assertCount(13, $count);
}
}
language: php
php: [ 5.4, 5.5, 5.6, hhvm]
env: [ SYMFONY_VERSION=2.5.* ]
matrix:
include:
- php: 5.5
env: SYMFONY_VERSION=2.3.*
- php: 5.5
env: SYMFONY_VERSION=2.6.*
before_script:
- composer require symfony/symfony:${SYMFONY_VERSION} --prefer-source
script: phpunit --coverage-text
app/Resources/FOSUserBundle/views/Security/login.html.twig
src/Acme/MyBundle/Resources/views/Security/login.html.twig
src/Acme/MyBundle/Controller/SecurityController.php
use Symfony\Component\HttpKernel\Bundle\Bundle;
class MyBundle extends Bundle
{
public function getParent()
{
return 'FOSUserBundle';
}
}
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mygithub/SomeSuperBundle"
}
],
"require" : {
"php": ">=5.3.3",
"symfony/symfony": "~2.3",
"some/super-bundle": "dev-add-rocknroll as 1.2.0"
}
}
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class MyController extends Controller
{
/**
* Get the list of articles
*
* @return array data
*
* @Secure(roles="ROLE_ADMIN")
*/
public function getArticlesAction()
{
/*
$security = $this->get('security.context');
if ($security->isGranted('ROLE_ADMIN')) {
throw new AccessDeniedException();
}
*/
$data = json_encode(array('bim', 'bam', 'bingo'));
return new Response($data);
}
}
use JMS\SerializerBundle\Annotation as Serializer;
use JMS\SerializerBundle\Annotation\XmlList;
use Doctrine\Common\Collections\Collection;
/**
* @Serializer\XmlRoot("response")
*/
class ArticleResponse
{
/**
* @var Collection
* @XmlList(inline = true, entry = "article")
*/
protected $articles;
protected $page;
public function __construct(Collection $a, $page)
{
$this->articles = $a;
$this->page = $page;
}
}
use Acme\MyBundle\ArticleResponse;
class RestController
{
/**
* Get the list of articles
* route name: liip_hello_rest_get_articles
* pattern: /liip/hello/rest/articles.{_format}
* http method requirement: GET
*
* @param string $page page number
* @return array data
*
* @View()
* @QueryParam(name="page",
* requirements="\d+",
* default="1")
* @ApiDoc()
*/
public function getArticlesAction($page)
{
$articles = array('bim', 'bam', 'bingo');
return new ArticleResponse($articles, $page);
}
}
<html>
<body>
<div>
<div>bim</div>
<div>bam</div>
<div>bingo</div>
</div>
<div>page: 2</div>
</body>
</html>
<response>
<article>bim</article>
<article>bam</article>
<article>bingo</article>
<page>2</page>
</response>
{
"articles": [
"bim",
"bam",
"bingo"
],
"page": "2"
}
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/** @ORM\Entity() */
class Post
{
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
protected $createdAt;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="update")
*/
protected $updatedAt;
}
Renders the menu with several renderers:
Pluggable data providers
{% extends "LiipHelloBundle::layout.html.twig" %}
{% block content %}
<div>
original:<br>
<img src="{{ '/bundles/hello/images/test.jpg' }}"/>
</div>
<div>
LiipImagineBundle in action:<br>
<img src="{{ '/bundles/hello/images/test.png'
| imagine_filter('my_thumb') }}"/>
</div>
<div>
LiipImagineBundle in action:<br>
<img src="{{ '/bundles/hello/images/test.png'
| imagine_filter('my_thumb', true) }}"/>
</div>
{% endblock content %}
.. and what are you looking for?
.. what feature you need in your next project and lets see if we can find a Bundle for you ..