Introducing Symfony Composer Bundles Symfony Framework Symfon y
Introducing Symfony ●Composer, Bundles, ●Symfony Framework Symfon y Georgi Gyurov georgi@stenik. bg Software University http: //softuni. bg
Table of Contents 1. Introducing Symfony 2. Install Symfony • Composer • Symfony installer 3. Symfony Overview
Have a question? #sli. do #softuni-symfony
About Stenik Founded in 2004 Main areas of expertise E-Commerce solutions Corporate Web Sites and Applications Custom Design Small company with young team Compelling projects and great customers http: //stenik. bg 4
Course: Out of Scope We will not learn things like: PHP Programming language OOP Databases HTML/CSS/Javascript LAMP/XAMPP setup and troubleshouting Those are required skills you should have prior attending this course 5
Course Goals Become familiar with Symfony Learn the MVC approach and configurations in Symfony Learn how to create bundles Have knowledge of advanced mechanisms and possibilities of the platform 6
Assesment 80 points from course projects 7
Introducing Symfony Advantages of The Framework
Sample Magento Stores kinoarena. com tokudabank. bg kontrax. bg service. skoda-auto. bg http: //symfony. com/projects 9
Introducing Symfony MVC Architecture Great Set of Components Active community Good documentation
Install & Configure Symfony Composer
Run Symfony Creating vhost https: //symfony. com/doc/current/setup/web_server_configuration. html
Composer Introduction Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. To install Composer go to https: //getcomposer. org/download/ and follow instructions.
Composer Install Symfony with Composer: php composer. phar create-project symfony/frameworkstandard-edition my_project_name “ 3. 2. *" georgi@georgi-desktop: ~/projects$ composer create-project symfony/framework-standard-edition symfony-project "3. 2. *" Installing symfony/framework-standard-edition (v 3. 2. 8) - Installing symfony/framework-standard-edition (v 3. 2. 8) Downloading: 100% Created project in symfony-project Loading composer repositories with package information
Run Symfony To check configuration symfony. localhost/config. php
Run Symfony Setting up permissions https: //symfony. com/doc/current/setup/file_permissions. html Linux HTTPDUSER=`ps axo user, comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d f 1` sudo setfacl -R -m u: "$HTTPDUSER": rw. X -m u: `whoami`: rw. X var sudo setfacl -d. R -m u: "$HTTPDUSER": rw. X -m u: `whoami`: rw. X var mac. OS rm -rf var/cache/* rm -rf var/logs/* HTTPDUSER=`ps axo user, comm | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data|[n]ginx' | grep -v root | head -1 | cut -d sudo chmod -R +a "$HTTPDUSER allow delete, write, append, file_inherit, directory_inherit" var sudo chmod -R +a "`whoami` allow delete, write, append, file_inherit, directory_inherit" var - Windows umask(0002); // This will let the permissions be 0775 // or umask(0000); // This will let the permissions be 0777 -f 1`
Welcome to Symfony
Practise: Install Symfony Live Exercise In Class (Lab)
Symfony Overview First Steps With The Framework
The Bundle System What is a Bundle? set of files within a directory designed to imlpement a single feature each bundle has its own namespace <Vendor Name>(<Namespace>)*<Class Name>
The Bundle System The bundle class name must follow five simple rules: 1. Use only alphanumeric characters and underscores; 2. Use a Camel. Case name; 3. Use a descriptive and short name (no more than two words); 4. Prefix the name with the concatenation of the vendor (and optionally the category namespaces); 5. Suffix the name with Bundle.
The Bundle System Example of valid bundle names: Namespace StenikBlog. BundleStenik. Blog. Bundle StenikServices. BundleStenik. Services. Bun dle Bundle Class Name Stenik. Blog. Bundle Stenik. Services. Bundle
Directory Structure Directory Description var/ logs and cache files vendor/ dependecies (bundles) src/ the project’s code (own bundles) Web/ Web root directory, application index app/ Application Kernel and configuration files bin/ Symfony console tests/ Automatic tests
Symfony Project Overview app/App. Kernel. php Is the most important file of our project All bundles are registered/activated in App. Kernel class App. Kernel extends Kernel { public function register. Bundles() { $bundles = [ new SymfonyBundleFramework. Bundle(), ]; //TO DO }
Symfony Project Overview app/App. Kernel. php App. Kernel also provides configuration for different environments class App. Kernel extends Kernel { public function register. Bundles() { //TO DO if (in_array($this->get. Environment(), ['dev', 'test'])) { $bundles[] = new SymfonyBundleDebug. Bundle(); } } } Each environment should have its own config file suffixed with the name of the provided environment, e. g. : config_dev. yml Each environment creates its own cache and log files in var/cache and var/log
YAML is: human-readable data serialization language like json and xml, but easier to read based on key: value used for Symfony configuration
Symfony Project Overview app/config. yml Application main config file for application settings framework: templating: engines: [‘twig’] imports: - { resource: parameters. yml } - { resource: security. yml } - { resource: services. yml } - { resource: "@App. Bundle/Resources/config/services. yml" }
Symfony Project Overview app/config/parameters. yml Infrastructure-related configuration like database settings and mail service parameters: database_host: localhost database_name: symfony dabatase_user: root database_pass: custom_param: param_value
Symfony Routing app/config/routing. yml Contains mapping between controllers and routes user_profile: path: /user/profile defaults: { _controller: App. Bundle: User: profile } services_bundle: resource: "@Stenik. Services. Bundle/Controller" type: annotation prefix: /{_locale} requirements: _locale: "[a-z]{2}"
Symfony Routing Parameters app/config/routing. yml _controller This parameter is used to determine which controller is executed when the route is matched. _format Used to set the request format (read more). _locale Used to set the locale on the request (read more).
Trying some code git clone git@github. com: stenikgroup/softuni-symfony. git
Summary Symfony is leading PHP framework to create websites and web applications. Built on top of the Symfony Components A bundle is similar to a plugin in other software, but even better. The key difference is that everything is a bundle in Symfony, including both the core framework functionality and the code written for your application. Bundles are first-class citizens in Symfony Large Community Highly scalable 32
? s n o i t s e u Q ? ? ? https: //softuni. bg/courses/
License This course (slides, examples, demos, videos, homework, etc. ) is licensed under the "Creative Commons Attribution. Non. Commercial-Share. Alike 4. 0 International" license 34
Trainings @ Software University (Soft. Uni) Software University – High-Quality Education, Profession and Job for Software Developers softuni. bg Software University Foundation softuni. org Software University @ Facebook facebook. com/Software. University Software University Forums forum. softuni. bg
- Slides: 35