├── .gitignore ├── README.md ├── app ├── .htaccess ├── AppCache.php ├── AppKernel.php ├── Resources │ └── views │ │ ├── base.html.twig │ │ └── default │ │ └── index.html.twig └── config │ ├── config.yml │ ├── config_dev.yml │ ├── config_prod.yml │ ├── config_test.yml │ ├── keys │ ├── private_key.pem │ ├── private_key.txt │ └── public_key.txt │ ├── parameters.yml.dist │ ├── routing.yml │ ├── routing_dev.yml │ ├── security.yml │ └── services.yml ├── bin ├── console └── symfony_requirements ├── composer.json ├── package.json ├── phpunit.xml.dist ├── src ├── .htaccess └── AppBundle │ ├── AppBundle.php │ ├── Command │ ├── PushNotificationCommand.php │ └── PushVapidKeysCommand.php │ ├── Controller │ └── DefaultController.php │ ├── Entity │ └── Subscriber.php │ └── Repository │ └── SubscriberRepository.php ├── tests └── AppBundle │ └── Controller │ └── DefaultControllerTest.php ├── var ├── SymfonyRequirements.php ├── cache │ └── .gitkeep ├── logs │ └── .gitkeep └── sessions │ └── .gitkeep ├── web ├── .htaccess ├── app.php ├── app_dev.php ├── apple-touch-icon.png ├── assets │ ├── img │ │ ├── 256.png │ │ └── 512.png │ ├── js │ │ ├── App.vue │ │ ├── components │ │ │ ├── Demo.vue │ │ │ ├── Hello.vue │ │ │ ├── Home.vue │ │ │ └── Notfound.vue │ │ ├── router │ │ │ └── index.js │ │ ├── sw.js │ │ ├── vendor.js │ │ └── vue.js │ └── scss │ │ └── style.scss ├── build │ ├── manifest.json │ ├── style.css │ ├── sw.js │ ├── vendor.js │ └── vue.js ├── config.php ├── favicon.ico ├── img │ ├── 256.png │ └── 512.png ├── robots.txt └── sw.js └── webpack.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | /.web-server-pid 2 | /app/config/parameters.yml 3 | /build/ 4 | /phpunit.xml 5 | /var/* 6 | !/var/cache 7 | /var/cache/* 8 | !var/cache/.gitkeep 9 | !/var/logs 10 | /var/logs/* 11 | !var/logs/.gitkeep 12 | !/var/sessions 13 | /var/sessions/* 14 | !var/sessions/.gitkeep 15 | !var/SymfonyRequirements.php 16 | /vendor/ 17 | /web/bundles/ 18 | /node_modules/* 19 | ./app/config/keys/* -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | sf-vue 2 | ====== 3 | 4 | A Symfony project created on July 24, 2017, 2:10 pm. 5 | -------------------------------------------------------------------------------- /app/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Require all denied 3 | 4 | 5 | Order deny,allow 6 | Deny from all 7 | 8 | -------------------------------------------------------------------------------- /app/AppCache.php: -------------------------------------------------------------------------------- 1 | getEnvironment(), ['dev', 'test'], true)) { 23 | $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); 24 | $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); 25 | $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); 26 | 27 | if ('dev' === $this->getEnvironment()) { 28 | $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); 29 | $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle(); 30 | } 31 | } 32 | 33 | return $bundles; 34 | } 35 | 36 | public function getRootDir() 37 | { 38 | return __DIR__; 39 | } 40 | 41 | public function getCacheDir() 42 | { 43 | return dirname(__DIR__).'/var/cache/'.$this->getEnvironment(); 44 | } 45 | 46 | public function getLogDir() 47 | { 48 | return dirname(__DIR__).'/var/logs'; 49 | } 50 | 51 | public function registerContainerConfiguration(LoaderInterface $loader) 52 | { 53 | $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml'); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/Resources/views/base.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {% block title %}Welcome!{% endblock %} 8 | {% block stylesheets %}{% endblock %} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | {% block body %}{% endblock %} 17 | {% block javascripts %}{% endblock %} 18 | 19 | 20 | -------------------------------------------------------------------------------- /app/Resources/views/default/index.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'base.html.twig' %} 2 | 3 | {% block body %} 4 |
5 | 6 |
7 | {% endblock %} 8 | 9 | {% block stylesheets %} 10 | 11 | 12 | 13 | 14 | 15 | 16 | {% endblock %} 17 | 18 | 19 | {% block javascripts %} 20 | 21 | 22 | 23 | 26 | 27 | {% endblock javascripts%} -------------------------------------------------------------------------------- /app/config/config.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: parameters.yml } 3 | - { resource: security.yml } 4 | - { resource: services.yml } 5 | 6 | # Put parameters here that don't need to change on each machine where the app is deployed 7 | # https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration 8 | parameters: 9 | locale: en 10 | 11 | framework: 12 | #esi: ~ 13 | #translator: { fallbacks: ['%locale%'] } 14 | secret: '%secret%' 15 | router: 16 | resource: '%kernel.project_dir%/app/config/routing.yml' 17 | strict_requirements: ~ 18 | form: ~ 19 | csrf_protection: ~ 20 | validation: { enable_annotations: true } 21 | #serializer: { enable_annotations: true } 22 | templating: 23 | engines: ['twig'] 24 | default_locale: '%locale%' 25 | trusted_hosts: ~ 26 | session: 27 | # https://symfony.com/doc/current/reference/configuration/framework.html#handler-id 28 | handler_id: session.handler.native_file 29 | save_path: '%kernel.project_dir%/var/sessions/%kernel.environment%' 30 | fragments: ~ 31 | http_method_override: true 32 | assets: ~ 33 | php_errors: 34 | log: true 35 | 36 | # Twig Configuration 37 | twig: 38 | debug: '%kernel.debug%' 39 | strict_variables: '%kernel.debug%' 40 | 41 | # Doctrine Configuration 42 | doctrine: 43 | dbal: 44 | driver: pdo_mysql 45 | host: '%database_host%' 46 | port: '%database_port%' 47 | dbname: '%database_name%' 48 | user: '%database_user%' 49 | password: '%database_password%' 50 | charset: UTF8 51 | # if using pdo_sqlite as your database driver: 52 | # 1. add the path in parameters.yml 53 | # e.g. database_path: '%kernel.project_dir%/var/data/data.sqlite' 54 | # 2. Uncomment database_path in parameters.yml.dist 55 | # 3. Uncomment next line: 56 | #path: '%database_path%' 57 | 58 | orm: 59 | auto_generate_proxy_classes: '%kernel.debug%' 60 | naming_strategy: doctrine.orm.naming_strategy.underscore 61 | auto_mapping: true 62 | 63 | # Swiftmailer Configuration 64 | swiftmailer: 65 | transport: '%mailer_transport%' 66 | host: '%mailer_host%' 67 | username: '%mailer_user%' 68 | password: '%mailer_password%' 69 | spool: { type: memory } 70 | 71 | minishlink_web_push: 72 | api_keys: # you should put api keys in your "app/config/parameters.yml" file 73 | GCM: '%webpush.gcm%' 74 | VAPID: 75 | subject: '%webpush.subject%' # can be an URL or a mailto: 76 | publicKey: '%webpush.publickey%' # uncompressed public key P-256 encoded in Base64-URL 77 | privateKey: '%webpush.privatekey%' # the secret multiplier of the private key encoded in Base64-URL 78 | pemFile: '%webpush.pem%' # if you have a PEM file and want to hardcode its content 79 | ttl: 2419200 # Time to Live of notifications in seconds 80 | urgency: ~ # can be very-low / low / normal / high 81 | topic: ~ # default identifier for your notifications 82 | timeout: 30 # Timeout of each request in seconds 83 | automatic_padding: true # pad messages automatically for better security (against more bandwith usage) -------------------------------------------------------------------------------- /app/config/config_dev.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: config.yml } 3 | 4 | framework: 5 | router: 6 | resource: '%kernel.project_dir%/app/config/routing_dev.yml' 7 | strict_requirements: true 8 | profiler: { only_exceptions: false } 9 | 10 | web_profiler: 11 | toolbar: true 12 | intercept_redirects: false 13 | 14 | monolog: 15 | handlers: 16 | main: 17 | type: stream 18 | path: '%kernel.logs_dir%/%kernel.environment%.log' 19 | level: debug 20 | channels: ['!event'] 21 | console: 22 | type: console 23 | process_psr_3_messages: false 24 | channels: ['!event', '!doctrine', '!console'] 25 | # To follow logs in real time, execute the following command: 26 | # `bin/console server:log -vv` 27 | server_log: 28 | type: server_log 29 | process_psr_3_messages: false 30 | host: 127.0.0.1:9911 31 | # uncomment to get logging in your browser 32 | # you may have to allow bigger header sizes in your Web server configuration 33 | #firephp: 34 | # type: firephp 35 | # level: info 36 | #chromephp: 37 | # type: chromephp 38 | # level: info 39 | 40 | #swiftmailer: 41 | # delivery_addresses: ['me@example.com'] 42 | -------------------------------------------------------------------------------- /app/config/config_prod.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: config.yml } 3 | 4 | #doctrine: 5 | # orm: 6 | # metadata_cache_driver: apc 7 | # result_cache_driver: apc 8 | # query_cache_driver: apc 9 | 10 | monolog: 11 | handlers: 12 | main: 13 | type: fingers_crossed 14 | action_level: error 15 | handler: nested 16 | nested: 17 | type: stream 18 | path: '%kernel.logs_dir%/%kernel.environment%.log' 19 | level: debug 20 | console: 21 | type: console 22 | process_psr_3_messages: false 23 | -------------------------------------------------------------------------------- /app/config/config_test.yml: -------------------------------------------------------------------------------- 1 | imports: 2 | - { resource: config_dev.yml } 3 | 4 | framework: 5 | test: ~ 6 | session: 7 | storage_id: session.storage.mock_file 8 | profiler: 9 | collect: false 10 | 11 | web_profiler: 12 | toolbar: false 13 | intercept_redirects: false 14 | 15 | swiftmailer: 16 | disable_delivery: true 17 | -------------------------------------------------------------------------------- /app/config/keys/private_key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN EC PARAMETERS----- 2 | BggqhkjOPQMBBw== 3 | -----END EC PARAMETERS----- 4 | -----BEGIN EC PRIVATE KEY----- 5 | MHcCAQEEIJbBcL2HQ2fy7aWb01mLiocAiw78TbOSJwH5XW2wPCBhoAoGCCqGSM49 6 | AwEHoUQDQgAEXZsaYFm6FUgGh9fnxdjgI4cBWshacYyo5c5oAkwfKUGAuxeO9Gdh 7 | 3gj6+2ageeNCTw98MP8tqUxdKe33GAnNCA== 8 | -----END EC PRIVATE KEY----- 9 | -------------------------------------------------------------------------------- /app/config/keys/private_key.txt: -------------------------------------------------------------------------------- 1 | lsFwvYdDZ_LtpZvTWYuKhwCLDvxNs5InAfldbbA8IGE -------------------------------------------------------------------------------- /app/config/keys/public_key.txt: -------------------------------------------------------------------------------- 1 | BF2bGmBZuhVIBofX58XY4COHAVrIWnGMqOXOaAJMHylBgLsXjvRnYd4I-vtmoHnjQk8PfDD_LalMXSnt9xgJzQg -------------------------------------------------------------------------------- /app/config/parameters.yml.dist: -------------------------------------------------------------------------------- 1 | # This file is a "template" of what your parameters.yml file should look like 2 | # Set parameters here that may be different on each deployment target of the app, e.g. development, staging, production. 3 | # https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration 4 | parameters: 5 | database_host: 127.0.0.1 6 | database_port: ~ 7 | database_name: notifications 8 | database_user: root 9 | database_password: root 10 | # You should uncomment this if you want to use pdo_sqlite 11 | #database_path: '%kernel.project_dir%/var/data/data.sqlite' 12 | 13 | mailer_transport: smtp 14 | mailer_host: 127.0.0.1 15 | mailer_user: ~ 16 | mailer_password: ~ 17 | 18 | # A secret key that's used to generate certain security-related tokens 19 | secret: ThisTokenIsNotSoSecretChangeIt 20 | webpush.subject: http://elastic.live/ 21 | webpush.gcm: 314804067424 22 | webpush.publicKey: BF2bGmBZuhVIBofX58XY4COHAVrIWnGMqOXOaAJMHylBgLsXjvRnYd4I-vtmoHnjQk8PfDD_LalMXSnt9xgJzQg 23 | webpush.privateKey: lsFwvYdDZ_LtpZvTWYuKhwCLDvxNs5InAfldbbA8IGE 24 | webpush.pem: %kernel.root_dir%/config/keys/private_key.pem -------------------------------------------------------------------------------- /app/config/routing.yml: -------------------------------------------------------------------------------- 1 | app: 2 | resource: '@AppBundle/Controller/' 3 | type: annotation 4 | 5 | #spa: 6 | # path: /{path} 7 | # defaults: { _controller: AppBundle:Default:index, path: '' } 8 | # requirements: 9 | # path: .* -------------------------------------------------------------------------------- /app/config/routing_dev.yml: -------------------------------------------------------------------------------- 1 | _wdt: 2 | resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml' 3 | prefix: /_wdt 4 | 5 | _profiler: 6 | resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml' 7 | prefix: /_profiler 8 | 9 | _errors: 10 | resource: '@TwigBundle/Resources/config/routing/errors.xml' 11 | prefix: /_error 12 | 13 | _main: 14 | resource: routing.yml 15 | -------------------------------------------------------------------------------- /app/config/security.yml: -------------------------------------------------------------------------------- 1 | # To get started with security, check out the documentation: 2 | # https://symfony.com/doc/current/security.html 3 | security: 4 | 5 | # https://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded 6 | providers: 7 | in_memory: 8 | memory: ~ 9 | 10 | firewalls: 11 | # disables authentication for assets and the profiler, adapt it according to your needs 12 | dev: 13 | pattern: ^/(_(profiler|wdt)|css|images|js)/ 14 | security: false 15 | 16 | main: 17 | anonymous: ~ 18 | # activate different ways to authenticate 19 | 20 | # https://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate 21 | #http_basic: ~ 22 | 23 | # https://symfony.com/doc/current/security/form_login_setup.html 24 | #form_login: ~ 25 | -------------------------------------------------------------------------------- /app/config/services.yml: -------------------------------------------------------------------------------- 1 | # Learn more about services, parameters and containers at 2 | # https://symfony.com/doc/current/service_container.html 3 | parameters: 4 | #parameter_name: value 5 | 6 | services: 7 | # default configuration for services in *this* file 8 | _defaults: 9 | # automatically injects dependencies in your services 10 | autowire: true 11 | # automatically registers your services as commands, event subscribers, etc. 12 | autoconfigure: true 13 | # this means you cannot fetch services directly from the container via $container->get() 14 | # if you need to do this, you can override this setting on individual services 15 | public: false 16 | 17 | # makes classes in src/AppBundle available to be used as services 18 | # this creates a service per class whose id is the fully-qualified class name 19 | AppBundle\: 20 | resource: '../../src/AppBundle/*' 21 | # you can exclude directories or files 22 | # but if a service is unused, it's removed anyway 23 | exclude: '../../src/AppBundle/{Entity,Repository,Tests}' 24 | 25 | # controllers are imported separately to make sure they're public 26 | # and have a tag that allows actions to type-hint services 27 | AppBundle\Controller\: 28 | resource: '../../src/AppBundle/Controller' 29 | public: true 30 | tags: ['controller.service_arguments'] 31 | 32 | # add more services, or override services that need manual wiring 33 | # AppBundle\Service\ExampleService: 34 | # arguments: 35 | # $someArgument: 'some_value' 36 | # event listener to redirect all 404 requests to our SPA page 37 | #app.spa_listener: 38 | # class: AppBundle\EventListener\SPA 39 | # tags: 40 | # - { name: kernel.event_listener, event: kernel.exception, method: onKernelException } -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev'); 19 | $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; 20 | 21 | if ($debug) { 22 | Debug::enable(); 23 | } 24 | 25 | $kernel = new AppKernel($env, $debug); 26 | $application = new Application($kernel); 27 | $application->run($input); 28 | -------------------------------------------------------------------------------- /bin/symfony_requirements: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | getPhpIniConfigPath(); 9 | 10 | echo_title('Symfony Requirements Checker'); 11 | 12 | echo '> PHP is using the following php.ini file:'.PHP_EOL; 13 | if ($iniPath) { 14 | echo_style('green', ' '.$iniPath); 15 | } else { 16 | echo_style('yellow', ' WARNING: No configuration file (php.ini) used by PHP!'); 17 | } 18 | 19 | echo PHP_EOL.PHP_EOL; 20 | 21 | echo '> Checking Symfony requirements:'.PHP_EOL.' '; 22 | 23 | $messages = array(); 24 | foreach ($symfonyRequirements->getRequirements() as $req) { 25 | if ($helpText = get_error_message($req, $lineSize)) { 26 | echo_style('red', 'E'); 27 | $messages['error'][] = $helpText; 28 | } else { 29 | echo_style('green', '.'); 30 | } 31 | } 32 | 33 | $checkPassed = empty($messages['error']); 34 | 35 | foreach ($symfonyRequirements->getRecommendations() as $req) { 36 | if ($helpText = get_error_message($req, $lineSize)) { 37 | echo_style('yellow', 'W'); 38 | $messages['warning'][] = $helpText; 39 | } else { 40 | echo_style('green', '.'); 41 | } 42 | } 43 | 44 | if ($checkPassed) { 45 | echo_block('success', 'OK', 'Your system is ready to run Symfony projects'); 46 | } else { 47 | echo_block('error', 'ERROR', 'Your system is not ready to run Symfony projects'); 48 | 49 | echo_title('Fix the following mandatory requirements', 'red'); 50 | 51 | foreach ($messages['error'] as $helpText) { 52 | echo ' * '.$helpText.PHP_EOL; 53 | } 54 | } 55 | 56 | if (!empty($messages['warning'])) { 57 | echo_title('Optional recommendations to improve your setup', 'yellow'); 58 | 59 | foreach ($messages['warning'] as $helpText) { 60 | echo ' * '.$helpText.PHP_EOL; 61 | } 62 | } 63 | 64 | echo PHP_EOL; 65 | echo_style('title', 'Note'); 66 | echo ' The command console could use a different php.ini file'.PHP_EOL; 67 | echo_style('title', '~~~~'); 68 | echo ' than the one used with your web server. To be on the'.PHP_EOL; 69 | echo ' safe side, please check the requirements from your web'.PHP_EOL; 70 | echo ' server using the '; 71 | echo_style('yellow', 'web/config.php'); 72 | echo ' script.'.PHP_EOL; 73 | echo PHP_EOL; 74 | 75 | exit($checkPassed ? 0 : 1); 76 | 77 | function get_error_message(Requirement $requirement, $lineSize) 78 | { 79 | if ($requirement->isFulfilled()) { 80 | return; 81 | } 82 | 83 | $errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL; 84 | $errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL; 85 | 86 | return $errorMessage; 87 | } 88 | 89 | function echo_title($title, $style = null) 90 | { 91 | $style = $style ?: 'title'; 92 | 93 | echo PHP_EOL; 94 | echo_style($style, $title.PHP_EOL); 95 | echo_style($style, str_repeat('~', strlen($title)).PHP_EOL); 96 | echo PHP_EOL; 97 | } 98 | 99 | function echo_style($style, $message) 100 | { 101 | // ANSI color codes 102 | $styles = array( 103 | 'reset' => "\033[0m", 104 | 'red' => "\033[31m", 105 | 'green' => "\033[32m", 106 | 'yellow' => "\033[33m", 107 | 'error' => "\033[37;41m", 108 | 'success' => "\033[37;42m", 109 | 'title' => "\033[34m", 110 | ); 111 | $supports = has_color_support(); 112 | 113 | echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : ''); 114 | } 115 | 116 | function echo_block($style, $title, $message) 117 | { 118 | $message = ' '.trim($message).' '; 119 | $width = strlen($message); 120 | 121 | echo PHP_EOL.PHP_EOL; 122 | 123 | echo_style($style, str_repeat(' ', $width)); 124 | echo PHP_EOL; 125 | echo_style($style, str_pad(' ['.$title.']', $width, ' ', STR_PAD_RIGHT)); 126 | echo PHP_EOL; 127 | echo_style($style, $message); 128 | echo PHP_EOL; 129 | echo_style($style, str_repeat(' ', $width)); 130 | echo PHP_EOL; 131 | } 132 | 133 | function has_color_support() 134 | { 135 | static $support; 136 | 137 | if (null === $support) { 138 | if (DIRECTORY_SEPARATOR == '\\') { 139 | $support = false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI'); 140 | } else { 141 | $support = function_exists('posix_isatty') && @posix_isatty(STDOUT); 142 | } 143 | } 144 | 145 | return $support; 146 | } 147 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tawfek/sf-vue", 3 | "license": "proprietary", 4 | "type": "project", 5 | "autoload": { 6 | "psr-4": { 7 | "AppBundle\\": "src/AppBundle" 8 | }, 9 | "classmap": [ 10 | "app/AppKernel.php", 11 | "app/AppCache.php" 12 | ] 13 | }, 14 | "autoload-dev": { 15 | "psr-4": { 16 | "Tests\\": "tests/" 17 | }, 18 | "files": [ 19 | "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" 20 | ] 21 | }, 22 | "require": { 23 | "php": ">=5.5.9", 24 | "doctrine/doctrine-bundle": "^1.6", 25 | "doctrine/orm": "^2.5", 26 | "incenteev/composer-parameter-handler": "^2.0", 27 | "minishlink/web-push-bundle": "^1.4", 28 | "sensio/distribution-bundle": "^5.0.19", 29 | "sensio/framework-extra-bundle": "^3.0.2", 30 | "symfony/monolog-bundle": "^3.1.0", 31 | "symfony/polyfill-apcu": "^1.0", 32 | "symfony/swiftmailer-bundle": "^2.3.10", 33 | "symfony/symfony": "3.3.*", 34 | "twig/twig": "^1.0||^2.0" 35 | }, 36 | "require-dev": { 37 | "sensio/generator-bundle": "^3.0", 38 | "symfony/phpunit-bridge": "^3.0" 39 | }, 40 | "scripts": { 41 | "symfony-scripts": [ 42 | "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", 43 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", 44 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", 45 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", 46 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", 47 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" 48 | ], 49 | "post-install-cmd": [ 50 | "@symfony-scripts" 51 | ], 52 | "post-update-cmd": [ 53 | "@symfony-scripts" 54 | ] 55 | }, 56 | "config": { 57 | "sort-packages": true 58 | }, 59 | "extra": { 60 | "symfony-app-dir": "app", 61 | "symfony-bin-dir": "bin", 62 | "symfony-var-dir": "var", 63 | "symfony-web-dir": "web", 64 | "symfony-tests-dir": "tests", 65 | "symfony-assets-install": "relative", 66 | "incenteev-parameters": { 67 | "file": "app/config/parameters.yml" 68 | }, 69 | "branch-alias": null 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "@symfony/webpack-encore": "^0.11.0", 4 | "babel-preset-env": "^1.6.0", 5 | "buefy": "^0.4.5", 6 | "node-sass": "^4.5.3", 7 | "offline-plugin": "^4.8.3", 8 | "sass-loader": "^6.0.6", 9 | "vue": "^2.4.2", 10 | "vue-loader": "^13.0.2", 11 | "vue-router": "^2.7.0", 12 | "vue-template-compiler": "^2.4.2", 13 | "webpack-manifest-plugin": "^1.2.1" 14 | }, 15 | "scripts": { 16 | "dev": "./node_modules/.bin/encore dev", 17 | "prod": "./node_modules/.bin/encore production" 18 | }, 19 | "dependencies": { 20 | "axios": "^0.16.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | tests 18 | 19 | 20 | 21 | 22 | 23 | src 24 | 25 | src/*Bundle/Resources 26 | src/*/*Bundle/Resources 27 | src/*/Bundle/*Bundle/Resources 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Require all denied 3 | 4 | 5 | Order deny,allow 6 | Deny from all 7 | 8 | -------------------------------------------------------------------------------- /src/AppBundle/AppBundle.php: -------------------------------------------------------------------------------- 1 | setName('push:notification') 20 | ->setDescription('...') 21 | ->addArgument('argument', InputArgument::OPTIONAL, 'Argument description') 22 | ->addOption('option', null, InputOption::VALUE_NONE, 'Option description') 23 | ; 24 | } 25 | 26 | protected function execute(InputInterface $input, OutputInterface $output) 27 | { 28 | 29 | /** @var WebPush $webPush */ 30 | $webPush = $this->getContainer()->get("minishlink_web_push"); 31 | 32 | $em = $this->getContainer()->get('doctrine')->getManager(); 33 | $repository = $em->getRepository("AppBundle:Subscriber"); 34 | $subscribers = $repository->findBy(["enabled" => 1]); 35 | 36 | $notification = json_encode([ 37 | "icon" => "https://cdn1.iconfinder.com/data/icons/twitter-ui-colored/48/JD-24-128.png", 38 | "title" => "this is a title", 39 | "tag" => "SymfonyPushNotification", 40 | "body" => "this is the body!!!", 41 | "url" => "https://google.com/" 42 | ]); 43 | 44 | /** @var Subscriber $subscriber */ 45 | foreach($subscribers as $subscriber){ 46 | $webPush->sendNotification($subscriber->getEndpoint() , $notification , $subscriber->getBrowserKey() , $subscriber->getAuthSecret() , false); 47 | $output->writeln("I've sent a notification!"); 48 | } 49 | $responses = $webPush->flush(); 50 | foreach($responses as $response){ 51 | switch ($response["success"]){ 52 | case false: 53 | $output->writeln($response["message"]); 54 | break; 55 | case true: 56 | /// no need to bother the user with success ones 57 | break; 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/AppBundle/Command/PushVapidKeysCommand.php: -------------------------------------------------------------------------------- 1 | setName('push:vapid-keys') 18 | ->setDescription('it will generate vapid keys') 19 | ; 20 | } 21 | 22 | protected function execute(InputInterface $input, OutputInterface $output) 23 | { 24 | $keys = VAPID::createVapidKeys(); 25 | $output->writeln("Generated Keys:"); 26 | $output->writeln("PublicKey:{$keys['publicKey']}"); 27 | $output->writeln("PrivateKey:{$keys['privateKey']}"); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/AppBundle/Controller/DefaultController.php: -------------------------------------------------------------------------------- 1 | render('default/index.html.twig', [ 23 | 'base_dir' => realpath($this->getParameter('kernel.project_dir')).DIRECTORY_SEPARATOR, 24 | 'vapidPublicKey' => $this->getParameter("webpush.publickey") 25 | ]); 26 | } 27 | 28 | 29 | /** 30 | * @Route("/notification/register", name="notification_register") 31 | * @Method("POST") 32 | */ 33 | public function registerAction(Request $request) 34 | { 35 | $em = $this->getDoctrine()->getManager(); 36 | $is_new = false; 37 | // looking for better approach ? look in http://labs.qandidate.com/blog/2014/08/13/handling-angularjs-post-requests-in-symfony/ 38 | $data = json_decode($request->getContent(), true); 39 | $is_subscribed = $em->getRepository("AppBundle:Subscriber")->findOneBy(['endpoint' => $data['endpoint']]); 40 | if(is_null($is_subscribed)){ 41 | $is_new = true; 42 | $subscriber = new Subscriber(); 43 | $subscriber->setEnabled(1); 44 | $subscriber->setBrowserKey($data['key']); 45 | $subscriber->setEndpoint($data['endpoint']); 46 | $subscriber->setAuthSecret($data['authSecret']); 47 | $em->persist($subscriber); 48 | $em->flush(); 49 | } 50 | return new JsonResponse(array('new' => $is_new, "success" => true)); 51 | } 52 | 53 | /** 54 | * @Route("/notification/unregister", name="notification_unregister") 55 | * @Method("POST") 56 | */ 57 | public function unregisterAction(Request $request) 58 | { 59 | $em = $this->getDoctrine()->getManager(); 60 | $data = json_decode($request->getContent(), true); 61 | $is_subscribed = $em->getRepository("AppBundle:Subscriber")->findOneBy(['endpoint' => $data['endpoint']]); 62 | if (!$is_subscribed) { 63 | throw $this->createNotFoundException('No found'); 64 | } 65 | $em->remove($is_subscribed); 66 | $em->flush(); 67 | return new JsonResponse(array("removed" => true)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/AppBundle/Entity/Subscriber.php: -------------------------------------------------------------------------------- 1 | id; 76 | } 77 | 78 | /** 79 | * Set endpoint 80 | * 81 | * @param string $endpoint 82 | * 83 | * @return Subscriber 84 | */ 85 | public function setEndpoint($endpoint) 86 | { 87 | $this->endpoint = $endpoint; 88 | 89 | return $this; 90 | } 91 | 92 | /** 93 | * Get endpoint 94 | * 95 | * @return string 96 | */ 97 | public function getEndpoint() 98 | { 99 | return $this->endpoint; 100 | } 101 | 102 | /** 103 | * Set browserKey 104 | * 105 | * @param string $browserKey 106 | * 107 | * @return Subscriber 108 | */ 109 | public function setBrowserKey($browserKey) 110 | { 111 | $this->browserKey = $browserKey; 112 | 113 | return $this; 114 | } 115 | 116 | /** 117 | * Get browserKey 118 | * 119 | * @return string 120 | */ 121 | public function getBrowserKey() 122 | { 123 | return $this->browserKey; 124 | } 125 | 126 | /** 127 | * Set authSecret 128 | * 129 | * @param string $authSecret 130 | * 131 | * @return Subscriber 132 | */ 133 | public function setAuthSecret($authSecret) 134 | { 135 | $this->authSecret = $authSecret; 136 | 137 | return $this; 138 | } 139 | 140 | /** 141 | * Get authSecret 142 | * 143 | * @return string 144 | */ 145 | public function getAuthSecret() 146 | { 147 | return $this->authSecret; 148 | } 149 | 150 | /** 151 | * Set subscribedAt 152 | * 153 | * @param \DateTime $subscribedAt 154 | * 155 | * @return Subscriber 156 | */ 157 | public function setSubscribedAt($subscribedAt) 158 | { 159 | $this->subscribedAt = $subscribedAt; 160 | 161 | return $this; 162 | } 163 | 164 | /** 165 | * Get SubscribedAt 166 | * 167 | * @return \DateTime 168 | */ 169 | public function getSubscribedAt() 170 | { 171 | return $this->subscribedAt; 172 | } 173 | 174 | /** 175 | * Set unsubscribedAt 176 | * 177 | * @param \DateTime $unsubscribedAt 178 | * 179 | * @return Subscriber 180 | */ 181 | public function setUnsubscribedAt($unsubscribedAt) 182 | { 183 | $this->unsubscribedAt = $unsubscribedAt; 184 | 185 | return $this; 186 | } 187 | 188 | /** 189 | * Get unsubscribedAt 190 | * 191 | * @return \DateTime 192 | */ 193 | public function getUnsubscribedAt() 194 | { 195 | return $this->unsubscribedAt; 196 | } 197 | 198 | /** 199 | * Set enabled 200 | * 201 | * @param boolean $enabled 202 | * 203 | * @return Subscriber 204 | */ 205 | public function setEnabled($enabled) 206 | { 207 | $this->enabled = $enabled; 208 | 209 | return $this; 210 | } 211 | 212 | /** 213 | * Get enabled 214 | * 215 | * @return bool 216 | */ 217 | public function getEnabled() 218 | { 219 | return $this->enabled; 220 | } 221 | 222 | /** 223 | * @ORM\PrePersist 224 | * @ORM\PreUpdate 225 | */ 226 | public function updatedTimestamps() 227 | { 228 | if ($this->subscribedAt == null) { 229 | $this->setSubscribedAt(new \DateTime('now')); 230 | $this->setUnsubscribedAt(new \DateTime('now')); 231 | } 232 | } 233 | } 234 | 235 | -------------------------------------------------------------------------------- /src/AppBundle/Repository/SubscriberRepository.php: -------------------------------------------------------------------------------- 1 | request('GET', '/'); 14 | 15 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); 16 | $this->assertContains('Welcome to Symfony', $crawler->filter('#container h1')->text()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /var/SymfonyRequirements.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * For the full copyright and license information, please view the LICENSE 9 | * file that was distributed with this source code. 10 | */ 11 | 12 | /* 13 | * Users of PHP 5.2 should be able to run the requirements checks. 14 | * This is why the file and all classes must be compatible with PHP 5.2+ 15 | * (e.g. not using namespaces and closures). 16 | * 17 | * ************** CAUTION ************** 18 | * 19 | * DO NOT EDIT THIS FILE as it will be overridden by Composer as part of 20 | * the installation/update process. The original file resides in the 21 | * SensioDistributionBundle. 22 | * 23 | * ************** CAUTION ************** 24 | */ 25 | 26 | /** 27 | * Represents a single PHP requirement, e.g. an installed extension. 28 | * It can be a mandatory requirement or an optional recommendation. 29 | * There is a special subclass, named PhpIniRequirement, to check a php.ini configuration. 30 | * 31 | * @author Tobias Schultze 32 | */ 33 | class Requirement 34 | { 35 | private $fulfilled; 36 | private $testMessage; 37 | private $helpText; 38 | private $helpHtml; 39 | private $optional; 40 | 41 | /** 42 | * Constructor that initializes the requirement. 43 | * 44 | * @param bool $fulfilled Whether the requirement is fulfilled 45 | * @param string $testMessage The message for testing the requirement 46 | * @param string $helpHtml The help text formatted in HTML for resolving the problem 47 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 48 | * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement 49 | */ 50 | public function __construct($fulfilled, $testMessage, $helpHtml, $helpText = null, $optional = false) 51 | { 52 | $this->fulfilled = (bool) $fulfilled; 53 | $this->testMessage = (string) $testMessage; 54 | $this->helpHtml = (string) $helpHtml; 55 | $this->helpText = null === $helpText ? strip_tags($this->helpHtml) : (string) $helpText; 56 | $this->optional = (bool) $optional; 57 | } 58 | 59 | /** 60 | * Returns whether the requirement is fulfilled. 61 | * 62 | * @return bool true if fulfilled, otherwise false 63 | */ 64 | public function isFulfilled() 65 | { 66 | return $this->fulfilled; 67 | } 68 | 69 | /** 70 | * Returns the message for testing the requirement. 71 | * 72 | * @return string The test message 73 | */ 74 | public function getTestMessage() 75 | { 76 | return $this->testMessage; 77 | } 78 | 79 | /** 80 | * Returns the help text for resolving the problem. 81 | * 82 | * @return string The help text 83 | */ 84 | public function getHelpText() 85 | { 86 | return $this->helpText; 87 | } 88 | 89 | /** 90 | * Returns the help text formatted in HTML. 91 | * 92 | * @return string The HTML help 93 | */ 94 | public function getHelpHtml() 95 | { 96 | return $this->helpHtml; 97 | } 98 | 99 | /** 100 | * Returns whether this is only an optional recommendation and not a mandatory requirement. 101 | * 102 | * @return bool true if optional, false if mandatory 103 | */ 104 | public function isOptional() 105 | { 106 | return $this->optional; 107 | } 108 | } 109 | 110 | /** 111 | * Represents a PHP requirement in form of a php.ini configuration. 112 | * 113 | * @author Tobias Schultze 114 | */ 115 | class PhpIniRequirement extends Requirement 116 | { 117 | /** 118 | * Constructor that initializes the requirement. 119 | * 120 | * @param string $cfgName The configuration name used for ini_get() 121 | * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, 122 | * or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement 123 | * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. 124 | * This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. 125 | * Example: You require a config to be true but PHP later removes this config and defaults it to true internally. 126 | * @param string|null $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) 127 | * @param string|null $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) 128 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 129 | * @param bool $optional Whether this is only an optional recommendation not a mandatory requirement 130 | */ 131 | public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null, $optional = false) 132 | { 133 | $cfgValue = ini_get($cfgName); 134 | 135 | if (is_callable($evaluation)) { 136 | if (null === $testMessage || null === $helpHtml) { 137 | throw new InvalidArgumentException('You must provide the parameters testMessage and helpHtml for a callback evaluation.'); 138 | } 139 | 140 | $fulfilled = call_user_func($evaluation, $cfgValue); 141 | } else { 142 | if (null === $testMessage) { 143 | $testMessage = sprintf('%s %s be %s in php.ini', 144 | $cfgName, 145 | $optional ? 'should' : 'must', 146 | $evaluation ? 'enabled' : 'disabled' 147 | ); 148 | } 149 | 150 | if (null === $helpHtml) { 151 | $helpHtml = sprintf('Set %s to %s in php.ini*.', 152 | $cfgName, 153 | $evaluation ? 'on' : 'off' 154 | ); 155 | } 156 | 157 | $fulfilled = $evaluation == $cfgValue; 158 | } 159 | 160 | parent::__construct($fulfilled || ($approveCfgAbsence && false === $cfgValue), $testMessage, $helpHtml, $helpText, $optional); 161 | } 162 | } 163 | 164 | /** 165 | * A RequirementCollection represents a set of Requirement instances. 166 | * 167 | * @author Tobias Schultze 168 | */ 169 | class RequirementCollection implements IteratorAggregate 170 | { 171 | /** 172 | * @var Requirement[] 173 | */ 174 | private $requirements = array(); 175 | 176 | /** 177 | * Gets the current RequirementCollection as an Iterator. 178 | * 179 | * @return Traversable A Traversable interface 180 | */ 181 | public function getIterator() 182 | { 183 | return new ArrayIterator($this->requirements); 184 | } 185 | 186 | /** 187 | * Adds a Requirement. 188 | * 189 | * @param Requirement $requirement A Requirement instance 190 | */ 191 | public function add(Requirement $requirement) 192 | { 193 | $this->requirements[] = $requirement; 194 | } 195 | 196 | /** 197 | * Adds a mandatory requirement. 198 | * 199 | * @param bool $fulfilled Whether the requirement is fulfilled 200 | * @param string $testMessage The message for testing the requirement 201 | * @param string $helpHtml The help text formatted in HTML for resolving the problem 202 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 203 | */ 204 | public function addRequirement($fulfilled, $testMessage, $helpHtml, $helpText = null) 205 | { 206 | $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, false)); 207 | } 208 | 209 | /** 210 | * Adds an optional recommendation. 211 | * 212 | * @param bool $fulfilled Whether the recommendation is fulfilled 213 | * @param string $testMessage The message for testing the recommendation 214 | * @param string $helpHtml The help text formatted in HTML for resolving the problem 215 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 216 | */ 217 | public function addRecommendation($fulfilled, $testMessage, $helpHtml, $helpText = null) 218 | { 219 | $this->add(new Requirement($fulfilled, $testMessage, $helpHtml, $helpText, true)); 220 | } 221 | 222 | /** 223 | * Adds a mandatory requirement in form of a php.ini configuration. 224 | * 225 | * @param string $cfgName The configuration name used for ini_get() 226 | * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, 227 | * or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement 228 | * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. 229 | * This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. 230 | * Example: You require a config to be true but PHP later removes this config and defaults it to true internally. 231 | * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) 232 | * @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) 233 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 234 | */ 235 | public function addPhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null) 236 | { 237 | $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, false)); 238 | } 239 | 240 | /** 241 | * Adds an optional recommendation in form of a php.ini configuration. 242 | * 243 | * @param string $cfgName The configuration name used for ini_get() 244 | * @param bool|callback $evaluation Either a boolean indicating whether the configuration should evaluate to true or false, 245 | * or a callback function receiving the configuration value as parameter to determine the fulfillment of the requirement 246 | * @param bool $approveCfgAbsence If true the Requirement will be fulfilled even if the configuration option does not exist, i.e. ini_get() returns false. 247 | * This is helpful for abandoned configs in later PHP versions or configs of an optional extension, like Suhosin. 248 | * Example: You require a config to be true but PHP later removes this config and defaults it to true internally. 249 | * @param string $testMessage The message for testing the requirement (when null and $evaluation is a boolean a default message is derived) 250 | * @param string $helpHtml The help text formatted in HTML for resolving the problem (when null and $evaluation is a boolean a default help is derived) 251 | * @param string|null $helpText The help text (when null, it will be inferred from $helpHtml, i.e. stripped from HTML tags) 252 | */ 253 | public function addPhpIniRecommendation($cfgName, $evaluation, $approveCfgAbsence = false, $testMessage = null, $helpHtml = null, $helpText = null) 254 | { 255 | $this->add(new PhpIniRequirement($cfgName, $evaluation, $approveCfgAbsence, $testMessage, $helpHtml, $helpText, true)); 256 | } 257 | 258 | /** 259 | * Adds a requirement collection to the current set of requirements. 260 | * 261 | * @param RequirementCollection $collection A RequirementCollection instance 262 | */ 263 | public function addCollection(RequirementCollection $collection) 264 | { 265 | $this->requirements = array_merge($this->requirements, $collection->all()); 266 | } 267 | 268 | /** 269 | * Returns both requirements and recommendations. 270 | * 271 | * @return Requirement[] 272 | */ 273 | public function all() 274 | { 275 | return $this->requirements; 276 | } 277 | 278 | /** 279 | * Returns all mandatory requirements. 280 | * 281 | * @return Requirement[] 282 | */ 283 | public function getRequirements() 284 | { 285 | $array = array(); 286 | foreach ($this->requirements as $req) { 287 | if (!$req->isOptional()) { 288 | $array[] = $req; 289 | } 290 | } 291 | 292 | return $array; 293 | } 294 | 295 | /** 296 | * Returns the mandatory requirements that were not met. 297 | * 298 | * @return Requirement[] 299 | */ 300 | public function getFailedRequirements() 301 | { 302 | $array = array(); 303 | foreach ($this->requirements as $req) { 304 | if (!$req->isFulfilled() && !$req->isOptional()) { 305 | $array[] = $req; 306 | } 307 | } 308 | 309 | return $array; 310 | } 311 | 312 | /** 313 | * Returns all optional recommendations. 314 | * 315 | * @return Requirement[] 316 | */ 317 | public function getRecommendations() 318 | { 319 | $array = array(); 320 | foreach ($this->requirements as $req) { 321 | if ($req->isOptional()) { 322 | $array[] = $req; 323 | } 324 | } 325 | 326 | return $array; 327 | } 328 | 329 | /** 330 | * Returns the recommendations that were not met. 331 | * 332 | * @return Requirement[] 333 | */ 334 | public function getFailedRecommendations() 335 | { 336 | $array = array(); 337 | foreach ($this->requirements as $req) { 338 | if (!$req->isFulfilled() && $req->isOptional()) { 339 | $array[] = $req; 340 | } 341 | } 342 | 343 | return $array; 344 | } 345 | 346 | /** 347 | * Returns whether a php.ini configuration is not correct. 348 | * 349 | * @return bool php.ini configuration problem? 350 | */ 351 | public function hasPhpIniConfigIssue() 352 | { 353 | foreach ($this->requirements as $req) { 354 | if (!$req->isFulfilled() && $req instanceof PhpIniRequirement) { 355 | return true; 356 | } 357 | } 358 | 359 | return false; 360 | } 361 | 362 | /** 363 | * Returns the PHP configuration file (php.ini) path. 364 | * 365 | * @return string|false php.ini file path 366 | */ 367 | public function getPhpIniConfigPath() 368 | { 369 | return get_cfg_var('cfg_file_path'); 370 | } 371 | } 372 | 373 | /** 374 | * This class specifies all requirements and optional recommendations that 375 | * are necessary to run the Symfony Standard Edition. 376 | * 377 | * @author Tobias Schultze 378 | * @author Fabien Potencier 379 | */ 380 | class SymfonyRequirements extends RequirementCollection 381 | { 382 | const LEGACY_REQUIRED_PHP_VERSION = '5.3.3'; 383 | const REQUIRED_PHP_VERSION = '5.5.9'; 384 | 385 | /** 386 | * Constructor that initializes the requirements. 387 | */ 388 | public function __construct() 389 | { 390 | /* mandatory requirements follow */ 391 | 392 | $installedPhpVersion = phpversion(); 393 | $requiredPhpVersion = $this->getPhpRequiredVersion(); 394 | 395 | $this->addRecommendation( 396 | $requiredPhpVersion, 397 | 'Vendors should be installed in order to check all requirements.', 398 | 'Run the composer install command.', 399 | 'Run the "composer install" command.' 400 | ); 401 | 402 | if (false !== $requiredPhpVersion) { 403 | $this->addRequirement( 404 | version_compare($installedPhpVersion, $requiredPhpVersion, '>='), 405 | sprintf('PHP version must be at least %s (%s installed)', $requiredPhpVersion, $installedPhpVersion), 406 | sprintf('You are running PHP version "%s", but Symfony needs at least PHP "%s" to run. 407 | Before using Symfony, upgrade your PHP installation, preferably to the latest version.', 408 | $installedPhpVersion, $requiredPhpVersion), 409 | sprintf('Install PHP %s or newer (installed version is %s)', $requiredPhpVersion, $installedPhpVersion) 410 | ); 411 | } 412 | 413 | $this->addRequirement( 414 | version_compare($installedPhpVersion, '5.3.16', '!='), 415 | 'PHP version must not be 5.3.16 as Symfony won\'t work properly with it', 416 | 'Install PHP 5.3.17 or newer (or downgrade to an earlier PHP version)' 417 | ); 418 | 419 | $this->addRequirement( 420 | is_dir(__DIR__.'/../vendor/composer'), 421 | 'Vendor libraries must be installed', 422 | 'Vendor libraries are missing. Install composer following instructions from http://getcomposer.org/. '. 423 | 'Then run "php composer.phar install" to install them.' 424 | ); 425 | 426 | $cacheDir = is_dir(__DIR__.'/../var/cache') ? __DIR__.'/../var/cache' : __DIR__.'/cache'; 427 | 428 | $this->addRequirement( 429 | is_writable($cacheDir), 430 | 'app/cache/ or var/cache/ directory must be writable', 431 | 'Change the permissions of either "app/cache/" or "var/cache/" directory so that the web server can write into it.' 432 | ); 433 | 434 | $logsDir = is_dir(__DIR__.'/../var/logs') ? __DIR__.'/../var/logs' : __DIR__.'/logs'; 435 | 436 | $this->addRequirement( 437 | is_writable($logsDir), 438 | 'app/logs/ or var/logs/ directory must be writable', 439 | 'Change the permissions of either "app/logs/" or "var/logs/" directory so that the web server can write into it.' 440 | ); 441 | 442 | if (version_compare($installedPhpVersion, '7.0.0', '<')) { 443 | $this->addPhpIniRequirement( 444 | 'date.timezone', true, false, 445 | 'date.timezone setting must be set', 446 | 'Set the "date.timezone" setting in php.ini* (like Europe/Paris).' 447 | ); 448 | } 449 | 450 | if (false !== $requiredPhpVersion && version_compare($installedPhpVersion, $requiredPhpVersion, '>=')) { 451 | $timezones = array(); 452 | foreach (DateTimeZone::listAbbreviations() as $abbreviations) { 453 | foreach ($abbreviations as $abbreviation) { 454 | $timezones[$abbreviation['timezone_id']] = true; 455 | } 456 | } 457 | 458 | $this->addRequirement( 459 | isset($timezones[@date_default_timezone_get()]), 460 | sprintf('Configured default timezone "%s" must be supported by your installation of PHP', @date_default_timezone_get()), 461 | 'Your default timezone is not supported by PHP. Check for typos in your php.ini file and have a look at the list of deprecated timezones at http://php.net/manual/en/timezones.others.php.' 462 | ); 463 | } 464 | 465 | $this->addRequirement( 466 | function_exists('iconv'), 467 | 'iconv() must be available', 468 | 'Install and enable the iconv extension.' 469 | ); 470 | 471 | $this->addRequirement( 472 | function_exists('json_encode'), 473 | 'json_encode() must be available', 474 | 'Install and enable the JSON extension.' 475 | ); 476 | 477 | $this->addRequirement( 478 | function_exists('session_start'), 479 | 'session_start() must be available', 480 | 'Install and enable the session extension.' 481 | ); 482 | 483 | $this->addRequirement( 484 | function_exists('ctype_alpha'), 485 | 'ctype_alpha() must be available', 486 | 'Install and enable the ctype extension.' 487 | ); 488 | 489 | $this->addRequirement( 490 | function_exists('token_get_all'), 491 | 'token_get_all() must be available', 492 | 'Install and enable the Tokenizer extension.' 493 | ); 494 | 495 | $this->addRequirement( 496 | function_exists('simplexml_import_dom'), 497 | 'simplexml_import_dom() must be available', 498 | 'Install and enable the SimpleXML extension.' 499 | ); 500 | 501 | if (function_exists('apc_store') && ini_get('apc.enabled')) { 502 | if (version_compare($installedPhpVersion, '5.4.0', '>=')) { 503 | $this->addRequirement( 504 | version_compare(phpversion('apc'), '3.1.13', '>='), 505 | 'APC version must be at least 3.1.13 when using PHP 5.4', 506 | 'Upgrade your APC extension (3.1.13+).' 507 | ); 508 | } else { 509 | $this->addRequirement( 510 | version_compare(phpversion('apc'), '3.0.17', '>='), 511 | 'APC version must be at least 3.0.17', 512 | 'Upgrade your APC extension (3.0.17+).' 513 | ); 514 | } 515 | } 516 | 517 | $this->addPhpIniRequirement('detect_unicode', false); 518 | 519 | if (extension_loaded('suhosin')) { 520 | $this->addPhpIniRequirement( 521 | 'suhosin.executor.include.whitelist', 522 | create_function('$cfgValue', 'return false !== stripos($cfgValue, "phar");'), 523 | false, 524 | 'suhosin.executor.include.whitelist must be configured correctly in php.ini', 525 | 'Add "phar" to suhosin.executor.include.whitelist in php.ini*.' 526 | ); 527 | } 528 | 529 | if (extension_loaded('xdebug')) { 530 | $this->addPhpIniRequirement( 531 | 'xdebug.show_exception_trace', false, true 532 | ); 533 | 534 | $this->addPhpIniRequirement( 535 | 'xdebug.scream', false, true 536 | ); 537 | 538 | $this->addPhpIniRecommendation( 539 | 'xdebug.max_nesting_level', 540 | create_function('$cfgValue', 'return $cfgValue > 100;'), 541 | true, 542 | 'xdebug.max_nesting_level should be above 100 in php.ini', 543 | 'Set "xdebug.max_nesting_level" to e.g. "250" in php.ini* to stop Xdebug\'s infinite recursion protection erroneously throwing a fatal error in your project.' 544 | ); 545 | } 546 | 547 | $pcreVersion = defined('PCRE_VERSION') ? (float) PCRE_VERSION : null; 548 | 549 | $this->addRequirement( 550 | null !== $pcreVersion, 551 | 'PCRE extension must be available', 552 | 'Install the PCRE extension (version 8.0+).' 553 | ); 554 | 555 | if (extension_loaded('mbstring')) { 556 | $this->addPhpIniRequirement( 557 | 'mbstring.func_overload', 558 | create_function('$cfgValue', 'return (int) $cfgValue === 0;'), 559 | true, 560 | 'string functions should not be overloaded', 561 | 'Set "mbstring.func_overload" to 0 in php.ini* to disable function overloading by the mbstring extension.' 562 | ); 563 | } 564 | 565 | /* optional recommendations follow */ 566 | 567 | if (file_exists(__DIR__.'/../vendor/composer')) { 568 | require_once __DIR__.'/../vendor/autoload.php'; 569 | 570 | try { 571 | $r = new ReflectionClass('Sensio\Bundle\DistributionBundle\SensioDistributionBundle'); 572 | 573 | $contents = file_get_contents(dirname($r->getFileName()).'/Resources/skeleton/app/SymfonyRequirements.php'); 574 | } catch (ReflectionException $e) { 575 | $contents = ''; 576 | } 577 | $this->addRecommendation( 578 | file_get_contents(__FILE__) === $contents, 579 | 'Requirements file should be up-to-date', 580 | 'Your requirements file is outdated. Run composer install and re-check your configuration.' 581 | ); 582 | } 583 | 584 | $this->addRecommendation( 585 | version_compare($installedPhpVersion, '5.3.4', '>='), 586 | 'You should use at least PHP 5.3.4 due to PHP bug #52083 in earlier versions', 587 | 'Your project might malfunction randomly due to PHP bug #52083 ("Notice: Trying to get property of non-object"). Install PHP 5.3.4 or newer.' 588 | ); 589 | 590 | $this->addRecommendation( 591 | version_compare($installedPhpVersion, '5.3.8', '>='), 592 | 'When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156', 593 | 'Install PHP 5.3.8 or newer if your project uses annotations.' 594 | ); 595 | 596 | $this->addRecommendation( 597 | version_compare($installedPhpVersion, '5.4.0', '!='), 598 | 'You should not use PHP 5.4.0 due to the PHP bug #61453', 599 | 'Your project might not work properly due to the PHP bug #61453 ("Cannot dump definitions which have method calls"). Install PHP 5.4.1 or newer.' 600 | ); 601 | 602 | $this->addRecommendation( 603 | version_compare($installedPhpVersion, '5.4.11', '>='), 604 | 'When using the logout handler from the Symfony Security Component, you should have at least PHP 5.4.11 due to PHP bug #63379 (as a workaround, you can also set invalidate_session to false in the security logout handler configuration)', 605 | 'Install PHP 5.4.11 or newer if your project uses the logout handler from the Symfony Security Component.' 606 | ); 607 | 608 | $this->addRecommendation( 609 | (version_compare($installedPhpVersion, '5.3.18', '>=') && version_compare($installedPhpVersion, '5.4.0', '<')) 610 | || 611 | version_compare($installedPhpVersion, '5.4.8', '>='), 612 | 'You should use PHP 5.3.18+ or PHP 5.4.8+ to always get nice error messages for fatal errors in the development environment due to PHP bug #61767/#60909', 613 | 'Install PHP 5.3.18+ or PHP 5.4.8+ if you want nice error messages for all fatal errors in the development environment.' 614 | ); 615 | 616 | if (null !== $pcreVersion) { 617 | $this->addRecommendation( 618 | $pcreVersion >= 8.0, 619 | sprintf('PCRE extension should be at least version 8.0 (%s installed)', $pcreVersion), 620 | 'PCRE 8.0+ is preconfigured in PHP since 5.3.2 but you are using an outdated version of it. Symfony probably works anyway but it is recommended to upgrade your PCRE extension.' 621 | ); 622 | } 623 | 624 | $this->addRecommendation( 625 | class_exists('DomDocument'), 626 | 'PHP-DOM and PHP-XML modules should be installed', 627 | 'Install and enable the PHP-DOM and the PHP-XML modules.' 628 | ); 629 | 630 | $this->addRecommendation( 631 | function_exists('mb_strlen'), 632 | 'mb_strlen() should be available', 633 | 'Install and enable the mbstring extension.' 634 | ); 635 | 636 | $this->addRecommendation( 637 | function_exists('utf8_decode'), 638 | 'utf8_decode() should be available', 639 | 'Install and enable the XML extension.' 640 | ); 641 | 642 | $this->addRecommendation( 643 | function_exists('filter_var'), 644 | 'filter_var() should be available', 645 | 'Install and enable the filter extension.' 646 | ); 647 | 648 | if (!defined('PHP_WINDOWS_VERSION_BUILD')) { 649 | $this->addRecommendation( 650 | function_exists('posix_isatty'), 651 | 'posix_isatty() should be available', 652 | 'Install and enable the php_posix extension (used to colorize the CLI output).' 653 | ); 654 | } 655 | 656 | $this->addRecommendation( 657 | extension_loaded('intl'), 658 | 'intl extension should be available', 659 | 'Install and enable the intl extension (used for validators).' 660 | ); 661 | 662 | if (extension_loaded('intl')) { 663 | // in some WAMP server installations, new Collator() returns null 664 | $this->addRecommendation( 665 | null !== new Collator('fr_FR'), 666 | 'intl extension should be correctly configured', 667 | 'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.' 668 | ); 669 | 670 | // check for compatible ICU versions (only done when you have the intl extension) 671 | if (defined('INTL_ICU_VERSION')) { 672 | $version = INTL_ICU_VERSION; 673 | } else { 674 | $reflector = new ReflectionExtension('intl'); 675 | 676 | ob_start(); 677 | $reflector->info(); 678 | $output = strip_tags(ob_get_clean()); 679 | 680 | preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches); 681 | $version = $matches[1]; 682 | } 683 | 684 | $this->addRecommendation( 685 | version_compare($version, '4.0', '>='), 686 | 'intl ICU version should be at least 4+', 687 | 'Upgrade your intl extension with a newer ICU version (4+).' 688 | ); 689 | 690 | if (class_exists('Symfony\Component\Intl\Intl')) { 691 | $this->addRecommendation( 692 | \Symfony\Component\Intl\Intl::getIcuDataVersion() <= \Symfony\Component\Intl\Intl::getIcuVersion(), 693 | sprintf('intl ICU version installed on your system is outdated (%s) and does not match the ICU data bundled with Symfony (%s)', \Symfony\Component\Intl\Intl::getIcuVersion(), \Symfony\Component\Intl\Intl::getIcuDataVersion()), 694 | 'To get the latest internationalization data upgrade the ICU system package and the intl PHP extension.' 695 | ); 696 | if (\Symfony\Component\Intl\Intl::getIcuDataVersion() <= \Symfony\Component\Intl\Intl::getIcuVersion()) { 697 | $this->addRecommendation( 698 | \Symfony\Component\Intl\Intl::getIcuDataVersion() === \Symfony\Component\Intl\Intl::getIcuVersion(), 699 | sprintf('intl ICU version installed on your system (%s) does not match the ICU data bundled with Symfony (%s)', \Symfony\Component\Intl\Intl::getIcuVersion(), \Symfony\Component\Intl\Intl::getIcuDataVersion()), 700 | 'To avoid internationalization data inconsistencies upgrade the symfony/intl component.' 701 | ); 702 | } 703 | } 704 | 705 | $this->addPhpIniRecommendation( 706 | 'intl.error_level', 707 | create_function('$cfgValue', 'return (int) $cfgValue === 0;'), 708 | true, 709 | 'intl.error_level should be 0 in php.ini', 710 | 'Set "intl.error_level" to "0" in php.ini* to inhibit the messages when an error occurs in ICU functions.' 711 | ); 712 | } 713 | 714 | $accelerator = 715 | (extension_loaded('eaccelerator') && ini_get('eaccelerator.enable')) 716 | || 717 | (extension_loaded('apc') && ini_get('apc.enabled')) 718 | || 719 | (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.enable')) 720 | || 721 | (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) 722 | || 723 | (extension_loaded('xcache') && ini_get('xcache.cacher')) 724 | || 725 | (extension_loaded('wincache') && ini_get('wincache.ocenabled')) 726 | ; 727 | 728 | $this->addRecommendation( 729 | $accelerator, 730 | 'a PHP accelerator should be installed', 731 | 'Install and/or enable a PHP accelerator (highly recommended).' 732 | ); 733 | 734 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 735 | $this->addRecommendation( 736 | $this->getRealpathCacheSize() >= 5 * 1024 * 1024, 737 | 'realpath_cache_size should be at least 5M in php.ini', 738 | 'Setting "realpath_cache_size" to e.g. "5242880" or "5M" in php.ini* may improve performance on Windows significantly in some cases.' 739 | ); 740 | } 741 | 742 | $this->addPhpIniRecommendation('short_open_tag', false); 743 | 744 | $this->addPhpIniRecommendation('magic_quotes_gpc', false, true); 745 | 746 | $this->addPhpIniRecommendation('register_globals', false, true); 747 | 748 | $this->addPhpIniRecommendation('session.auto_start', false); 749 | 750 | $this->addRecommendation( 751 | class_exists('PDO'), 752 | 'PDO should be installed', 753 | 'Install PDO (mandatory for Doctrine).' 754 | ); 755 | 756 | if (class_exists('PDO')) { 757 | $drivers = PDO::getAvailableDrivers(); 758 | $this->addRecommendation( 759 | count($drivers) > 0, 760 | sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'), 761 | 'Install PDO drivers (mandatory for Doctrine).' 762 | ); 763 | } 764 | } 765 | 766 | /** 767 | * Loads realpath_cache_size from php.ini and converts it to int. 768 | * 769 | * (e.g. 16k is converted to 16384 int) 770 | * 771 | * @return int 772 | */ 773 | protected function getRealpathCacheSize() 774 | { 775 | $size = ini_get('realpath_cache_size'); 776 | $size = trim($size); 777 | $unit = ''; 778 | if (!ctype_digit($size)) { 779 | $unit = strtolower(substr($size, -1, 1)); 780 | $size = (int) substr($size, 0, -1); 781 | } 782 | switch ($unit) { 783 | case 'g': 784 | return $size * 1024 * 1024 * 1024; 785 | case 'm': 786 | return $size * 1024 * 1024; 787 | case 'k': 788 | return $size * 1024; 789 | default: 790 | return (int) $size; 791 | } 792 | } 793 | 794 | /** 795 | * Defines PHP required version from Symfony version. 796 | * 797 | * @return string|false The PHP required version or false if it could not be guessed 798 | */ 799 | protected function getPhpRequiredVersion() 800 | { 801 | if (!file_exists($path = __DIR__.'/../composer.lock')) { 802 | return false; 803 | } 804 | 805 | $composerLock = json_decode(file_get_contents($path), true); 806 | foreach ($composerLock['packages'] as $package) { 807 | $name = $package['name']; 808 | if ('symfony/symfony' !== $name && 'symfony/http-kernel' !== $name) { 809 | continue; 810 | } 811 | 812 | return (int) $package['version'][1] > 2 ? self::REQUIRED_PHP_VERSION : self::LEGACY_REQUIRED_PHP_VERSION; 813 | } 814 | 815 | return false; 816 | } 817 | } 818 | -------------------------------------------------------------------------------- /var/cache/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tawfekov/SymfonyVue/f260de942784f098f625b55b251e1bdff5e5e757/var/cache/.gitkeep -------------------------------------------------------------------------------- /var/logs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tawfekov/SymfonyVue/f260de942784f098f625b55b251e1bdff5e5e757/var/logs/.gitkeep -------------------------------------------------------------------------------- /var/sessions/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tawfekov/SymfonyVue/f260de942784f098f625b55b251e1bdff5e5e757/var/sessions/.gitkeep -------------------------------------------------------------------------------- /web/.htaccess: -------------------------------------------------------------------------------- 1 | # Use the front controller as index file. It serves as a fallback solution when 2 | # every other rewrite/redirect fails (e.g. in an aliased environment without 3 | # mod_rewrite). Additionally, this reduces the matching process for the 4 | # start page (path "/") because otherwise Apache will apply the rewriting rules 5 | # to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl). 6 | DirectoryIndex app.php 7 | 8 | # By default, Apache does not evaluate symbolic links if you did not enable this 9 | # feature in your server configuration. Uncomment the following line if you 10 | # install assets as symlinks or if you experience problems related to symlinks 11 | # when compiling LESS/Sass/CoffeScript assets. 12 | # Options FollowSymlinks 13 | 14 | # Disabling MultiViews prevents unwanted negotiation, e.g. "/app" should not resolve 15 | # to the front controller "/app.php" but be rewritten to "/app.php/app". 16 | 17 | Options -MultiViews 18 | 19 | 20 | 21 | RewriteEngine On 22 | 23 | # Determine the RewriteBase automatically and set it as environment variable. 24 | # If you are using Apache aliases to do mass virtual hosting or installed the 25 | # project in a subdirectory, the base path will be prepended to allow proper 26 | # resolution of the app.php file and to redirect to the correct URI. It will 27 | # work in environments without path prefix as well, providing a safe, one-size 28 | # fits all solution. But as you do not need it in this case, you can comment 29 | # the following 2 lines to eliminate the overhead. 30 | RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 31 | RewriteRule ^(.*) - [E=BASE:%1] 32 | 33 | # Sets the HTTP_AUTHORIZATION header removed by Apache 34 | RewriteCond %{HTTP:Authorization} . 35 | RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 36 | 37 | # Redirect to URI without front controller to prevent duplicate content 38 | # (with and without `/app.php`). Only do this redirect on the initial 39 | # rewrite by Apache and not on subsequent cycles. Otherwise we would get an 40 | # endless redirect loop (request -> rewrite to front controller -> 41 | # redirect -> request -> ...). 42 | # So in case you get a "too many redirects" error or you always get redirected 43 | # to the start page because your Apache does not expose the REDIRECT_STATUS 44 | # environment variable, you have 2 choices: 45 | # - disable this feature by commenting the following 2 lines or 46 | # - use Apache >= 2.3.9 and replace all L flags by END flags and remove the 47 | # following RewriteCond (best solution) 48 | RewriteCond %{ENV:REDIRECT_STATUS} ^$ 49 | RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L] 50 | 51 | # If the requested filename exists, simply serve it. 52 | # We only want to let Apache serve files and not directories. 53 | RewriteCond %{REQUEST_FILENAME} -f 54 | RewriteRule ^ - [L] 55 | 56 | # Rewrite all other queries to the front controller. 57 | RewriteRule ^ %{ENV:BASE}/app.php [L] 58 | 59 | 60 | 61 | 62 | # When mod_rewrite is not available, we instruct a temporary redirect of 63 | # the start page to the front controller explicitly so that the website 64 | # and the generated links can still be used. 65 | RedirectMatch 302 ^/$ /app.php/ 66 | # RedirectTemp cannot be used instead 67 | 68 | 69 | -------------------------------------------------------------------------------- /web/app.php: -------------------------------------------------------------------------------- 1 | loadClassCache(); 13 | } 14 | //$kernel = new AppCache($kernel); 15 | 16 | // When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter 17 | //Request::enableHttpMethodParameterOverride(); 18 | $request = Request::createFromGlobals(); 19 | $response = $kernel->handle($request); 20 | $response->send(); 21 | $kernel->terminate($request, $response); 22 | -------------------------------------------------------------------------------- /web/app_dev.php: -------------------------------------------------------------------------------- 1 | loadClassCache(); 27 | } 28 | $request = Request::createFromGlobals(); 29 | $response = $kernel->handle($request); 30 | $response->send(); 31 | $kernel->terminate($request, $response); 32 | -------------------------------------------------------------------------------- /web/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tawfekov/SymfonyVue/f260de942784f098f625b55b251e1bdff5e5e757/web/apple-touch-icon.png -------------------------------------------------------------------------------- /web/assets/img/256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tawfekov/SymfonyVue/f260de942784f098f625b55b251e1bdff5e5e757/web/assets/img/256.png -------------------------------------------------------------------------------- /web/assets/img/512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tawfekov/SymfonyVue/f260de942784f098f625b55b251e1bdff5e5e757/web/assets/img/512.png -------------------------------------------------------------------------------- /web/assets/js/App.vue: -------------------------------------------------------------------------------- 1 | < 26 | 27 | -------------------------------------------------------------------------------- /web/assets/js/components/Demo.vue: -------------------------------------------------------------------------------- 1 | 87 | 88 | -------------------------------------------------------------------------------- /web/assets/js/components/Hello.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 28 | -------------------------------------------------------------------------------- /web/assets/js/components/Home.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 28 | -------------------------------------------------------------------------------- /web/assets/js/components/Notfound.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | 21 | -------------------------------------------------------------------------------- /web/assets/js/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import Router from 'vue-router' 3 | Vue.use(Router) 4 | 5 | // components 6 | import Home from '../components/Home' 7 | import Hello from '../components/Hello' 8 | import Notfound from '../components/Notfound' 9 | import Demo from '../components/Demo' 10 | 11 | export default new Router({ 12 | mode: 'history', 13 | routes: [ 14 | { 15 | path: '/', 16 | name: 'homepage', 17 | component: Home 18 | }, 19 | { 20 | path: '*', 21 | name: 'notfound', 22 | component: Notfound 23 | }, 24 | { 25 | path: '/hello', 26 | name: 'Hello', 27 | component: Hello 28 | }, 29 | { 30 | path: '/demo', 31 | name: 'demo', 32 | component: Demo 33 | } 34 | ] 35 | }) -------------------------------------------------------------------------------- /web/assets/js/sw.js: -------------------------------------------------------------------------------- 1 | self.addEventListener("install", () => { 2 | self.skipWaiting(); 3 | }); 4 | 5 | //listen to push notification 6 | /// listen to push event , aka push messages and display them 7 | self.addEventListener('push', function (event) { 8 | 9 | var payload = event.data ? event.data.text() : 'no payload'; 10 | console.log('Received a push message', payload); 11 | payload = JSON.parse(payload); 12 | 13 | var title = payload.title; 14 | var body = payload.body; 15 | var icon = payload.icon; 16 | var tag = payload.tag; 17 | 18 | event.waitUntil( 19 | self.registration.showNotification(title, { 20 | body: body, 21 | icon: icon, 22 | tag: tag 23 | }) 24 | ); 25 | }); 26 | 27 | // listen to close notification event , try to gain focus on webapp 28 | self.addEventListener("notificationclick", function (event) { 29 | console.log(event); 30 | //To open the app after click notification 31 | event.waitUntil( 32 | clients.matchAll({ 33 | type: "window" 34 | }) 35 | .then(function (clientList) { 36 | for (var i = 0; i < clientList.length; i++) { 37 | var client = clientList[i]; 38 | if ("focus" in client) { 39 | return client.focus(); 40 | } 41 | } 42 | 43 | if (clientList.length === 0) { 44 | if (clients.openWindow) { 45 | return clients.openWindow(event.url); 46 | } 47 | } 48 | }) 49 | ); 50 | 51 | // close the notification 52 | event.notification.close(); 53 | }); -------------------------------------------------------------------------------- /web/assets/js/vendor.js: -------------------------------------------------------------------------------- 1 | require('offline-plugin/runtime').install(); 2 | import axios from 'axios' 3 | 4 | /// make axis global so we can use it every where 5 | window.axios = axios 6 | 7 | function urlBase64ToUint8Array(base64String) { 8 | const padding = '='.repeat((4 - base64String.length % 4) % 4); 9 | const base64 = (base64String + padding) 10 | .replace(/\-/g, '+') 11 | .replace(/_/g, '/'); 12 | 13 | const rawData = window.atob(base64); 14 | const outputArray = new Uint8Array(rawData.length); 15 | 16 | for (let i = 0; i < rawData.length; ++i) { 17 | outputArray[i] = rawData.charCodeAt(i); 18 | } 19 | return outputArray; 20 | } 21 | 22 | /// get browser's end point 23 | if ('serviceWorker' in navigator && "Notification" in window) { 24 | Notification.requestPermission().then(function (result) { 25 | if (result == "granted") { 26 | navigator.serviceWorker.getRegistration() 27 | .then(function (registration) { 28 | return registration.pushManager.getSubscription() 29 | .then(function (subscription) { 30 | if (subscription) { 31 | return subscription; 32 | } 33 | return registration.pushManager.subscribe({ 34 | userVisibleOnly: true, 35 | applicationServerKey: new urlBase64ToUint8Array('BGisx88cLlx83WZ1Yc/V/2U+4G4/g2u9aeoUaUKSd1L+cCTF/4ow5xGWvLCZTPZav92/wkr6r9h2OyKgcWb6s5c=') 36 | }); 37 | }); 38 | }).then(function (subscription) { 39 | 40 | const endpoint = subscription.endpoint; 41 | const rawKey = subscription.getKey('p256dh'); 42 | const rawToken = subscription.getKey('auth'); 43 | const key = rawKey ? btoa(String.fromCharCode.apply(null, new Uint8Array(rawKey))) : null; 44 | const token = rawToken ? btoa(String.fromCharCode.apply(null, new Uint8Array(rawToken))) : null; 45 | console.log(subscription.toJSON()); 46 | console.log(rawKey,token); 47 | 48 | axios.post('/notification/register', { 'endpoint': endpoint , 'key' : key , 'authSecret' : token}) 49 | .then(function (response) { 50 | if (response.data.new) { 51 | new Notification("Thank you for enabling notification", { 52 | body: "We won't spam you , we promise", 53 | tag: "success", 54 | icon: "https://cdn1.iconfinder.com/data/icons/twitter-ui-colored/48/JD-24-128.png" 55 | }); 56 | } 57 | }) 58 | .catch(function (error) { 59 | alert("we can't save your endpoint"); 60 | console.log(error); 61 | }); 62 | }); 63 | } 64 | }); 65 | } -------------------------------------------------------------------------------- /web/assets/js/vue.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueRouter from 'vue-router' 3 | import router from './router/' 4 | import Buefy from 'buefy' 5 | /// application specific 6 | import App from './App' 7 | 8 | Vue.config.productionTip = false 9 | Vue.use(Buefy) 10 | Vue.use(VueRouter); 11 | 12 | // bootstrap the demo 13 | let demo = new Vue({ 14 | el: '#vueApp', 15 | router, 16 | template: '', 17 | components: { App } 18 | }) -------------------------------------------------------------------------------- /web/assets/scss/style.scss: -------------------------------------------------------------------------------- 1 | @import "../../../node_modules/buefy/lib/buefy.css"; 2 | 3 | @media (min-width: 768px) { 4 | @-webkit-keyframes fade-in { 5 | 0% { 6 | opacity: 0; 7 | } 8 | 100% { 9 | opacity: 1; 10 | } 11 | } 12 | @keyframes fade-in { 13 | 0% { 14 | opacity: 0; 15 | } 16 | 100% { 17 | opacity: 1; 18 | } 19 | } 20 | .sf-toolbar { 21 | opacity: 0; 22 | -webkit-animation: fade-in 1s .2s forwards; 23 | animation: fade-in 1s .2s forwards; 24 | } 25 | } -------------------------------------------------------------------------------- /web/build/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "SymfonyVue", 3 | "name": "SymfonyVue", 4 | "start_url": "/", 5 | "icons": [ 6 | { 7 | "src": "/build/images/256.png", 8 | "sizes": "256x256", 9 | "type": "image/png" 10 | }, 11 | { 12 | "src": "/build/images/512.png", 13 | "sizes": "512x512", 14 | "type": "image/png" 15 | } 16 | ], 17 | "background_color": "#FAFAFA", 18 | "theme_color": "#e10b0b", 19 | "display": "standalone", 20 | "orientation": "portrait", 21 | "/web/build/style.css": "/web/build/style.css", 22 | "/web/build/sw.js": "/web/build/sw.js", 23 | "/web/build/vendor.js": "/web/build/vendor.js", 24 | "/web/build/vue.js": "/web/build/vue.js" 25 | } -------------------------------------------------------------------------------- /web/build/sw.js: -------------------------------------------------------------------------------- 1 | !function(n){function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var e={};t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:r})},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p="/build/",t(t.s="jgIZ")}({jgIZ:/*!*****************************!*\ 2 | !*** ./web/assets/js/sw.js ***! 3 | \*****************************/ 4 | /*! no static exports found */ 5 | /*! all exports used */ 6 | function(n,t){self.addEventListener("install",function(){self.skipWaiting()})}}); -------------------------------------------------------------------------------- /web/build/vendor.js: -------------------------------------------------------------------------------- 1 | !function(n){function t(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return n[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var e={};t.m=n,t.c=e,t.d=function(n,e,o){t.o(n,e)||Object.defineProperty(n,e,{configurable:!1,enumerable:!0,get:o})},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},t.p="/build/",t(t.s="SGwB")}({SGwB:/*!*********************************!*\ 2 | !*** ./web/assets/js/vendor.js ***! 3 | \*********************************/ 4 | /*! no static exports found */ 5 | /*! all exports used */ 6 | function(n,t,e){e(/*! offline-plugin/runtime */"t8iB").install()},t8iB:/*!************************************************!*\ 7 | !*** ./node_modules/offline-plugin/runtime.js ***! 8 | \************************************************/ 9 | /*! no static exports found */ 10 | /*! all exports used */ 11 | function(n,t){function e(){return"serviceWorker"in navigator&&(window.fetch||"imageRendering"in document.documentElement.style)&&("https:"===window.location.protocol||"localhost"===window.location.hostname||0===window.location.hostname.indexOf("127."))}function o(n){if(n||(n={}),e()){navigator.serviceWorker.register("/sw.js",{scope:"/"})}else;}function r(n,t){}function i(){e()&&navigator.serviceWorker.getRegistration().then(function(n){if(n)return n.update()})}t.install=o,t.applyUpdate=r,t.update=i}}); -------------------------------------------------------------------------------- /web/config.php: -------------------------------------------------------------------------------- 1 | getFailedRequirements(); 30 | $minorProblems = $symfonyRequirements->getFailedRecommendations(); 31 | $hasMajorProblems = (bool) count($majorProblems); 32 | $hasMinorProblems = (bool) count($minorProblems); 33 | 34 | ?> 35 | 36 | 37 | 38 | 39 | 40 | Symfony Configuration Checker 41 | 331 | 332 | 333 |
334 |
335 | 338 | 339 | 359 |
360 | 361 |
362 |
363 |
364 |

Configuration Checker

365 |

366 | This script analyzes your system to check whether is 367 | ready to run Symfony applications. 368 |

369 | 370 | 371 |

Major problems

372 |

Major problems have been detected and must be fixed before continuing:

373 |
    374 | 375 |
  1. getTestMessage() ?> 376 |

    getHelpHtml() ?>

    377 |
  2. 378 | 379 |
380 | 381 | 382 | 383 |

Recommendations

384 |

385 | Additionally, toTo enhance your Symfony experience, 386 | it’s recommended that you fix the following: 387 |

388 |
    389 | 390 |
  1. getTestMessage() ?> 391 |

    getHelpHtml() ?>

    392 |
  2. 393 | 394 |
395 | 396 | 397 | hasPhpIniConfigIssue()): ?> 398 |

* 399 | getPhpIniConfigPath()): ?> 400 | Changes to the php.ini file must be done in "getPhpIniConfigPath() ?>". 401 | 402 | To change settings, create a "php.ini". 403 | 404 |

405 | 406 | 407 | 408 |

All checks passed successfully. Your system is ready to run Symfony applications.

409 | 410 | 411 | 416 |
417 |
418 |
419 |
Symfony Standard Edition
420 |
421 | 422 | 423 | -------------------------------------------------------------------------------- /web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tawfekov/SymfonyVue/f260de942784f098f625b55b251e1bdff5e5e757/web/favicon.ico -------------------------------------------------------------------------------- /web/img/256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tawfekov/SymfonyVue/f260de942784f098f625b55b251e1bdff5e5e757/web/img/256.png -------------------------------------------------------------------------------- /web/img/512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tawfekov/SymfonyVue/f260de942784f098f625b55b251e1bdff5e5e757/web/img/512.png -------------------------------------------------------------------------------- /web/robots.txt: -------------------------------------------------------------------------------- 1 | # www.robotstxt.org/ 2 | # www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449 3 | 4 | User-agent: * 5 | Disallow: 6 | -------------------------------------------------------------------------------- /web/sw.js: -------------------------------------------------------------------------------- 1 | var __wpo = { 2 | "assets": { 3 | "main": [ 4 | "/build/manifest.json", 5 | "/build/style.css", 6 | "/build/vue.js", 7 | "/build/vendor.js", 8 | "/build/sw.js" 9 | ], 10 | "additional": [], 11 | "optional": [] 12 | }, 13 | "externals": [], 14 | "hashesMap": { 15 | "0e67b2a89df2130491f39fa4366506b677dce5a1": "/build/vue.js", 16 | "cd455750703a5f496a3ea40185844de2929bba7b": "/build/vendor.js", 17 | "3b74b98a4229fa5ae3bcd7419e442b26f7542582": "/build/sw.js", 18 | "7b22795ab1fb451903939019ae81495ce0011113": "/build/style.css", 19 | "8069438e3ce4fa26c9fd97abde2424f7b501be7f": "/build/manifest.json" 20 | }, 21 | "navigateFallbackURL": "/../", 22 | "navigateFallbackForRedirects": true, 23 | "strategy": "changed", 24 | "responseStrategy": "cache-first", 25 | "version": "7/25/2017, 4:20:57 PM", 26 | "name": "webpack-offline:SymfonyVue", 27 | "pluginVersion": "4.8.3", 28 | "relativePaths": false 29 | }; 30 | 31 | /******/ (function(modules) { // webpackBootstrap 32 | /******/ // The module cache 33 | /******/ var installedModules = {}; 34 | /******/ 35 | /******/ // The require function 36 | /******/ function __webpack_require__(moduleId) { 37 | /******/ 38 | /******/ // Check if module is in cache 39 | /******/ if(installedModules[moduleId]) { 40 | /******/ return installedModules[moduleId].exports; 41 | /******/ } 42 | /******/ // Create a new module (and put it into the cache) 43 | /******/ var module = installedModules[moduleId] = { 44 | /******/ i: moduleId, 45 | /******/ l: false, 46 | /******/ exports: {} 47 | /******/ }; 48 | /******/ 49 | /******/ // Execute the module function 50 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 51 | /******/ 52 | /******/ // Flag the module as loaded 53 | /******/ module.l = true; 54 | /******/ 55 | /******/ // Return the exports of the module 56 | /******/ return module.exports; 57 | /******/ } 58 | /******/ 59 | /******/ 60 | /******/ // expose the modules object (__webpack_modules__) 61 | /******/ __webpack_require__.m = modules; 62 | /******/ 63 | /******/ // expose the module cache 64 | /******/ __webpack_require__.c = installedModules; 65 | /******/ 66 | /******/ // define getter function for harmony exports 67 | /******/ __webpack_require__.d = function(exports, name, getter) { 68 | /******/ if(!__webpack_require__.o(exports, name)) { 69 | /******/ Object.defineProperty(exports, name, { 70 | /******/ configurable: false, 71 | /******/ enumerable: true, 72 | /******/ get: getter 73 | /******/ }); 74 | /******/ } 75 | /******/ }; 76 | /******/ 77 | /******/ // getDefaultExport function for compatibility with non-harmony modules 78 | /******/ __webpack_require__.n = function(module) { 79 | /******/ var getter = module && module.__esModule ? 80 | /******/ function getDefault() { return module['default']; } : 81 | /******/ function getModuleExports() { return module; }; 82 | /******/ __webpack_require__.d(getter, 'a', getter); 83 | /******/ return getter; 84 | /******/ }; 85 | /******/ 86 | /******/ // Object.prototype.hasOwnProperty.call 87 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 88 | /******/ 89 | /******/ // __webpack_public_path__ 90 | /******/ __webpack_require__.p = "/build/"; 91 | /******/ 92 | /******/ // Load entry module and return exports 93 | /******/ return __webpack_require__(__webpack_require__.s = "UW7J"); 94 | /******/ }) 95 | /************************************************************************/ 96 | /******/ ({ 97 | 98 | /***/ "UW7J": 99 | /*!**********************************************************************************************************************************************************************************!*\ 100 | !*** ./node_modules/offline-plugin/lib/misc/sw-loader.js?json=%7B%22data_var_name%22%3A%22__wpo%22%2C%22loaders%22%3A%5B%5D%2C%22cacheMaps%22%3A%5B%5D%7D!./web/assets/js/sw.js ***! 101 | \**********************************************************************************************************************************************************************************/ 102 | /*! no static exports found */ 103 | /*! all exports used */ 104 | /***/ (function(module, exports, __webpack_require__) { 105 | 106 | "use strict"; 107 | 108 | 109 | (function () { 110 | var waitUntil = ExtendableEvent.prototype.waitUntil; 111 | var respondWith = FetchEvent.prototype.respondWith; 112 | var promisesMap = new WeakMap(); 113 | 114 | ExtendableEvent.prototype.waitUntil = function (promise) { 115 | var extendableEvent = this; 116 | var promises = promisesMap.get(extendableEvent); 117 | 118 | if (promises) { 119 | promises.push(Promise.resolve(promise)); 120 | return; 121 | } 122 | 123 | promises = [Promise.resolve(promise)]; 124 | promisesMap.set(extendableEvent, promises); 125 | 126 | // call original method 127 | return waitUntil.call(extendableEvent, Promise.resolve().then(function processPromises() { 128 | var len = promises.length; 129 | 130 | // wait for all to settle 131 | return Promise.all(promises.map(function (p) { 132 | return p["catch"](function () {}); 133 | })).then(function () { 134 | // have new items been added? If so, wait again 135 | if (promises.length != len) return processPromises(); 136 | // we're done! 137 | promisesMap["delete"](extendableEvent); 138 | // reject if one of the promises rejected 139 | return Promise.all(promises); 140 | }); 141 | })); 142 | }; 143 | 144 | FetchEvent.prototype.respondWith = function (promise) { 145 | this.waitUntil(promise); 146 | return respondWith.call(this, promise); 147 | }; 148 | })();; 149 | 'use strict'; 150 | 151 | if (typeof DEBUG === 'undefined') { 152 | var DEBUG = false; 153 | } 154 | 155 | function WebpackServiceWorker(params, helpers) { 156 | var loaders = helpers.loaders; 157 | var cacheMaps = helpers.cacheMaps; 158 | 159 | var strategy = params.strategy; 160 | var responseStrategy = params.responseStrategy; 161 | 162 | var assets = params.assets; 163 | var loadersMap = params.loaders || {}; 164 | 165 | var hashesMap = params.hashesMap; 166 | var externals = params.externals; 167 | 168 | // Not used yet 169 | // const alwaysRevalidate = params.alwaysRevalidate; 170 | // const ignoreSearch = params.ignoreSearch; 171 | // const preferOnline = params.preferOnline; 172 | 173 | var CACHE_PREFIX = params.name; 174 | var CACHE_TAG = params.version; 175 | var CACHE_NAME = CACHE_PREFIX + ':' + CACHE_TAG; 176 | 177 | var STORED_DATA_KEY = '__offline_webpack__data'; 178 | 179 | mapAssets(); 180 | 181 | var allAssets = [].concat(assets.main, assets.additional, assets.optional); 182 | var navigateFallbackURL = params.navigateFallbackURL; 183 | var navigateFallbackForRedirects = params.navigateFallbackForRedirects; 184 | 185 | self.addEventListener('install', function (event) { 186 | console.log('[SW]:', 'Install event'); 187 | 188 | var installing = undefined; 189 | 190 | if (strategy === 'changed') { 191 | installing = cacheChanged('main'); 192 | } else { 193 | installing = cacheAssets('main'); 194 | } 195 | 196 | event.waitUntil(installing); 197 | }); 198 | 199 | self.addEventListener('activate', function (event) { 200 | console.log('[SW]:', 'Activate event'); 201 | 202 | var activation = cacheAdditional(); 203 | 204 | // Delete all assets which name starts with CACHE_PREFIX and 205 | // is not current cache (CACHE_NAME) 206 | activation = activation.then(storeCacheData); 207 | activation = activation.then(deleteObsolete); 208 | activation = activation.then(function () { 209 | if (self.clients && self.clients.claim) { 210 | return self.clients.claim(); 211 | } 212 | }); 213 | 214 | event.waitUntil(activation); 215 | }); 216 | 217 | function cacheAdditional() { 218 | if (!assets.additional.length) { 219 | return Promise.resolve(); 220 | } 221 | 222 | if (DEBUG) { 223 | console.log('[SW]:', 'Caching additional'); 224 | } 225 | 226 | var operation = undefined; 227 | 228 | if (strategy === 'changed') { 229 | operation = cacheChanged('additional'); 230 | } else { 231 | operation = cacheAssets('additional'); 232 | } 233 | 234 | // Ignore fail of `additional` cache section 235 | return operation['catch'](function (e) { 236 | console.error('[SW]:', 'Cache section `additional` failed to load'); 237 | }); 238 | } 239 | 240 | function cacheAssets(section) { 241 | var batch = assets[section]; 242 | 243 | return caches.open(CACHE_NAME).then(function (cache) { 244 | return addAllNormalized(cache, batch, { 245 | bust: params.version, 246 | request: params.prefetchRequest 247 | }); 248 | }).then(function () { 249 | logGroup('Cached assets: ' + section, batch); 250 | })['catch'](function (e) { 251 | console.error(e); 252 | throw e; 253 | }); 254 | } 255 | 256 | function cacheChanged(section) { 257 | return getLastCache().then(function (args) { 258 | if (!args) { 259 | return cacheAssets(section); 260 | } 261 | 262 | var lastCache = args[0]; 263 | var lastKeys = args[1]; 264 | var lastData = args[2]; 265 | 266 | var lastMap = lastData.hashmap; 267 | var lastVersion = lastData.version; 268 | 269 | if (!lastData.hashmap || lastVersion === params.version) { 270 | return cacheAssets(section); 271 | } 272 | 273 | var lastHashedAssets = Object.keys(lastMap).map(function (hash) { 274 | return lastMap[hash]; 275 | }); 276 | 277 | var lastUrls = lastKeys.map(function (req) { 278 | var url = new URL(req.url); 279 | url.search = ''; 280 | url.hash = ''; 281 | 282 | return url.toString(); 283 | }); 284 | 285 | var sectionAssets = assets[section]; 286 | var moved = []; 287 | var changed = sectionAssets.filter(function (url) { 288 | if (lastUrls.indexOf(url) === -1 || lastHashedAssets.indexOf(url) === -1) { 289 | return true; 290 | } 291 | 292 | return false; 293 | }); 294 | 295 | Object.keys(hashesMap).forEach(function (hash) { 296 | var asset = hashesMap[hash]; 297 | 298 | // Return if not in sectionAssets or in changed or moved array 299 | if (sectionAssets.indexOf(asset) === -1 || changed.indexOf(asset) !== -1 || moved.indexOf(asset) !== -1) return; 300 | 301 | var lastAsset = lastMap[hash]; 302 | 303 | if (lastAsset && lastUrls.indexOf(lastAsset) !== -1) { 304 | moved.push([lastAsset, asset]); 305 | } else { 306 | changed.push(asset); 307 | } 308 | }); 309 | 310 | logGroup('Changed assets: ' + section, changed); 311 | logGroup('Moved assets: ' + section, moved); 312 | 313 | var movedResponses = Promise.all(moved.map(function (pair) { 314 | return lastCache.match(pair[0]).then(function (response) { 315 | return [pair[1], response]; 316 | }); 317 | })); 318 | 319 | return caches.open(CACHE_NAME).then(function (cache) { 320 | var move = movedResponses.then(function (responses) { 321 | return Promise.all(responses.map(function (pair) { 322 | return cache.put(pair[0], pair[1]); 323 | })); 324 | }); 325 | 326 | return Promise.all([move, addAllNormalized(cache, changed, { 327 | bust: params.version, 328 | request: params.prefetchRequest 329 | })]); 330 | }); 331 | }); 332 | } 333 | 334 | function deleteObsolete() { 335 | return caches.keys().then(function (keys) { 336 | var all = keys.map(function (key) { 337 | if (key.indexOf(CACHE_PREFIX) !== 0 || key.indexOf(CACHE_NAME) === 0) return; 338 | 339 | console.log('[SW]:', 'Delete cache:', key); 340 | return caches['delete'](key); 341 | }); 342 | 343 | return Promise.all(all); 344 | }); 345 | } 346 | 347 | function getLastCache() { 348 | return caches.keys().then(function (keys) { 349 | var index = keys.length; 350 | var key = undefined; 351 | 352 | while (index--) { 353 | key = keys[index]; 354 | 355 | if (key.indexOf(CACHE_PREFIX) === 0) { 356 | break; 357 | } 358 | } 359 | 360 | if (!key) return; 361 | 362 | var cache = undefined; 363 | 364 | return caches.open(key).then(function (_cache) { 365 | cache = _cache; 366 | return _cache.match(new URL(STORED_DATA_KEY, location).toString()); 367 | }).then(function (response) { 368 | if (!response) return; 369 | 370 | return Promise.all([cache, cache.keys(), response.json()]); 371 | }); 372 | }); 373 | } 374 | 375 | function storeCacheData() { 376 | return caches.open(CACHE_NAME).then(function (cache) { 377 | var data = new Response(JSON.stringify({ 378 | version: params.version, 379 | hashmap: hashesMap 380 | })); 381 | 382 | return cache.put(new URL(STORED_DATA_KEY, location).toString(), data); 383 | }); 384 | } 385 | 386 | self.addEventListener('fetch', function (event) { 387 | var url = new URL(event.request.url); 388 | url.hash = ''; 389 | 390 | var urlString = url.toString(); 391 | 392 | // Not external, so search part of the URL should be stripped, 393 | // if it's external URL, the search part should be kept 394 | if (externals.indexOf(urlString) === -1) { 395 | url.search = ''; 396 | urlString = url.toString(); 397 | } 398 | 399 | // Handle only GET requests 400 | var isGET = event.request.method === 'GET'; 401 | var assetMatches = allAssets.indexOf(urlString) !== -1; 402 | var cacheUrl = urlString; 403 | 404 | if (!assetMatches) { 405 | var cacheRewrite = matchCacheMap(event.request); 406 | 407 | if (cacheRewrite) { 408 | cacheUrl = cacheRewrite; 409 | assetMatches = true; 410 | } 411 | } 412 | 413 | if (!assetMatches && isGET) { 414 | // If isn't a cached asset and is a navigation request, 415 | // fallback to navigateFallbackURL if available 416 | if (navigateFallbackURL && isNavigateRequest(event.request)) { 417 | event.respondWith(handleNavigateFallback(fetch(event.request))); 418 | 419 | return; 420 | } 421 | } 422 | 423 | if (!assetMatches || !isGET) { 424 | // Fix for https://twitter.com/wanderview/status/696819243262873600 425 | if (url.origin !== location.origin && navigator.userAgent.indexOf('Firefox/44.') !== -1) { 426 | event.respondWith(fetch(event.request)); 427 | } 428 | 429 | return; 430 | } 431 | 432 | // Logic of caching / fetching is here 433 | // * urlString -- url to match from the CACHE_NAME 434 | // * event.request -- original Request to perform fetch() if necessary 435 | var resource = undefined; 436 | 437 | if (responseStrategy === 'network-first') { 438 | resource = networkFirstResponse(event, urlString, cacheUrl); 439 | } 440 | // 'cache-first' 441 | // (responseStrategy has been validated before) 442 | else { 443 | resource = cacheFirstResponse(event, urlString, cacheUrl); 444 | } 445 | 446 | if (navigateFallbackURL && isNavigateRequest(event.request)) { 447 | resource = handleNavigateFallback(resource); 448 | } 449 | 450 | event.respondWith(resource); 451 | }); 452 | 453 | self.addEventListener('message', function (e) { 454 | var data = e.data; 455 | if (!data) return; 456 | 457 | switch (data.action) { 458 | case 'skipWaiting': 459 | { 460 | if (self.skipWaiting) self.skipWaiting(); 461 | }break; 462 | } 463 | }); 464 | 465 | function cacheFirstResponse(event, urlString, cacheUrl) { 466 | return cachesMatch(cacheUrl, CACHE_NAME).then(function (response) { 467 | if (response) { 468 | if (DEBUG) { 469 | console.log('[SW]:', 'URL [' + cacheUrl + '](' + urlString + ') from cache'); 470 | } 471 | 472 | return response; 473 | } 474 | 475 | // Load and cache known assets 476 | var fetching = fetch(event.request).then(function (response) { 477 | if (!response.ok) { 478 | if (DEBUG) { 479 | console.log('[SW]:', 'URL [' + urlString + '] wrong response: [' + response.status + '] ' + response.type); 480 | } 481 | 482 | return response; 483 | } 484 | 485 | if (DEBUG) { 486 | console.log('[SW]:', 'URL [' + urlString + '] from network'); 487 | } 488 | 489 | if (cacheUrl === urlString) { 490 | (function () { 491 | var responseClone = response.clone(); 492 | var storing = caches.open(CACHE_NAME).then(function (cache) { 493 | return cache.put(urlString, responseClone); 494 | }).then(function () { 495 | console.log('[SW]:', 'Cache asset: ' + urlString); 496 | }); 497 | 498 | event.waitUntil(storing); 499 | })(); 500 | } 501 | 502 | return response; 503 | }); 504 | 505 | return fetching; 506 | }); 507 | } 508 | 509 | function networkFirstResponse(event, urlString, cacheUrl) { 510 | return fetch(event.request).then(function (response) { 511 | if (response.ok) { 512 | if (DEBUG) { 513 | console.log('[SW]:', 'URL [' + urlString + '] from network'); 514 | } 515 | 516 | return response; 517 | } 518 | 519 | // Throw to reach the code in the catch below 520 | throw new Error('Response is not ok'); 521 | }) 522 | // This needs to be in a catch() and not just in the then() above 523 | // cause if your network is down, the fetch() will throw 524 | ['catch'](function () { 525 | if (DEBUG) { 526 | console.log('[SW]:', 'URL [' + urlString + '] from cache if possible'); 527 | } 528 | 529 | return cachesMatch(cacheUrl, CACHE_NAME); 530 | }); 531 | } 532 | 533 | function handleNavigateFallback(fetching) { 534 | return fetching['catch'](function () {}).then(function (response) { 535 | var isOk = response && response.ok; 536 | var isRedirect = response && response.type === 'opaqueredirect'; 537 | 538 | if (isOk || isRedirect && !navigateFallbackForRedirects) { 539 | return response; 540 | } 541 | 542 | if (DEBUG) { 543 | console.log('[SW]:', 'Loading navigation fallback [' + navigateFallbackURL + '] from cache'); 544 | } 545 | 546 | return cachesMatch(navigateFallbackURL, CACHE_NAME); 547 | }); 548 | } 549 | 550 | function mapAssets() { 551 | Object.keys(assets).forEach(function (key) { 552 | assets[key] = assets[key].map(function (path) { 553 | var url = new URL(path, location); 554 | 555 | url.hash = ''; 556 | 557 | if (externals.indexOf(path) === -1) { 558 | url.search = ''; 559 | } 560 | 561 | return url.toString(); 562 | }); 563 | }); 564 | 565 | Object.keys(loadersMap).forEach(function (key) { 566 | loadersMap[key] = loadersMap[key].map(function (path) { 567 | var url = new URL(path, location); 568 | 569 | url.hash = ''; 570 | 571 | if (externals.indexOf(path) === -1) { 572 | url.search = ''; 573 | } 574 | 575 | return url.toString(); 576 | }); 577 | }); 578 | 579 | hashesMap = Object.keys(hashesMap).reduce(function (result, hash) { 580 | var url = new URL(hashesMap[hash], location); 581 | url.search = ''; 582 | url.hash = ''; 583 | 584 | result[hash] = url.toString(); 585 | return result; 586 | }, {}); 587 | 588 | externals = externals.map(function (path) { 589 | var url = new URL(path, location); 590 | url.hash = ''; 591 | 592 | return url.toString(); 593 | }); 594 | } 595 | 596 | function addAllNormalized(cache, requests, options) { 597 | var allowLoaders = options.allowLoaders !== false; 598 | var bustValue = options && options.bust; 599 | var requestInit = options.request || { 600 | credentials: 'omit', 601 | mode: 'cors' 602 | }; 603 | 604 | return Promise.all(requests.map(function (request) { 605 | if (bustValue) { 606 | request = applyCacheBust(request, bustValue); 607 | } 608 | 609 | return fetch(request, requestInit).then(fixRedirectedResponse); 610 | })).then(function (responses) { 611 | if (responses.some(function (response) { 612 | return !response.ok; 613 | })) { 614 | return Promise.reject(new Error('Wrong response status')); 615 | } 616 | 617 | var extracted = []; 618 | var addAll = responses.map(function (response, i) { 619 | if (allowLoaders) { 620 | extracted.push(extractAssetsWithLoaders(requests[i], response)); 621 | } 622 | 623 | return cache.put(requests[i], response); 624 | }); 625 | 626 | if (extracted.length) { 627 | (function () { 628 | var newOptions = copyObject(options); 629 | newOptions.allowLoaders = false; 630 | 631 | var waitAll = addAll; 632 | 633 | addAll = Promise.all(extracted).then(function (all) { 634 | var extractedRequests = [].concat.apply([], all); 635 | 636 | if (requests.length) { 637 | waitAll = waitAll.concat(addAllNormalized(cache, extractedRequests, newOptions)); 638 | } 639 | 640 | return Promise.all(waitAll); 641 | }); 642 | })(); 643 | } else { 644 | addAll = Promise.all(addAll); 645 | } 646 | 647 | return addAll; 648 | }); 649 | } 650 | 651 | function extractAssetsWithLoaders(request, response) { 652 | var all = Object.keys(loadersMap).map(function (key) { 653 | var loader = loadersMap[key]; 654 | 655 | if (loader.indexOf(request) !== -1 && loaders[key]) { 656 | return loaders[key](response.clone()); 657 | } 658 | }).filter(function (a) { 659 | return !!a; 660 | }); 661 | 662 | return Promise.all(all).then(function (all) { 663 | return [].concat.apply([], all); 664 | }); 665 | } 666 | 667 | function matchCacheMap(request) { 668 | var urlString = request.url; 669 | var url = new URL(urlString); 670 | 671 | var requestType = undefined; 672 | 673 | if (request.mode === 'navigate') { 674 | requestType = 'navigate'; 675 | } else if (url.origin === location.origin) { 676 | requestType = 'same-origin'; 677 | } else { 678 | requestType = 'cross-origin'; 679 | } 680 | 681 | for (var i = 0; i < cacheMaps.length; i++) { 682 | var map = cacheMaps[i]; 683 | 684 | if (!map) continue; 685 | if (map.requestTypes && map.requestTypes.indexOf(requestType) === -1) { 686 | continue; 687 | } 688 | 689 | var newString = undefined; 690 | 691 | if (typeof map.match === 'function') { 692 | newString = map.match(url, request); 693 | } else { 694 | newString = urlString.replace(map.match, map.to); 695 | } 696 | 697 | if (newString && newString !== urlString) { 698 | return newString; 699 | } 700 | } 701 | } 702 | } 703 | 704 | function cachesMatch(request, cacheName) { 705 | return caches.match(request, { 706 | cacheName: cacheName 707 | }).then(function (response) { 708 | if (isNotRedirectedResponse()) { 709 | return response; 710 | } 711 | 712 | // Fix already cached redirected responses 713 | return fixRedirectedResponse(response).then(function (fixedResponse) { 714 | return caches.open(cacheName).then(function (cache) { 715 | return cache.put(request, fixedResponse); 716 | }).then(function () { 717 | return fixedResponse; 718 | }); 719 | }); 720 | }) 721 | // Return void if error happened (cache not found) 722 | ['catch'](function () {}); 723 | } 724 | 725 | function applyCacheBust(asset, key) { 726 | var hasQuery = asset.indexOf('?') !== -1; 727 | return asset + (hasQuery ? '&' : '?') + '__uncache=' + encodeURIComponent(key); 728 | } 729 | 730 | function getClientsURLs() { 731 | if (!self.clients) { 732 | return Promise.resolve([]); 733 | } 734 | 735 | return self.clients.matchAll({ 736 | includeUncontrolled: true 737 | }).then(function (clients) { 738 | if (!clients.length) return []; 739 | 740 | var result = []; 741 | 742 | clients.forEach(function (client) { 743 | var url = new URL(client.url); 744 | url.search = ''; 745 | url.hash = ''; 746 | var urlString = url.toString(); 747 | 748 | if (!result.length || result.indexOf(urlString) === -1) { 749 | result.push(urlString); 750 | } 751 | }); 752 | 753 | return result; 754 | }); 755 | } 756 | 757 | function isNavigateRequest(request) { 758 | return request.mode === 'navigate' || request.headers.get('Upgrade-Insecure-Requests') || (request.headers.get('Accept') || '').indexOf('text/html') !== -1; 759 | } 760 | 761 | function isNotRedirectedResponse(response) { 762 | return !response || !response.redirected || !response.ok || response.type === 'opaqueredirect'; 763 | } 764 | 765 | // Based on https://github.com/GoogleChrome/sw-precache/pull/241/files#diff-3ee9060dc7a312c6a822cac63a8c630bR85 766 | function fixRedirectedResponse(response) { 767 | if (isNotRedirectedResponse(response)) { 768 | return Promise.resolve(response); 769 | } 770 | 771 | var body = 'body' in response ? Promise.resolve(response.body) : response.blob(); 772 | 773 | return body.then(function (data) { 774 | return new Response(data, { 775 | headers: response.headers, 776 | status: response.status 777 | }); 778 | }); 779 | } 780 | 781 | function copyObject(original) { 782 | return Object.keys(original).reduce(function (result, key) { 783 | result[key] = original[key]; 784 | return result; 785 | }, {}); 786 | } 787 | 788 | function logGroup(title, assets) { 789 | console.groupCollapsed('[SW]:', title); 790 | 791 | assets.forEach(function (asset) { 792 | console.log('Asset:', asset); 793 | }); 794 | 795 | console.groupEnd(); 796 | } 797 | WebpackServiceWorker(__wpo, { 798 | loaders: {}, 799 | cacheMaps: [], 800 | }); 801 | module.exports = __webpack_require__(/*! ./sw.js */ "jgIZ") 802 | 803 | 804 | /***/ }), 805 | 806 | /***/ "jgIZ": 807 | /*!*****************************!*\ 808 | !*** ./web/assets/js/sw.js ***! 809 | \*****************************/ 810 | /*! no static exports found */ 811 | /*! all exports used */ 812 | /***/ (function(module, exports) { 813 | 814 | self.addEventListener("install", function () { 815 | self.skipWaiting(); 816 | }); 817 | 818 | /***/ }) 819 | 820 | /******/ }); -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var Encore = require('@symfony/webpack-encore'); 3 | // require offline-plugin 4 | var OfflinePlugin = require('offline-plugin'); 5 | // manifest plugin 6 | var ManifestPlugin = require('webpack-manifest-plugin'); 7 | 8 | var commonChunk = require("webpack/lib/optimize/CommonsChunkPlugin"); 9 | 10 | Encore 11 | // directory where all compiled assets will be stored 12 | .setOutputPath('web/build/') 13 | // what's the public path to this directory (relative to your project's document root dir) 14 | .setPublicPath('/build') 15 | // empty the outputPath dir before each build 16 | .cleanupOutputBeforeBuild() 17 | // will output as web/build/vendor.js , main.js , sw.js 18 | .addEntry('vendor', './web/assets/js/vendor.js') 19 | .addEntry('vue', './web/assets/js/vue.js') 20 | .addEntry("sw", './web/assets/js/sw.js') 21 | // will output as web/build/style.css 22 | .addStyleEntry('style', './web/assets/scss/style.scss') 23 | // allow sass/scss files to be processed 24 | .enableSassLoader() 25 | .enableSourceMaps(!Encore.isProduction()) 26 | // create hashed filenames (e.g. app.abc123.css) 27 | //.enableVersioning() 28 | .enableVueLoader(); 29 | 30 | 31 | // fetch webpack config, then modify it! 32 | var config = Encore.getWebpackConfig(); 33 | config.plugins.push(new commonChunk({ 34 | name: 'chunck', 35 | async: true 36 | })); 37 | config.plugins.push(new ManifestPlugin({ 38 | fileName: 'manifest.json', 39 | basePath: '/web/build/', 40 | seed: { 41 | "short_name": "SymfonyVue", 42 | "name": "SymfonyVue", 43 | "start_url": "/", 44 | "icons": [{ 45 | "src": "/build/images/256.png", 46 | "sizes": "256x256", 47 | "type": "image/png" 48 | }, 49 | { 50 | "src": "/build/images/512.png", 51 | "sizes": "512x512", 52 | "type": "image/png" 53 | } 54 | ], 55 | "background_color": "#FAFAFA", 56 | "theme_color": "#e10b0b", 57 | "display": "standalone", 58 | "orientation": "portrait", 59 | "gcm_sender_id": "314804067424" 60 | } 61 | })); 62 | // push offline-plugin it must be the last one to use 63 | config.plugins.push(new OfflinePlugin({ 64 | "strategy": "changed", 65 | "responseStrategy": "cache-first", 66 | "publicPath": "/build/", 67 | "caches": { 68 | // offline plugin doesn't know about build folder 69 | // if I added build in it , it will show something like : OfflinePlugin: Cache pattern [build/images/*] did not match any assets 70 | "main": [ 71 | '*.json', 72 | '*.css', 73 | '*.js', 74 | 'img/*' 75 | ] 76 | }, 77 | "ServiceWorker": { 78 | "events": !Encore.isProduction(), 79 | "entry": "./web/assets/js/sw.js", 80 | "cacheName": "SymfonyVue", 81 | "navigateFallbackURL": '/', 82 | "minify": !Encore.isProduction(), 83 | "output": "./../sw.js", 84 | "scope": "/" 85 | }, 86 | "AppCache": null 87 | })); 88 | 89 | // export the final and modified configuration 90 | module.exports = config; --------------------------------------------------------------------------------