xm / starter_symfony_4
Starter for creating Symfony 4/5 sites at XM Media
Installs: 11
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 5
Forks: 2
Open Issues: 4
Type:project
Requires
- php: 7.4.*
- ext-ctype: *
- ext-iconv: *
- ext-json: *
- ext-pcntl: *
- ext-pdo: *
- egulias/email-validator: ^2.1
- guzzlehttp/guzzle: ^6.3
- knplabs/knp-paginator-bundle: ^5.0
- moneyphp/money: ^3.2
- nesbot/carbon: ^2.4
- odolbeau/phone-number-bundle: ^3.0
- overblog/graphql-bundle: ^0.13
- prooph/event-store-bus-bridge: ^3.3
- prooph/event-store-symfony-bundle: ^0.8
- prooph/pdo-event-store: ^1.10
- ramsey/uuid: ^4.0
- ramsey/uuid-doctrine: ^1.5
- roave/security-advisories: dev-master
- scienta/doctrine-json-functions: ^4.3
- sensio/framework-extra-bundle: ^5.1
- symfony/asset: *
- symfony/console: *
- symfony/dotenv: *
- symfony/expression-language: *
- symfony/flex: ^1.1
- symfony/form: *
- symfony/framework-bundle: *
- symfony/http-client: *
- symfony/messenger: *
- symfony/monolog-bundle: ^3.5
- symfony/orm-pack: ^2.0
- symfony/process: *
- symfony/security-bundle: *
- symfony/serializer-pack: ^1.0
- symfony/string: *
- symfony/swiftmailer-bundle: ^3.4
- symfony/templating: *
- symfony/twig-bundle: *
- symfony/validator: *
- symfony/web-link: *
- symfony/webpack-encore-bundle: ^1.0
- symfony/yaml: *
- twig/extra-bundle: ^3.0
- webmozart/assert: ^1.3
- xm/symfony-bundle: ^1.0
Requires (Dev)
- doctrine/doctrine-fixtures-bundle: ^3.0
- ekino/phpstan-banned-code: ^0.3.1
- fakerphp/faker: ^1.8
- friendsofphp/php-cs-fixer: ^2.13
- liip/functional-test-bundle: ^4.1
- mockery/mockery: ^1.2
- overblog/graphiql-bundle: ^0.2.0
- phpstan/phpstan: ^0.12
- phpstan/phpstan-deprecation-rules: ^0.12
- phpstan/phpstan-mockery: ^0.12
- phpstan/phpstan-phpunit: ^0.12
- phpstan/phpstan-symfony: ^0.12
- phpstan/phpstan-webmozart-assert: ^0.12
- symfony/apache-pack: ^1.0
- symfony/debug-pack: ^1.0
- symfony/maker-bundle: ^1.0
- symfony/phpunit-bridge: *
- symfony/profiler-pack: ^1.0
- symfony/test-pack: ^1.0
- theofidry/alice-data-fixtures: ^1.1
Conflicts
This package is auto-updated.
Last update: 2021-02-19 04:22:26 UTC
README
Used to create new projects using Symfony 4 at XM Media.
Setting Up a New Site
- Create a new project:
composer create-project xm/starter_symfony_4 project-name --stability=dev --no-install --remove-vcs
- Setup dev server:
- If using InterWorx, upload
setup_dev.sh
and run:sh ./setup_dev.sh
- Upload the files (exclude files that are OS dependent like
node_modules
&.env.local
or that are only for editing like.idea
and.git
and a lot of what's in.gitignore
). - Install Composer (if not already installed)
- Install PHP packages/vendors:
php composer.phar install
- Add
.env.local
– copy.env
and update. - Run
. ./node_setup.sh
(this will setup node & install the JS packages – requires yarn to be installed). - Run
yarn dev
oryarn build
(for production) to compile JS & CSS files. - Give executable perms to bin dir:
chmod u+x bin/*
- Create event streams & projections tables from
db_create.sql
. Set database collation toutf8mb4_bin
. - Create one or more event streams with the command
bin/console event-store:event-stream:create user && bin/console event-store:event-stream:create auth && bin/console event-store:event-stream:create enquiry
(remove enquiry if not using the enquiry form). - Run all projections once:
bin/console event-store:projection:run user_projection -o && bin/console event-store:projection:run user_token_projection -o && bin/console event-store:projection:run enquiry_projection -o
- Create a user
bin/console app:user:add
(select roleROLE_SUPER_ADMIN
). - Setup mail spool: add cron task similar to:
*/15 * * * * cd /home/user/example.com/current && bin/console swiftmailer:spool:send --message-limit=10 --time-limit=45 >> var/log/mailer.log 2>&1
(this only sends error emails, runs every 15 minutes)- As one command:
crontab -l > mycron; echo "*/15 * * * * cd ${BASE}/current && bin/console swiftmailer:spool:send --message-limit=10 --time-limit=45 >> var/log/mailer.log 2>&1" >> mycron; crontab mycron; rm mycron
- As one command:
- Add logrotate cron (only needed on production):
30 4 * * 1 cd /home/user/example.com/current && logrotate app/config/packages/logrotate.conf --state var/logrotate-state
(runs Mondays at 04:30 UTC)
- If using InterWorx, upload
- Remove or update the
LICENSE
file. - Install Composer locally (if not installed globally).
- Update
composer.json
:name
,license
(likelyprivate
) anddescription
- Update
package.json
:name
,version
,git.url
,license
,private
,script.dev-server
- Composer install & update (locally):
composer install && composer update
(or without memory limit:php -d memory_limit=-1 /usr/local/bin/composer update
) - Run
yarn && yarn upgrade
locally. - Find and make changes near
@todo-symfony
comments throughout the site. - Delete starter files:
README.md
(or update) andTEMPLATES.md
. - Optional: Run
composer test
– will install PHPUnit & run PHP tests - Create new favicons: realfavicongenerator.net
- Copy (use "Push to another server") or recreate the templates in Postmark. The templates are referenced by the aliases.
- Optional: Run
bin/console app:graphql:dump-schema <username>
to update the GraphQL schema file whereusername
is the email of an admin user.
Dev site can be accessed at https://[domain]/
System Requirements
- PHP 7.3+
- MySQL 5.7+
- Node 10
- Yarn
Commands
- Production JS/CSS build:
yarn build
- Dev JS/CSS build:
yarn dev
- Dev JS/CSS watch:
yarn watch
(files will not be versioned) - Dev JS/CSS HMR server:
yarn dev-server
(see below) - JS Tests (Jest):
yarn test:unit
- E2E Tests (Cypress):
yarn test:e2e
- Linting:
- JS (ESLint):
yarn lint:js
oryarn lint:js:fix
- CSS:
yarn lint:css
oryarn lint:css:fix
- JS (ESLint):
- PHP Tests (PhpUnit):
composer test
- no memory limit
php -d memory_limit=-1 bin/simple-phpunit
- with coverage (HTML)
composer test:coverage
- PHP CS: (must be installed first)
- Dry run:
composer cs
- Fix:
composer cs:fix
- Dry run:
- PHP Static Analysis (PHPStan):
composer static
- Projections:
- All commands:
bin/console event-store:projection
- Run once:
bin/console event-store:projection:run user_projection -o
- All commands:
- Makers (PHP):
- Make aggregate root/model:
bin/console make:model
- Make projection:
bin/console make:projection
- Make aggregate root/model:
Apache Config
The following is needed in the Apache VirtualHost for the Webpack Dev Server/HMR to work:
ProxyPassMatch ^(\/dev-server\/.+$)|(sockjs-node) http://localhost:<port>
ProxyPassReverse / http://localhost:<port>
You'll probably want to customize the port number in the Apache ProxyPass config
and in package.json
(script.dev-server
) to be unique to each project if
running multiple sites on one server.
Incorporated Libraries & Tools
- Frontend – full list of dependencies can be found in package.json
- Vue – frontend framework
- Vue Router – routing package for frontend
- Vuex – helps to manage state
- Vue Devtools – makes debugging in the browser easier
- Vue Templates – the syntax for .vue files
- Vue Test Utils – to help testing Vue components
- Vue CLI – to manage & run the frontend compilation & testing
- GraphQL – the communication (query) language for the API
- Apollo Client through Vue Apollo – frontend GraphQL
- SASS – CSS preprocessor (uses node-sass)
- Webpack – compiles JS & CSS
- Babel – transforms JS to work in all browsers
- Webpack Encore – connects the frontend and backend and makes Webpack configuration simpler
- PostCSS – transforms CSS
- Autoprefixer – for adding browser prefixes
- Purge CSS – removes unused CSS during the deployment process (not run in dev)
- SVGO – optimizes SVG files
- Bundle Analyzer – displays sizes/stats on the JS bundle size
- Tailwind – utility first styling framework
- Jest – JS unit testing
- Cypress – end-to-end (e2e) testing
- Lodash – helper functions for JS
- date-fns – helper functions for Dates in JS
- PortalVue – helps to manage things like modals
- Vue-JS-Modal – for modals
- Workbox – helps with configuration of service worker/PWA
- Faker.js – for generating fake data in tests
- ESLint – checks JS for conventions & errors
- Stylelint – checks CSS for conventions & errors
- Vue – frontend framework
- Backend – full list of dependencies can be found in composer.json
- Symfony – backend framework
- GraphQLBundle – provides GraphQL in PHP using graphql-php
- GraphQiL is available at
/graphiql
(on dev only)
- GraphQiL is available at
- Twig – server side templating language (limited use)
- Prooph PDO Event Store & Bridge/Bundle – for doing Event Sourcing
- Doctrine – for reading from read models
- PhpUnit – for running PHP tests
- PHP CS – PHP coding standards analyzer & fixer
- PHPStan – static analysis of PHP
- Postmark – for sending email, contains email templates (currently setup under XM Media's account)
- Cloudflare – DNS & CDN
- GitLab – deployment
- Dev Tools