Sf2 wtf
Upcoming SlideShare
Loading in...5
×
 

Sf2 wtf

on

  • 1,323 views

Symfony2 è sicuramente uno dei framework migliori in circolazione, ma non sono tutte rose e fiori, soprattutto per chi inizia a sviluppare ed è alle prime armi. In questa presentazione vorrei ...

Symfony2 è sicuramente uno dei framework migliori in circolazione, ma non sono tutte rose e fiori, soprattutto per chi inizia a sviluppare ed è alle prime armi. In questa presentazione vorrei condividere la mie esperienza di apprendimento ed utilizzo del framework, cercando di mettere in evidenza i miei momenti wtf e alcune linee guida per sviluppare applicazioni manutenibili

Statistics

Views

Total Views
1,323
Slideshare-icon Views on SlideShare
1,316
Embed Views
7

Actions

Likes
3
Downloads
11
Comments
0

2 Embeds 7

https://twitter.com 5
http://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Sf2 wtf Sf2 wtf Presentation Transcript

    • My Symfony WTF
    • Michele Orselli CTO@Ideato @_orso_ mo@ideato.it Who am I?
    • Why a talk on WTF? why a talk on WTF?
    • I♥ why a talk on WTF?
    • but... why a talk on WTF?
    • why a talk on WTF?
    • why a talk on WTF?
    • why a talk on WTF?
    • why a talk on WTF?
    • symfony 1 was focused on Rapid Application Development the (old) times?
    • Symfony2 is focused on Application Development the shiny new thing
    • the shiny new thing
    • the shiny new thing
    • the shiny new thing
    • speed as selling point
    • create-project symfony/framework-standard-edition ./foo 2.3.0 installation
    • cache/log permissions
    • cache/log permissions
    • php app/console cache:clear cache/log permissions
    • cache/log permissions
    • cache all the things (in dev too)!
    • http://symfony.com/doc/current/book/templating.html cache all the things (in dev too)!
    • config.yml: twig: cache: false user session in cache!
    • uhm, wait a minute...
    • user session in cache!
    • capifony? idephix? :-P user session in cache!
    • config.yml: framework: session: save_path: "%kernel.root_dir%/sessions/" user session in cache!
    • sf2 in da cloud
    • sf2 in da cloud
    • http:/ /www.ideato.it/planet-ideato/symfony2-su-google-app-engine/ symfony2 needs a writable filesystem symfony2 uses some restricted functions you can warmup cache, but paths are absolute the problem is not only limited to symfony (eg: assetic) sf2 in da cloud
    • sf2 in da cloud
    • /** * @ORMEntity(repositoryClass="IdeatoOfferBundleRepositoryCityRepository") * @ORMTable(name="city") */ class City { /** * @ORMId * @ORMColumn(type="integer") * @ORMGeneratedValue(strategy="AUTO") */ private $id; /** * @ORMColumn(type="string", length=255) * @AssertNotBlank() */ private $name; annotations
    • use DoctrineORMMapping as ORM; use SymfonyComponentValidatorConstraints as Assert; /** * @ORMEntity(repositoryClass="IdeatoOfferBundleRepositoryCityRepository") * @ORMTable(name="city") */ class City { /** * @ORMId * @ORMColumn(type="integer") * @ORMGeneratedValue(strategy="AUTO") */ private $id; /** * @ORMColumn(type="string", length=255) * @AssertNotBlank() */ private $name; annotations
    • @ParamConverter do you need everything?
    • /** * @ParamConverter("post", class="SensioBlogBundle:Post") */ public function showAction(Post $post) { ... } do you need everything?
    • /** * @ParamConverter("post", class="SensioBlogBundle:Post") */ public function showAction(Post $post) { ... } public function showAction(Post $post) { ... } do you need everything?
    • /** * @ParamConverter("post", class="SensioBlogBundle:Post") */ public function showAction(Post $post) { ... } public function showAction(Post $post) { ... } public function showAction(Post $post, Comment $comment) { ... } do you need everything?
    • /** * @ParamConverter("post", class="SensioBlogBundle:Post") */ public function showAction(Post $post) { ... } public function showAction(Post $post) { ... } public function showAction(Post $post, Comment $comment) { ... } kill the magic?
    • public function showAction($post_id) { $post = $this->getRepository(‘Posts’) ->findOneById($post_id); } explicit vs implicit
    • use DoctrineDBALTypesType; use DoctrineDBALPlatformsAbstractPlatform;   /** * NewObject datatype */ class NewObjectType extends Type { public function convertToPHPValue($value, AbstractPlatform $platform) { $listeners = $platform -> getEventManager() -> getListeners('getContainer');   $listener = array_shift($listeners); $container = $listener -> getContainer();   return $container -> get('service'); } } if u can it doesn’t mean you have to
    • class A { protected $first_service; protected $second_service; public function __construct(ContainerInterface $container) { $this->first_service = $container->get(‘firstService’); $this->second_service = $container->get(‘secondService’); } } passing around the DIC is bad
    • class A { protected $first_service; protected $second_service; public function __construct(FirstService $first, SecondService $second) { $this->first_service = $first; $this->second_service = $second; } } in services.yml: services: my.service: arguments: - "@first_service" - "@second_service" class: MyClassA passing around the DIC is bad
    • everything is a bundle
    • mopa_bootstrap: version: ~ form: templating: MopaBootstrapBundle:Form:fields.html.twig horizontal_label_class: col-lg-3 horizontal_input_wrapper_class: col-lg-9 row_wrapper_class: form-group render_fieldset: true render_collection_item: true show_legend: true show_child_legend: false checkbox_label: both render_optional_text: true render_required_asterisk: false error_type: ~ tooltip: icon: icon-info-sign placement: top tabs: class: nav nav-tabs popover: icon: icon-info-sign placement: top collection: widget_remove_btn: attr: class: btn icon: ~ icon_color: ~ widget_add_btn: attr: class: btn icon: ~ icon_color: ~ navbar: template: MopaBootstrapBundle:Navbar:navbar.html.twig initializr: meta: title: MopaBootstrapBundle description: MopaBootstrapBundle keywords: MopaBootstrapBundle, Twitter Bootstrap, HTML5 Boilerplate author_name: My name author_url: # feed_atom: ~ feed_rss: ~ sitemap: ~ nofollow: false noindex: false dns_prefetch: # Default: - //ajax.googleapis.com google: wt: ~ analytics: ~ diagnostic_mode: false configuration (Mopa)...
    • fos_user: db_driver: ~ # Required user_class: ~ # Required firewall_name: ~ # Required model_manager_name: ~ use_listener: true use_username_form_type: true from_email: address: webmaster@example.com sender_name: webmaster profile: form: type: fos_user_profile name: fos_user_profile_form validation_groups: # Defaults: - Profile - Default change_password: form: type: name: validation_groups: # Defaults: - ChangePassword - Default registration: confirmation: enabled: template: from_email: address: sender_name: form: type: name: validation_groups: fos_user_change_password fos_user_change_password_form false FOSUserBundle:Registration:email.txt.twig ~ # Required ~ # Required resetting: token_ttl: 86400 email: template: FOSUserBundle:Resetting:email.txt.twig from_email: address: ~ # Required sender_name: ~ # Required form: type: fos_user_resetting name: fos_user_resetting_form validation_groups: # Defaults: - ResetPassword - Default service: mailer: fos_user.mailer.default email_canonicalizer: fos_user.util.canonicalizer.default token_generator: fos_user.util.token_generator.default username_canonicalizer: fos_user.util.canonicalizer.default user_manager: fos_user.user_manager.default template: engine: twig group: group_class: ~ # Required group_manager: fos_user.group_manager.default form: type: fos_user_group name: fos_user_group_form validation_groups: # Defaults: - Registration - Default fos_user_registration fos_user_registration_form # Defaults: - Registration - Default configuration (FosUserBundle)...
    • configuration is just another way of programming configuration...
    • is there a way to create decoupled, maintainable code? configuration...
    • libraries configuration...
    • src !"" Acme #"" CoreDomain $ !"" User $ #"" User.php $ #"" UserId.php $ !"" UserRepository.php !"" CoreDomainBundle #"" Repository $   !"" InMemoryUserRepository.php !"" AcmeCoreDomainBundle.php http:/ /williamdurand.fr/2013/08/07 /ddd-with-symfony2-folder-structure-and-code-first/ http:/ /whitewashing.de ddd, code first, ...
    • wrap up Wrap up
    • after all Symfony2 is just a framework Wrap up
    • framework != architecture Wrap up
    • do you need that feature? Wrap up
    • think in advance Wrap up
    • keep things decoupled Wrap up
    • Thank you! @_orso_ that’s all folks! mo@ideato.it
    • Pics Credits wtf per minute: http://www.codinghorror.com/blog/2009/02/whos-your-coding-buddy.html pills: http://www.daygame.com/2013/blog/swallowing-the-red-pill/ umarell: http://www.informarexresistere.fr/ clouds: http://www.flickr.com/photos/uncle_jerry/49341110/ gae: http://venturebeat.files.wordpress.com/2013/05/google-app-engine-php-zend.jpg that’s all folks!