# Make file to install symfony, sonata-admin-bundle and fos-user-bundle # Usage: # make all app= # make symfony app= # make fos-user app= # make sonata-admin app= # composer command composer=composer5.6 # console command console=php5.6 bin/console include $(app).make all: entities | symfony fos-user sonata-admin symfony: $(app) sonata-admin: $(app)/vendor/sonata-project/admin-bundle fos-user: $(app)/vendor/friendsofsymfony/user-bundle entities: $(app)/var/schema-update.time # clear cache clear: FORCE cd $(app) && $(console) cache:clear ## Symfony framework # Target for symfony framework $(app): # Create project with symfony framework $(composer) create-project symfony/framework-standard-edition $(app) # Set access for both you and the webserver to all access for logs, cache and sessions folders in var folder setfacl -R -m u:www-data:rwx -m u:$(USER):rwx $(app)/var/logs $(app)/var/cache $(app)/var/sessions # Set default access for same folders, so files created in the future will get the correct access setfacl -dR -m u:www-data:rwx -m u:$(USER):rwx $(app)/var/logs $(app)/var/cache $(app)/var/sessions # Change app_dev.php to allow white listed IP-addresses # Make needs you to escape $ sign so use $$ instead of $ sed -i 's/!(in_array(@\$$_SERVER\['\''REMOTE_ADDR'\''\], \['\''127\.0\.0\.1'\'', '\''fe80::1'\'', '\''::1'\''\])/!($$whiteIP/' $(app)/web/app_dev.php # Change app_dev.php to check if IP-address is white listed or in white listed range. # Make needs you to escape $ sign so use $$ instead of $ sed -i '/if (isset(\$$_SERVER\['\''HTTP_CLIENT_IP'\''\])/i\ $$allowed = ["10."];\ array_walk($$allowed,function($$allow)use(&$$whiteIP){if(strpos($$_SERVER["REMOTE_ADDR"],$$allow)===0)$$whiteIP=true;});\ ' $(app)/web/app_dev.php # Use postgresql instead of mysql sed -i 's/pdo_mysql/pdo_pgsql/' $(app)/app/config/config.yml # Activate translator sed -i 's/#translator/translator/' $(app)/app/config/config.yml ## Sonata Admin Bundle # append to app/config/config.yml define sonata_admin_config_yml sonata_block: default_contexts: [cms] blocks: # Enable the SonataAdminBundle block sonata.admin.block.admin_list: contexts: [admin] endef export sonata_admin_config_yml # append to app/config/routing.yml define sonata_admin_routing_yml admin: resource: "@SonataAdminBundle/Resources/config/routing/sonata_admin.xml" prefix: /admin _sonata_admin: resource: . type: sonata_admin prefix: /admin endef export sonata_admin_routing_yml # Target for sonata admin: requires symfony $(app)/vendor/sonata-project/admin-bundle: | $(app) # Require dependencies cd $(app) && $(composer) require sonata-project/admin-bundle --no-update cd $(app) && $(composer) require sonata-project/doctrine-orm-admin-bundle --no-update cd $(app) && $(composer) update # Inject dependencies in AppKernel sed -i '/new AppBundle\\AppBundle()/i\ new Sonata\\CoreBundle\\SonataCoreBundle(),\ new Sonata\\BlockBundle\\SonataBlockBundle(),\ new Knp\\Bundle\\MenuBundle\\KnpMenuBundle(),\ new Sonata\\DoctrineORMAdminBundle\\SonataDoctrineORMAdminBundle(),\ new Sonata\\AdminBundle\\SonataAdminBundle(),' $(app)/app/AppKernel.php # Enable sonata block in config.yml # Make needs you to escape $ sign so use $$ instead of $ echo "$$sonata_admin_config_yml" >> $(app)/app/config/config.yml # Add routes in routing.yml # Make needs you to escape $ sign so use $$ instead of $ echo "$$sonata_admin_routing_yml" >> $(app)/app/config/routing.yml # Install assests cd $(app) && $(console) assets:install web # Clear cache cd $(app) && $(console) cache:clear ## FOS User Bundle # Append to app/config/config.yml define fos_user_config_yml fos_user: db_driver: orm firewall_name: main user_class: AppBundle\Entity\User endef export fos_user_config_yml # Append to app/config/routing.yml define fos_user_routing_yml fos_user: resource: "@FOSUserBundle/Resources/config/routing/all.xml" endef export fos_user_routing_yml # app/config/security.yml # Make needs you to escape $ sign so use $$ instead of $ define fos_user_security_yml security: encoders: FOS\UserBundle\Model\UserInterface: bcrypt role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: ROLE_ADMIN ROLE_SONATA_ADMIN providers: fos_userbundle: id: fos_user.user_provider.username firewalls: main: pattern: ^/ form_login: provider: fos_userbundle csrf_token_generator: security.csrf.token_manager logout: true anonymous: true access_control: - { path: ^/login$$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin/, role: ROLE_ADMIN } endef export fos_user_security_yml # src/AppBundle/Entity/User.php # Make needs you to escape $ sign so use $$ instead of $ define fos_user_user_php newPass = $$newPass; } public function getNewPass() { return $$this->newPass; } } endef export fos_user_user_php # src/AppBundle/Entity/User.php # Make needs you to escape $ sign so use $$ instead of $ define fos_user_admin_user_php updateUser($$object); } public function preUpdate($$object) { parent::preUpdate($$object); $$this->updateUser($$object); } public function updateUser(\AppBundle\Entity\User $$u) { if ($$u->getNewPass()) { $$u->setPlainPassword($$u->getNewPass()); } $$um = $$this->getConfigurationPool()->getContainer()->get('fos_user.user_manager'); $$um->updateUser($$u, false); } protected function configureFormFields(FormMapper $$formMapper) { $$formMapper ->add('username', 'text') ->add('email', 'text') ->add('newPass', 'text', array( 'label' => 'New password (empty filed means no changes)', 'required' => FALSE )) ; } protected function configureDatagridFilters(DatagridMapper $$datagridMapper) { $$datagridMapper->add('username'); $$datagridMapper->add('email'); } protected function configureListFields(ListMapper $$listMapper) { $$listMapper->addIdentifier('username'); $$listMapper->addIdentifier('email'); } } endef export fos_user_admin_user_php # Target for fos user bundle: requires symfony $(app)/vendor/friendsofsymfony/user-bundle: | $(app) # Require dependencies cd $(app) && $(composer) require doctrine/orm --no-update cd $(app) && $(composer) require friendsofsymfony/user-bundle "dev-master" --no-update cd $(app) && $(composer) update # Inject dependencies in AppKernel sed -i '/new AppBundle\\AppBundle()/i\ new FOS\\UserBundle\\FOSUserBundle(),' $(app)/app/AppKernel.php # Configure fos user-bundle in config.yml # Make needs you to escape $ sign so use $$ instead of $ echo "$$fos_user_config_yml" >> $(app)/app/config/config.yml # Add routes in routing.yml # Make needs you to escape $ sign so use $$ instead of $ echo "$$fos_user_routing_yml" >> $(app)/app/config/routing.yml # Override secrity.yml # Make needs you to escape $ sign so use $$ instead of $ echo "$$fos_user_security_yml" > $(app)/app/config/security.yml # Create Entity folder mkdir -p $(app)/src/AppBundle/Entity # Create user entity # Make needs you to escape $ sign so use $$ instead of $ echo "$$fos_user_user_php" > $(app)/src/AppBundle/Entity/User.php # Create Admin folder mkdir -p $(app)/src/AppBundle/Admin # Create admin user # Make needs you to escape $ sign so use $$ instead of $ echo "$$fos_user_admin_user_php" > $(app)/src/AppBundle/Admin/UserAdmin.php # Update schema cd $(app) && $(console) doctrine:schema:update --force # Create first user # Assuming you have your git configuration done # Don't forget to change your password cd $(app) && $(console) fos:user:create $(USER) `git config --global user.email` admin --super-admin # Clear cache cd $(app) && $(console) cache:clear ## Generate entities and update schema # Basic entity define entity_php $@ .PRECIOUS: $(app)/src/AppBundle/Repository/%Repository.php $(app)/src/AppBundle/Repository/%Repository.php: echo "$$repository_php" > $@ .PHONY: FORCE FORCE: