├── .editorconfig ├── .env ├── .gitignore ├── LICENSE.md ├── README.md ├── apiary.apib ├── app.json ├── app ├── .htaccess ├── AppCache.php ├── AppKernel.php ├── Resources │ ├── FOSUserBundle │ │ └── views │ │ │ └── Security │ │ │ └── login.html.twig │ ├── assets │ │ ├── js │ │ │ ├── clipboard.min.js │ │ │ └── layout.js │ │ └── less │ │ │ └── style.less │ ├── translations │ │ └── messages.en.yml │ └── views │ │ ├── base.html.twig │ │ └── default │ │ └── index.html.twig ├── autoload.php └── config │ ├── config.yml │ ├── config_dev.yml │ ├── config_prod.yml │ ├── config_test.yml │ ├── parameters.yml.dist │ ├── routing.yml │ ├── routing_dev.yml │ ├── security.yml │ └── services.yml ├── bin ├── console └── symfony_requirements ├── composer.json ├── composer.lock ├── etc └── docker │ ├── docker-compose.yml │ └── nginx │ └── default.conf ├── gulpfile.js ├── package.json ├── phpunit.xml.dist ├── src ├── .htaccess └── AppBundle │ ├── AppBundle.php │ ├── Controller │ ├── AdminController.php │ ├── HomeController.php │ ├── LinksController.php │ └── RedirectController.php │ ├── DataFixtures │ └── ORM │ │ ├── LoadApiKeyData.php │ │ ├── LoadLinkData.php │ │ └── LoadUserData.php │ ├── Entity │ ├── ApiKey.php │ ├── Link.php │ ├── User.php │ └── Visit.php │ ├── Event │ └── LinkVisitEvent.php │ ├── EventListener │ └── LinkCodeGenerator.php │ ├── EventSubscriber │ └── LinkVisitEventSubscriber.php │ ├── Form │ └── LinkType.php │ ├── Repository │ ├── ApiKeyRepository.php │ ├── LinkRepository.php │ ├── UserRepository.php │ └── VisitRepository.php │ ├── Resources │ ├── config │ │ ├── routes.yml │ │ └── services.yml │ ├── docs │ │ └── docker.md │ ├── translations │ │ └── messages.en.yml │ └── views │ │ ├── Home │ │ └── home.html.twig │ │ ├── Layout │ │ └── _navigation.html.twig │ │ └── layout.html.twig │ ├── Security │ ├── ApiKeyAuthenticator.php │ └── ApiKeyUserProvider.php │ └── Service │ └── CodeGeneratorService.php ├── tests └── AppBundle │ └── Controller │ └── LinksControllerTest.php ├── var ├── SymfonyRequirements.php ├── cache │ └── .gitkeep ├── logs │ └── .gitkeep └── sessions │ └── .gitkeep ├── web ├── .htaccess ├── app.php ├── app_dev.php ├── apple-touch-icon.png ├── config.php ├── css │ └── style.css ├── favicon.ico ├── img │ ├── background.jpg │ └── background@2x.jpg ├── js │ └── scripts.js └── robots.txt └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = lf 3 | insert_final_newline = true 4 | 5 | [*.{js,css,html.twig,yml,json,xml}] 6 | indent_size = 2 7 | indent_style = space 8 | 9 | [*.{php}] 10 | indent_size = space 11 | indent_size = 4 12 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | COMPOSE_FILE=etc/docker/docker-compose.yml 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /app/config/parameters.yml 2 | /build/ 3 | /phpunit.xml 4 | /var/* 5 | !/var/cache 6 | /var/cache/* 7 | !var/cache/.gitkeep 8 | !/var/logs 9 | /var/logs/* 10 | !var/logs/.gitkeep 11 | !/var/sessions 12 | /var/sessions/* 13 | !var/sessions/.gitkeep 14 | !var/SymfonyRequirements.php 15 | /vendor/ 16 | /web/bundles/ 17 | vendor 18 | _vendor/ 19 | app/bootstrap.php.cache 20 | node_modules -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Kevin Vandenborne 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Purl 2 | ==== 3 | 4 | Purl (Petite URL) is an open source project with the goal of providing you with your own private URL shortener! 5 | 6 | ![](https://goo.gl/HstQ5n) 7 | 8 | This project was my first symfony project, keep in mind that there are a lot of improvements that could be made. The point of this project was to **learn** symfony, and I happened to need a URL shortener. 9 | 10 | You are welcome to send pull requests if you like! 11 | 12 | ## Development 13 | 14 | [Check the docker guide](https://github.com/veloxy/purl/tree/master/src/AppBundle/Resources/docs/docker.md) if you want to use the docker images, if you use your own workflow, continue reading! 15 | 16 | ### Install 17 | 18 | Install the required packages. 19 | 20 | ``` 21 | composer install 22 | ``` 23 | 24 | Create the database scheme, add an admin, install assets: 25 | 26 | ```shell 27 | bin/console doctrine:schema:create 28 | bin/console fos:user:create admin test@example.com admin 29 | bin/console fos:user:promote admin ROLE_ADMIN 30 | bin/console assets:install 31 | ``` 32 | 33 | You will be asked to enter some parameters, adjust them to your own needs. 34 | 35 | Once done, you should be ready to go. You can access the admin on /admin and log in using your previously created admin user. 36 | 37 | ![](https://goo.gl/uhNULT) 38 | 39 | ### Testing 40 | 41 | 42 | Create a database named `test` and make sure the `dev` mysql user has access to it. Then create the schema for the test environment: 43 | 44 | ```shell 45 | bin/console doctrine:schema:create -e test 46 | ``` 47 | 48 | Once the database is set up, you simply run `phpunit`: 49 | 50 | ```shell 51 | vendor/bin/phpunit 52 | ``` 53 | 54 | ## REST API 55 | 56 | REST API docs can be found [here](http://docs.purl.apiary.io/#) 57 | 58 | ## Credits 59 | 60 | - Background image by Roman Pohorecki ([source](https://www.pexels.com/photo/mountains-landscape-winter-snow-15382/)) 61 | -------------------------------------------------------------------------------- /apiary.apib: -------------------------------------------------------------------------------- 1 | FORMAT: A1 2 | HOST: http://purl.docker 3 | 4 | # Purl 5 | 6 | Purl (Petite URL) is an open source project with the goal of providing you with your own private URL shortener! 7 | 8 | ## Group Link 9 | ## List [/api/v1/links.json?apiKey={apiKey}] 10 | 11 | + Parameters 12 | + apiKey: `7f74c3f0-8116-4c82-8dae-a813ef57852d` (uuid, required) - API Key 13 | 14 | ### Get all links [GET] 15 | 16 | Returns a list of links connected to the user that the API key belongs to. 17 | 18 | + Response 200 (application/json) 19 | 20 | { 21 | "links":[ 22 | { 23 | "id": 14, 24 | "url": "http:\/\/example.com", 25 | "code": "LD1ZB8B" 26 | } 27 | ] 28 | } 29 | 30 | 31 | ## Detail [/api/v1/link/{code}.json?apiKey={apiKey}] 32 | 33 | + Parameters 34 | + apiKey: `7f74c3f0-8116-4c82-8dae-a813ef57852d` (uuid, required) - API Key 35 | + code: `LD1ZB8B` (string, required) - Link code 36 | 37 | ### Get link detail [GET] 38 | 39 | Returns data for specified link code. 40 | Note: Data is only returned if the link belongs to the API user. 41 | 42 | + Response 200 (application/json) 43 | 44 | { 45 | "link": { 46 | "id": 14, 47 | "url": "http:\/\/example.com", 48 | "code": "LD1ZB8B" 49 | } 50 | } 51 | 52 | ## New [/api/v1/link.json?apiKey={apiKey}] 53 | 54 | + Parameters 55 | + apiKey: `7f74c3f0-8116-4c82-8dae-a813ef57852d` (uuid, required) - API Key 56 | 57 | ### Create a new link [POST] 58 | 59 | Adds a new link and attaches it for the user that belongs to the given API key. 60 | 61 | + Request (application/json) 62 | 63 | { 64 | "url": "http://github.com" 65 | } 66 | 67 | + Response 201 (application/json) 68 | 69 | { 70 | "link": { 71 | "id": 16, 72 | "url": "http:\/\/github.com", 73 | "code": "dedGv4P" 74 | }, 75 | "url":"http:\/\/purl.docker\/dedGv4P" 76 | } -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Purl", 3 | "description": "Purl (Petite URL) is an open source project with the goal of providing you with your own private URL shortener!", 4 | "repository": "https://github.com/veloxy/purl", 5 | "keywords": ["symfony", "url-shortenr", "php"] 6 | } -------------------------------------------------------------------------------- /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)) { 26 | $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle(); 27 | $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle(); 28 | $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle(); 29 | $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); 30 | $bundles[] = new Liip\FunctionalTestBundle\LiipFunctionalTestBundle(); 31 | } 32 | 33 | return $bundles; 34 | } 35 | 36 | public function getRootDir() 37 | { 38 | return __DIR__; 39 | } 40 | 41 | public function getCacheDir() 42 | { 43 | return '/tmpfs/' . $this->getEnvironment(); 44 | } 45 | 46 | public function getLogDir() 47 | { 48 | return '/tmpfs/' . $this->getEnvironment() . '/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/FOSUserBundle/views/Security/login.html.twig: -------------------------------------------------------------------------------- 1 | {# app/Resources/FOSUserBundle/views/Security/login.html.twig #} 2 | {# May change depending on your app #} 3 | {% extends 'EasyAdminBundle:default:layout.html.twig' %} 4 | 5 | {# This removes totally the navigation #} 6 | {% block sidebar '' %} 7 | 8 | {% block page_title %} 9 | {{ 'layout.login' | trans({}, 'FOSUserBundle') }} 10 | {% endblock %} 11 | 12 | {% block wrapper %} 13 |
14 | {% for type, messages in app.session.flashBag.all %} 15 | {% for message in messages %} 16 |
17 | {{ message|trans({}, 'FOSUserBundle') }} 18 |
19 | {% endfor %} 20 | {% endfor %} 21 | 22 | {% block fos_user_content %} 23 | {% if error %} 24 |
{{ error.messageKey|trans(error.messageData, 'security') }}
25 | {% endif %} 26 |
27 |
28 | 29 | 30 |
31 | 34 | 35 |
36 | 37 |
38 |
39 | 40 |
41 | 42 | 43 |
44 | 45 |
46 |
47 | 48 |
49 | 53 |
54 | 55 |
56 |
57 | 58 |
59 |
60 | 61 |
62 |
63 | {% endblock fos_user_content %} 64 |
65 | {% endblock %} -------------------------------------------------------------------------------- /app/Resources/assets/js/clipboard.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * clipboard.js v1.5.9 3 | * https://zenorocha.github.io/clipboard.js 4 | * 5 | * Licensed MIT © Zeno Rocha 6 | */ 7 | !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Clipboard=t()}}(function(){var t,e,n;return function t(e,n,o){function r(c,s){if(!n[c]){if(!e[c]){var a="function"==typeof require&&require;if(!s&&a)return a(c,!0);if(i)return i(c,!0);var l=new Error("Cannot find module '"+c+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[c]={exports:{}};e[c][0].call(u.exports,function(t){var n=e[c][1][t];return r(n?n:t)},u,u.exports,t,e,n,o)}return n[c].exports}for(var i="function"==typeof require&&require,c=0;co;o++)n[o].fn.apply(n[o].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),o=n[t],r=[];if(o&&e)for(var i=0,c=o.length;c>i;i++)o[i].fn!==e&&o[i].fn._!==e&&r.push(o[i]);return r.length?n[t]=r:delete n[t],this}},e.exports=o},{}],8:[function(e,n,o){!function(r,i){if("function"==typeof t&&t.amd)t(["module","select"],i);else if("undefined"!=typeof o)i(n,e("select"));else{var c={exports:{}};i(c,r.select),r.clipboardAction=c.exports}}(this,function(t,e){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=n(e),i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},c=function(){function t(t,e){for(var n=0;n 2 | 3 | 4 | 5 | {% block title %}Welcome!{% endblock %} 6 | {% block stylesheets %}{% endblock %} 7 | 8 | 9 | 10 | {% block body %}{% endblock %} 11 | {% block javascripts %}{% endblock %} 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/Resources/views/default/index.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'base.html.twig' %} 2 | 3 | {% block body %} 4 |
5 |
6 |
7 |

Welcome to Symfony {{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}

8 |
9 | 10 |
11 |

12 | 13 | 14 | Your application is now ready. You can start working on it at: 15 | {{ base_dir }}/ 16 |

17 |
18 | 19 | 44 | 45 |
46 |
47 | {% endblock %} 48 | 49 | {% block stylesheets %} 50 | 76 | {% endblock %} 77 | -------------------------------------------------------------------------------- /app/autoload.php: -------------------------------------------------------------------------------- 1 | getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev'); 21 | $debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; 22 | 23 | if ($debug) { 24 | Debug::enable(); 25 | } 26 | 27 | $kernel = new AppKernel($env, $debug); 28 | $application = new Application($kernel); 29 | $application->run($input); 30 | -------------------------------------------------------------------------------- /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": "kevinvandenborne/purl", 3 | "license": "proprietary", 4 | "type": "project", 5 | "autoload": { 6 | "psr-4": { 7 | "": "src/" 8 | }, 9 | "classmap": [ 10 | "app/AppKernel.php", 11 | "app/AppCache.php" 12 | ] 13 | }, 14 | "autoload-dev": { 15 | "psr-4": { 16 | "Tests\\": "tests/" 17 | } 18 | }, 19 | "require": { 20 | "php": ">=5.5.9", 21 | "symfony/symfony": "3.0.*", 22 | "doctrine/orm": "^2.5", 23 | "doctrine/doctrine-bundle": "^1.6", 24 | "doctrine/doctrine-cache-bundle": "^1.2", 25 | "symfony/swiftmailer-bundle": "^2.3", 26 | "symfony/monolog-bundle": "^2.8", 27 | "sensio/distribution-bundle": "^5.0", 28 | "sensio/framework-extra-bundle": "^3.0.2", 29 | "incenteev/composer-parameter-handler": "^2.0", 30 | "javiereguiluz/easyadmin-bundle": "^1.12", 31 | "friendsofsymfony/user-bundle": "~2.0@dev", 32 | "friendsofsymfony/rest-bundle": "1.7.8", 33 | "jms/serializer-bundle": "^1.1", 34 | "ramsey/uuid": "^3.3", 35 | "hashids/hashids": "^1.0" 36 | }, 37 | "require-dev": { 38 | "sensio/generator-bundle": "^3.0", 39 | "symfony/phpunit-bridge": "^3.0", 40 | "liip/functional-test-bundle": "^1.5", 41 | "phpunit/phpunit": "^5.2", 42 | "doctrine/doctrine-fixtures-bundle": "^2.3" 43 | }, 44 | "scripts": { 45 | "post-install-cmd": [ 46 | "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", 47 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", 48 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", 49 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", 50 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", 51 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" 52 | ], 53 | "post-update-cmd": [ 54 | "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", 55 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", 56 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", 57 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", 58 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", 59 | "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" 60 | ] 61 | }, 62 | "config": { 63 | "platform": { 64 | "php": "7.0" 65 | } 66 | }, 67 | "extra": { 68 | "symfony-app-dir": "app", 69 | "symfony-bin-dir": "bin", 70 | "symfony-var-dir": "var", 71 | "symfony-web-dir": "web", 72 | "symfony-tests-dir": "tests", 73 | "symfony-assets-install": "relative", 74 | "incenteev-parameters": { 75 | "file": "app/config/parameters.yml" 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /etc/docker/docker-compose.yml: -------------------------------------------------------------------------------- 1 | data: 2 | image: busybox 3 | container_name: purl_data 4 | volumes: 5 | - ../../:/var/www/purl 6 | - /vendor 7 | - ~/.composer:/root/.composer 8 | - ~/.ssh/id_rsa:/root/.ssh/id_rsa:ro 9 | - /tmpfs 10 | tty: true 11 | 12 | nginx: 13 | image: nginx 14 | container_name: purl_nginx 15 | links: 16 | - php 17 | volumes_from: 18 | - data 19 | volumes: 20 | - ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro 21 | environment: 22 | DNSDOCK_ALIAS: purl.docker 23 | 24 | mysql: 25 | image: mariadb 26 | container_name: purl_mysql 27 | environment: 28 | MYSQL_ROOT_PASSWORD: root 29 | MYSQL_DATABASE: purl 30 | MYSQL_USER: dev 31 | MYSQL_PASSWORD: dev 32 | DNSDOCK_ALIAS: mysql.purl.docker 33 | 34 | php: 35 | image: yappabe/php:7.0 36 | container_name: purl_php 37 | working_dir: /var/www/purl 38 | volumes_from: 39 | - data 40 | links: 41 | - mysql 42 | 43 | 44 | -------------------------------------------------------------------------------- /etc/docker/nginx/default.conf: -------------------------------------------------------------------------------- 1 | upstream php-upstream { 2 | server php:9000; 3 | } 4 | 5 | server { 6 | listen 80; 7 | 8 | root /var/www/purl/web; 9 | server_name purl.docker; 10 | server_tokens on; 11 | 12 | access_log /var/log/nginx/access.log; 13 | error_log /var/log/nginx/error.log; 14 | 15 | client_max_body_size 200M; 16 | 17 | index app_dev.php; 18 | 19 | location / { 20 | try_files $uri $uri/ /app_dev.php$is_args$args; 21 | } 22 | 23 | location ~ \.php$ { 24 | fastcgi_pass php-upstream; 25 | fastcgi_param SERVER_NAME $host; 26 | fastcgi_split_path_info ^(.+\.php)(/.*)$; 27 | 28 | fastcgi_param QUERY_STRING $query_string; 29 | fastcgi_param REQUEST_METHOD $request_method; 30 | fastcgi_param CONTENT_TYPE $content_type; 31 | fastcgi_param CONTENT_LENGTH $content_length; 32 | 33 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 34 | fastcgi_param PATH_INFO $fastcgi_script_name; 35 | 36 | fastcgi_param SCRIPT_NAME $fastcgi_script_name; 37 | fastcgi_param REQUEST_URI $request_uri; 38 | fastcgi_param DOCUMENT_URI $document_uri; 39 | fastcgi_param /var/www/app/web $document_root; 40 | fastcgi_param SERVER_PROTOCOL $server_protocol; 41 | 42 | fastcgi_param GATEWAY_INTERFACE CGI/1.1; 43 | fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 44 | 45 | fastcgi_param REMOTE_ADDR $remote_addr; 46 | fastcgi_param REMOTE_PORT $remote_port; 47 | fastcgi_param SERVER_ADDR $server_addr; 48 | fastcgi_param SERVER_PORT $server_port; 49 | fastcgi_param SERVER_NAME $server_name; 50 | 51 | fastcgi_param HTTPS $https; 52 | 53 | # PHP only, required if PHP was built with --enable-force-cgi-redirect 54 | fastcgi_param REDIRECT_STATUS 200; 55 | 56 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 57 | fastcgi_param HTTPS off; 58 | fastcgi_read_timeout 120; 59 | } 60 | } -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var gutil = require('gulp-util'); 3 | var concat = require('gulp-concat'); 4 | var uglify = require('gulp-uglify'); 5 | var sourcemaps = require('gulp-sourcemaps'); 6 | var less = require('gulp-less'); 7 | var cleanCSS = require('gulp-clean-css'); 8 | 9 | gulp.task('default', ['scripts']); 10 | 11 | var src = 'app/Resources/assets'; 12 | 13 | // Concatenate & Minify JS 14 | gulp.task('scripts', function () { 15 | return gulp.src(src + '/js/*.js') 16 | .pipe(sourcemaps.init()) 17 | .pipe(concat('scripts.js')) 18 | .pipe(gutil.env.type === 'prod' ? uglify() : gutil.noop()) 19 | .pipe(sourcemaps.write()) 20 | .pipe(gulp.dest('web/js')); 21 | }); 22 | 23 | // Compile less. 24 | gulp.task('less', function () { 25 | return gulp.src(src + '/less/style.less') 26 | .pipe(less()) 27 | .pipe(cleanCSS({compatibility: 'ie8'})) 28 | .pipe(gulp.dest('web/css')); 29 | }); 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "purl", 3 | "version": "1.0.0", 4 | "description": "Purl (Petite URL) is an open source project with the goal of providing you with your own private URL shortener!", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "test": "echo \"Error: no test specified\" && exit 1" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/veloxy/purl.git" 15 | }, 16 | "keywords": [ 17 | "symfony", 18 | "url-shortenr", 19 | "php" 20 | ], 21 | "license": "ISC", 22 | "bugs": { 23 | "url": "https://github.com/veloxy/purl/issues" 24 | }, 25 | "homepage": "https://github.com/veloxy/purl#readme", 26 | "devDependencies": { 27 | "gulp": "^3.9.1", 28 | "gulp-clean-css": "^2.0.13", 29 | "gulp-concat": "^2.6.0", 30 | "gulp-less": "^3.1.0", 31 | "gulp-sourcemaps": "^1.6.0", 32 | "gulp-uglify": "^2.0.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /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 | get('fos_user.user_manager')->createUser(); 18 | } 19 | 20 | public function prePersistUserEntity($user) 21 | { 22 | $this->get('fos_user.user_manager')->updateUser($user, false); 23 | } 24 | 25 | public function preUpdateUserEntity($user) 26 | { 27 | $this->get('fos_user.user_manager')->updateUser($user, false); 28 | } 29 | 30 | /** 31 | * @Route(path = "/users/generate_api_key", name = "generate_api_key") 32 | * @Security("has_role('ROLE_ADMIN')") 33 | * @param Request $request 34 | * @return \Symfony\Component\HttpFoundation\RedirectResponse 35 | */ 36 | public function generateApiKeyAction(Request $request) 37 | { 38 | $user = $this->getDoctrine()->getRepository('AppBundle:User')->findOneBy([ 39 | 'id' => $request->query->get('id') 40 | ]); 41 | 42 | $apiKey = new ApiKey(); 43 | $apiKey->setUser($user) 44 | ->setApiKey(Uuid::uuid1()); 45 | 46 | $em = $this->getDoctrine()->getManager(); 47 | $em->persist($apiKey); 48 | $em->flush(); 49 | 50 | return $this->redirectToRoute('easyadmin', array( 51 | 'action' => 'show', 52 | 'entity' => 'ApiKey', 53 | 'id' => $apiKey->getId() 54 | )); 55 | } 56 | } -------------------------------------------------------------------------------- /src/AppBundle/Controller/HomeController.php: -------------------------------------------------------------------------------- 1 | createForm(LinkType::class, $link); 25 | 26 | $form->handleRequest($request); 27 | 28 | if ($form->isSubmitted() && $form->isValid()) { 29 | $em = $this->getDoctrine()->getManager(); 30 | $em->persist($link); 31 | $em->flush(); 32 | } 33 | 34 | return [ 35 | 'link' => $link, 36 | 'form' => $form->createView(), 37 | ]; 38 | } 39 | } -------------------------------------------------------------------------------- /src/AppBundle/Controller/LinksController.php: -------------------------------------------------------------------------------- 1 | get('security.token_storage')->getToken()->getUser(); 21 | $links = $this->getDoctrine()->getRepository('AppBundle:Link')->getAllLinksByUserId($user->getId()); 22 | return ['links' => $links]; 23 | } 24 | 25 | /** 26 | * @Route("/v1/link/{code}.{_format}", methods={"GET"}) 27 | * @View() 28 | * @param string $code 29 | * @return array 30 | * @internal param Link $link 31 | */ 32 | public function getLinkAction(string $code) : array 33 | { 34 | $link = $this->getDoctrine()->getRepository('AppBundle:Link')->getLink($code); 35 | 36 | return [ 37 | 'link' => $link 38 | ]; 39 | } 40 | 41 | /** 42 | * @Route("/v1/link.{_format}", methods={"POST"}) 43 | * @View() 44 | * @param Request $request 45 | * @return array 46 | */ 47 | public function postLinkAction(Request $request) 48 | { 49 | $link = new Link(); 50 | $link->setUser($this->get('security.token_storage')->getToken()->getUser()); 51 | 52 | $form = $this->get('form.factory')->createNamed(null, LinkType::class, $link); 53 | $form->handleRequest($request); 54 | 55 | if (!$form->isValid()) { 56 | return ['form' => $form]; 57 | } 58 | 59 | $em = $this->getDoctrine()->getManager(); 60 | $em->persist($link); 61 | $em->flush(); 62 | 63 | $linkResponse = $this->getDoctrine()->getRepository('AppBundle:Link')->getLink($link->getCode()); 64 | 65 | return [ 66 | 'link' => $linkResponse, 67 | 'url' => sprintf('%s/%s', $this->getParameter('host'), $link->getCode()), 68 | ]; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/AppBundle/Controller/RedirectController.php: -------------------------------------------------------------------------------- 1 | getDoctrine()->getRepository('AppBundle:Link')->findOneBy([ 24 | 'code' => $code 25 | ]); 26 | 27 | $event = new LinkVisitEvent($link); 28 | $dispatcher = $this->get('event_dispatcher'); 29 | $dispatcher->dispatch(LinkVisitEvent::NAME, $event); 30 | 31 | return $this->redirect($link->getUrl(), 301); 32 | } 33 | } -------------------------------------------------------------------------------- /src/AppBundle/DataFixtures/ORM/LoadApiKeyData.php: -------------------------------------------------------------------------------- 1 | setUser($this->getReference('user')) 24 | ->setApiKey('test-key'); 25 | 26 | $manager->persist($apiKey); 27 | $manager->flush(); 28 | } 29 | 30 | public function getOrder() 31 | { 32 | return 20; 33 | } 34 | } -------------------------------------------------------------------------------- /src/AppBundle/DataFixtures/ORM/LoadLinkData.php: -------------------------------------------------------------------------------- 1 | setClicks(0) 17 | ->setCode('test') 18 | ->setUrl('http://google.be') 19 | ->setUser($this->getReference('user')); 20 | 21 | $manager->persist($link); 22 | $manager->flush(); 23 | } 24 | 25 | public function getOrder() 26 | { 27 | return 30; 28 | } 29 | } -------------------------------------------------------------------------------- /src/AppBundle/DataFixtures/ORM/LoadUserData.php: -------------------------------------------------------------------------------- 1 | setUsername('api-user') 23 | ->setPassword('test') 24 | ->setEmail('test@test.com'); 25 | 26 | $manager->persist($user); 27 | $manager->flush(); 28 | 29 | $this->setReference('user', $user); 30 | } 31 | 32 | public function getOrder() 33 | { 34 | return 10; 35 | } 36 | } -------------------------------------------------------------------------------- /src/AppBundle/Entity/ApiKey.php: -------------------------------------------------------------------------------- 1 | id; 45 | } 46 | 47 | /** 48 | * @param int $id 49 | * @return ApiKey 50 | */ 51 | public function setId($id) 52 | { 53 | $this->id = $id; 54 | return $this; 55 | } 56 | 57 | /** 58 | * @return User 59 | */ 60 | public function getUser() 61 | { 62 | return $this->user; 63 | } 64 | 65 | /** 66 | * @param User $user 67 | * @return ApiKey 68 | */ 69 | public function setUser($user) 70 | { 71 | $this->user = $user; 72 | return $this; 73 | } 74 | 75 | /** 76 | * @return string 77 | */ 78 | public function getApiKey() 79 | { 80 | return $this->apiKey; 81 | } 82 | 83 | /** 84 | * @param string $apiKey 85 | * @return ApiKey 86 | */ 87 | public function setApiKey($apiKey) 88 | { 89 | $this->apiKey = $apiKey; 90 | return $this; 91 | } 92 | } -------------------------------------------------------------------------------- /src/AppBundle/Entity/Link.php: -------------------------------------------------------------------------------- 1 | visit; 62 | } 63 | 64 | /** 65 | * @param Visit $visit 66 | * @return Link 67 | */ 68 | public function setVisit($visit) 69 | { 70 | $this->visit = $visit; 71 | return $this; 72 | } 73 | 74 | /** 75 | * @return User 76 | */ 77 | public function getUser() 78 | { 79 | return $this->user; 80 | } 81 | 82 | /** 83 | * @param User $user 84 | * @return Link 85 | */ 86 | public function setUser($user) 87 | { 88 | $this->user = $user; 89 | return $this; 90 | } 91 | 92 | /** 93 | * Get id 94 | * 95 | * @return int 96 | */ 97 | public function getId() 98 | { 99 | return $this->id; 100 | } 101 | 102 | /** 103 | * Set url 104 | * 105 | * @param string $url 106 | * 107 | * @return Link 108 | */ 109 | public function setUrl($url) 110 | { 111 | $this->url = $url; 112 | 113 | return $this; 114 | } 115 | 116 | /** 117 | * Get url 118 | * 119 | * @return string 120 | */ 121 | public function getUrl() 122 | { 123 | return $this->url; 124 | } 125 | 126 | /** 127 | * Set code 128 | * 129 | * @param string $code 130 | * 131 | * @return Link 132 | */ 133 | public function setCode($code) 134 | { 135 | $this->code = $code; 136 | 137 | return $this; 138 | } 139 | 140 | /** 141 | * Get code 142 | * 143 | * @return string 144 | */ 145 | public function getCode() 146 | { 147 | return $this->code; 148 | } 149 | } 150 | 151 | -------------------------------------------------------------------------------- /src/AppBundle/Entity/User.php: -------------------------------------------------------------------------------- 1 | apiKeys; 38 | } 39 | 40 | /** 41 | * @param mixed $apiKeys 42 | * @return User 43 | */ 44 | public function setApiKeys($apiKeys) 45 | { 46 | $this->apiKeys = $apiKeys; 47 | return $this; 48 | } 49 | 50 | /** 51 | * @return int 52 | */ 53 | public function getId() 54 | { 55 | return $this->id; 56 | } 57 | 58 | /** 59 | * @param int $id 60 | * @return User 61 | */ 62 | public function setId($id) 63 | { 64 | $this->id = $id; 65 | return $this; 66 | } 67 | } -------------------------------------------------------------------------------- /src/AppBundle/Entity/Visit.php: -------------------------------------------------------------------------------- 1 | id; 51 | } 52 | 53 | /** 54 | * @param int $id 55 | * @return Visit 56 | */ 57 | public function setId($id) 58 | { 59 | $this->id = $id; 60 | return $this; 61 | } 62 | 63 | /** 64 | * @return Link 65 | */ 66 | public function getLink() 67 | { 68 | return $this->link; 69 | } 70 | 71 | /** 72 | * @param Link $link 73 | * @return Visit 74 | */ 75 | public function setLink($link) 76 | { 77 | $this->link = $link; 78 | return $this; 79 | } 80 | 81 | /** 82 | * @return datetime 83 | */ 84 | public function getVisitedAt() 85 | { 86 | return $this->visitedAt; 87 | } 88 | 89 | /** 90 | * @param datetime $visitedAt 91 | * @return Visit 92 | */ 93 | public function setVisitedAt($visitedAt) 94 | { 95 | $this->visitedAt = $visitedAt; 96 | return $this; 97 | } 98 | 99 | /** 100 | * @return string 101 | */ 102 | public function getIpAddress() 103 | { 104 | return $this->ipAddress; 105 | } 106 | 107 | /** 108 | * @param string $ipAddress 109 | * @return Visit 110 | */ 111 | public function setIpAddress($ipAddress) 112 | { 113 | $this->ipAddress = $ipAddress; 114 | return $this; 115 | } 116 | } -------------------------------------------------------------------------------- /src/AppBundle/Event/LinkVisitEvent.php: -------------------------------------------------------------------------------- 1 | link = $link; 27 | } 28 | 29 | public function getLink() 30 | { 31 | return $this->link; 32 | } 33 | } -------------------------------------------------------------------------------- /src/AppBundle/EventListener/LinkCodeGenerator.php: -------------------------------------------------------------------------------- 1 | codeGeneratorService = $codeGeneratorService; 25 | } 26 | 27 | public function prePersist(LifecycleEventArgs $args) 28 | { 29 | $entity = $args->getEntity(); 30 | 31 | if (!$entity instanceof Link) { 32 | return; 33 | } 34 | 35 | if (!$entity->getCode()) { 36 | $code = $this->codeGeneratorService->generateCode(); 37 | $entity->setCode($code); 38 | } 39 | } 40 | 41 | /** 42 | * Returns an array of events this subscriber wants to listen to. 43 | * 44 | * @return array 45 | */ 46 | public function getSubscribedEvents() 47 | { 48 | return [ 49 | 'prePersist', 50 | ]; 51 | } 52 | } -------------------------------------------------------------------------------- /src/AppBundle/EventSubscriber/LinkVisitEventSubscriber.php: -------------------------------------------------------------------------------- 1 | em = $em; 31 | $this->requestStack = $requestStack; 32 | } 33 | 34 | /** 35 | * @param $event LinkVisitEvent 36 | */ 37 | public function onLinkVisit(LinkVisitEvent $event) 38 | { 39 | 40 | $visit = new Visit(); 41 | $visit->setLink($event->getLink()) 42 | ->setIpAddress($this->requestStack->getCurrentRequest()->getClientIp()) 43 | ->setVisitedAt(new \DateTime()); 44 | 45 | $this->em->persist($visit); 46 | $this->em->flush(); 47 | } 48 | 49 | /** 50 | * Returns an array of event names this subscriber wants to listen to. 51 | * 52 | * The array keys are event names and the value can be: 53 | * 54 | * * The method name to call (priority defaults to 0) 55 | * * An array composed of the method name to call and the priority 56 | * * An array of arrays composed of the method names to call and respective 57 | * priorities, or 0 if unset 58 | * 59 | * For instance: 60 | * 61 | * * array('eventName' => 'methodName') 62 | * * array('eventName' => array('methodName', $priority)) 63 | * * array('eventName' => array(array('methodName1', $priority), array('methodName2'))) 64 | * 65 | * @return array The event names to listen to 66 | */ 67 | public static function getSubscribedEvents() 68 | { 69 | return [ 70 | LinkVisitEvent::NAME => 'onLinkVisit', 71 | ]; 72 | } 73 | } -------------------------------------------------------------------------------- /src/AppBundle/Form/LinkType.php: -------------------------------------------------------------------------------- 1 | add('url', TextType::class); 14 | } 15 | 16 | public function configureOptions(OptionsResolver $resolver) 17 | { 18 | $resolver->setDefaults([ 19 | 'csrf_protection' => false, 20 | 'data_class' => 'AppBundle\Entity\Link' 21 | ]); 22 | } 23 | } -------------------------------------------------------------------------------- /src/AppBundle/Repository/ApiKeyRepository.php: -------------------------------------------------------------------------------- 1 | getEntityManager()->createQueryBuilder(); 22 | $q = $qb->select('l') 23 | ->from('AppBundle:Link', 'l') 24 | ->where('l.user = ?1') 25 | ->setParameter(1, $id) 26 | ->getQuery(); 27 | 28 | return $q->execute(); 29 | } 30 | 31 | public function getLink(string $code) 32 | { 33 | /** 34 | * @var $qb QueryBuilder 35 | */ 36 | $qb = $this->getEntityManager()->createQueryBuilder(); 37 | 38 | $q = $qb->select('l') 39 | ->from('AppBundle:Link', 'l') 40 | ->where('l.code = ?1') 41 | ->setParameter(1, $code) 42 | ->setMaxResults(1) 43 | ->getQuery(); 44 | 45 | return $q->execute()[0]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/AppBundle/Repository/UserRepository.php: -------------------------------------------------------------------------------- 1 | providing you with your own private URL shortener! 7 | 8 | form: 9 | url_placeholder: http(s)://example.com 10 | url_label: URL to shorten 11 | submit_button: Shorten URL 12 | -------------------------------------------------------------------------------- /src/AppBundle/Resources/views/Home/home.html.twig: -------------------------------------------------------------------------------- 1 | {% extends 'AppBundle::layout.html.twig' %} 2 | {% form_theme form 'bootstrap_3_layout.html.twig' %} 3 | {% block body %} 4 |
5 |
6 |

{{ 'app.name' | trans }}

7 |

{{ 'home.lead' | trans | raw }}

8 |
9 | {% if link.id %} 10 |
11 | 12 |
13 | 14 |


15 | {{ 'home.add_another_url' | trans }} 16 | {% else %} 17 | {{ form_start(form) }} 18 |
19 | 20 | {{ form_widget(form.url, {'attr': {'class': 'input-lg', 'placeholder': 'home.form.url_placeholder' | trans }}) }} 21 |
22 | 23 | {{ form_end(form) }} 24 | {% endif %} 25 |
26 |
27 |
28 | 29 | {% endblock %} -------------------------------------------------------------------------------- /src/AppBundle/Resources/views/Layout/_navigation.html.twig: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/AppBundle/Resources/views/layout.html.twig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{ page_title is defined ? page_title : 'Purl - Your very own URL shortener!' }} 5 | 6 | 8 | 9 | 10 | 11 | {% include 'AppBundle:Layout:_navigation.html.twig' %} 12 |
13 | {% block body %}{% endblock %} 14 |
15 | {% block javascripts %} 16 | 17 | {% endblock %} 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/AppBundle/Security/ApiKeyAuthenticator.php: -------------------------------------------------------------------------------- 1 | getCredentials(); 30 | $username = $userProvider->getUsernameForApiKey($apiKey); 31 | 32 | if (!$username) { 33 | throw new CustomUserMessageAuthenticationException( 34 | sprintf('API Key "%s" does not exist.', $apiKey) 35 | ); 36 | } 37 | 38 | $user = $userProvider->loadUserByUsername($username); 39 | 40 | return new PreAuthenticatedToken( 41 | $user, 42 | $apiKey, 43 | $providerKey, 44 | $user->getRoles() 45 | ); 46 | } 47 | 48 | public function supportsToken(TokenInterface $token, $providerKey) 49 | { 50 | return $token instanceof PreAuthenticatedToken && $token->getProviderKey() === $providerKey; 51 | } 52 | 53 | public function createToken(Request $request, $providerKey) 54 | { 55 | $apiKey = $request->query->get('apiKey'); 56 | 57 | if (!$apiKey) { 58 | throw new BadCredentialsException('No API key found'); 59 | } 60 | 61 | return new PreAuthenticatedToken( 62 | 'anon.', 63 | $apiKey, 64 | $providerKey 65 | ); 66 | } 67 | 68 | /** 69 | * This is called when an interactive authentication attempt fails. This is 70 | * called by authentication listeners inheriting from 71 | * AbstractAuthenticationListener. 72 | * 73 | * @param Request $request 74 | * @param AuthenticationException $exception 75 | * 76 | * @return Response The response to return, never null 77 | */ 78 | public function onAuthenticationFailure(Request $request, AuthenticationException $exception) 79 | { 80 | return new Response( 81 | strtr($exception->getMessageKey(), $exception->getMessageData()), 82 | 403 83 | ); 84 | } 85 | } -------------------------------------------------------------------------------- /src/AppBundle/Security/ApiKeyUserProvider.php: -------------------------------------------------------------------------------- 1 | em = $em; 24 | } 25 | 26 | public function getUsernameForApiKey($apiKey) 27 | { 28 | // Look up the username based on the token in the database, via 29 | // an API call, or do something entirely different 30 | // $username = ...; 31 | $apiKey = $this->em->getRepository('AppBundle:ApiKey')->findOneBy(['apiKey' => $apiKey]); 32 | 33 | if (!$apiKey || !$apiKey->getUser()) { 34 | throw new AccessDeniedException(); 35 | } 36 | 37 | return $apiKey->getUser()->getUsername(); 38 | } 39 | 40 | public function loadUserByUsername($username) 41 | { 42 | $user = $this->em->getRepository('AppBundle:User')->findOneBy(['username' => $username]); 43 | return $user; 44 | } 45 | 46 | public function refreshUser(UserInterface $user) 47 | { 48 | // this is used for storing authentication in the session 49 | // but in this example, the token is sent in each request, 50 | // so authentication can be stateless. Throwing this exception 51 | // is proper to make things stateless 52 | throw new AccessDeniedException(); 53 | } 54 | 55 | public function supportsClass($class) 56 | { 57 | return 'Symfony\Component\Security\Core\User\User' === $class; 58 | } 59 | } -------------------------------------------------------------------------------- /src/AppBundle/Service/CodeGeneratorService.php: -------------------------------------------------------------------------------- 1 | salt = $salt; 18 | } 19 | 20 | public function generateCode() 21 | { 22 | $hashIds = new Hashids($this->salt); 23 | return $hashIds->encode(time() - 1000000000); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /tests/AppBundle/Controller/LinksControllerTest.php: -------------------------------------------------------------------------------- 1 | client = static::createClient(); 15 | $this->loadFixtures([ 16 | 'AppBundle\DataFixtures\ORM\LoadUserData', 17 | 'AppBundle\DataFixtures\ORM\LoadApiKeyData', 18 | 'AppBundle\DataFixtures\ORM\LoadLinkData', 19 | ]); 20 | } 21 | 22 | protected function assertJsonResponse($response, $statusCode = 200) 23 | { 24 | $this->assertEquals( 25 | $statusCode, $response->getStatusCode(), 26 | $response->getContent() 27 | ); 28 | $this->assertTrue( 29 | $response->headers->contains('Content-Type', 'application/json'), 30 | $response->headers 31 | ); 32 | } 33 | 34 | public function testGetLink() 35 | { 36 | $testUrl = sprintf('%s%s', $this->getApiUrl(), '/link/test.json?apiKey=test-key'); 37 | $this->client->request('GET', $testUrl, ['ACCEPT' => 'application/json']); 38 | 39 | $response = $this->client->getResponse(); 40 | 41 | $this->assertJsonResponse($response, 200); 42 | $this->assertContains('"url":"http:\/\/google.be","code":"test","clicks":0}}', $response->getContent()); 43 | } 44 | 45 | public function getApiUrl() 46 | { 47 | return 'http://purl.docker/api/v1'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /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('iconv'), 638 | 'iconv() should be available', 639 | 'Install and enable the iconv extension.' 640 | ); 641 | 642 | $this->addRecommendation( 643 | function_exists('utf8_decode'), 644 | 'utf8_decode() should be available', 645 | 'Install and enable the XML extension.' 646 | ); 647 | 648 | $this->addRecommendation( 649 | function_exists('filter_var'), 650 | 'filter_var() should be available', 651 | 'Install and enable the filter extension.' 652 | ); 653 | 654 | if (!defined('PHP_WINDOWS_VERSION_BUILD')) { 655 | $this->addRecommendation( 656 | function_exists('posix_isatty'), 657 | 'posix_isatty() should be available', 658 | 'Install and enable the php_posix extension (used to colorize the CLI output).' 659 | ); 660 | } 661 | 662 | $this->addRecommendation( 663 | extension_loaded('intl'), 664 | 'intl extension should be available', 665 | 'Install and enable the intl extension (used for validators).' 666 | ); 667 | 668 | if (extension_loaded('intl')) { 669 | // in some WAMP server installations, new Collator() returns null 670 | $this->addRecommendation( 671 | null !== new Collator('fr_FR'), 672 | 'intl extension should be correctly configured', 673 | 'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.' 674 | ); 675 | 676 | // check for compatible ICU versions (only done when you have the intl extension) 677 | if (defined('INTL_ICU_VERSION')) { 678 | $version = INTL_ICU_VERSION; 679 | } else { 680 | $reflector = new ReflectionExtension('intl'); 681 | 682 | ob_start(); 683 | $reflector->info(); 684 | $output = strip_tags(ob_get_clean()); 685 | 686 | preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches); 687 | $version = $matches[1]; 688 | } 689 | 690 | $this->addRecommendation( 691 | version_compare($version, '4.0', '>='), 692 | 'intl ICU version should be at least 4+', 693 | 'Upgrade your intl extension with a newer ICU version (4+).' 694 | ); 695 | 696 | if (class_exists('Symfony\Component\Intl\Intl')) { 697 | $this->addRecommendation( 698 | \Symfony\Component\Intl\Intl::getIcuDataVersion() <= \Symfony\Component\Intl\Intl::getIcuVersion(), 699 | 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()), 700 | 'To get the latest internationalization data upgrade the ICU system package and the intl PHP extension.' 701 | ); 702 | if (\Symfony\Component\Intl\Intl::getIcuDataVersion() <= \Symfony\Component\Intl\Intl::getIcuVersion()) { 703 | $this->addRecommendation( 704 | \Symfony\Component\Intl\Intl::getIcuDataVersion() === \Symfony\Component\Intl\Intl::getIcuVersion(), 705 | 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()), 706 | 'To avoid internationalization data inconsistencies upgrade the symfony/intl component.' 707 | ); 708 | } 709 | } 710 | 711 | $this->addPhpIniRecommendation( 712 | 'intl.error_level', 713 | create_function('$cfgValue', 'return (int) $cfgValue === 0;'), 714 | true, 715 | 'intl.error_level should be 0 in php.ini', 716 | 'Set "intl.error_level" to "0" in php.ini* to inhibit the messages when an error occurs in ICU functions.' 717 | ); 718 | } 719 | 720 | $accelerator = 721 | (extension_loaded('eaccelerator') && ini_get('eaccelerator.enable')) 722 | || 723 | (extension_loaded('apc') && ini_get('apc.enabled')) 724 | || 725 | (extension_loaded('Zend Optimizer+') && ini_get('zend_optimizerplus.enable')) 726 | || 727 | (extension_loaded('Zend OPcache') && ini_get('opcache.enable')) 728 | || 729 | (extension_loaded('xcache') && ini_get('xcache.cacher')) 730 | || 731 | (extension_loaded('wincache') && ini_get('wincache.ocenabled')) 732 | ; 733 | 734 | $this->addRecommendation( 735 | $accelerator, 736 | 'a PHP accelerator should be installed', 737 | 'Install and/or enable a PHP accelerator (highly recommended).' 738 | ); 739 | 740 | if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { 741 | $this->addRecommendation( 742 | $this->getRealpathCacheSize() >= 5 * 1024 * 1024, 743 | 'realpath_cache_size should be at least 5M in php.ini', 744 | 'Setting "realpath_cache_size" to e.g. "5242880" or "5M" in php.ini* may improve performance on Windows significantly in some cases.' 745 | ); 746 | } 747 | 748 | $this->addPhpIniRecommendation('short_open_tag', false); 749 | 750 | $this->addPhpIniRecommendation('magic_quotes_gpc', false, true); 751 | 752 | $this->addPhpIniRecommendation('register_globals', false, true); 753 | 754 | $this->addPhpIniRecommendation('session.auto_start', false); 755 | 756 | $this->addRecommendation( 757 | class_exists('PDO'), 758 | 'PDO should be installed', 759 | 'Install PDO (mandatory for Doctrine).' 760 | ); 761 | 762 | if (class_exists('PDO')) { 763 | $drivers = PDO::getAvailableDrivers(); 764 | $this->addRecommendation( 765 | count($drivers) > 0, 766 | sprintf('PDO should have some drivers installed (currently available: %s)', count($drivers) ? implode(', ', $drivers) : 'none'), 767 | 'Install PDO drivers (mandatory for Doctrine).' 768 | ); 769 | } 770 | } 771 | 772 | /** 773 | * Loads realpath_cache_size from php.ini and converts it to int. 774 | * 775 | * (e.g. 16k is converted to 16384 int) 776 | * 777 | * @return int 778 | */ 779 | protected function getRealpathCacheSize() 780 | { 781 | $size = ini_get('realpath_cache_size'); 782 | $size = trim($size); 783 | $unit = strtolower(substr($size, -1, 1)); 784 | switch ($unit) { 785 | case 'g': 786 | return $size * 1024 * 1024 * 1024; 787 | case 'm': 788 | return $size * 1024 * 1024; 789 | case 'k': 790 | return $size * 1024; 791 | default: 792 | return (int) $size; 793 | } 794 | } 795 | 796 | /** 797 | * Defines PHP required version from Symfony version. 798 | * 799 | * @return string|false The PHP required version or false if it could not be guessed 800 | */ 801 | protected function getPhpRequiredVersion() 802 | { 803 | if (!file_exists($path = __DIR__.'/../composer.lock')) { 804 | return false; 805 | } 806 | 807 | $composerLock = json_decode(file_get_contents($path), true); 808 | foreach ($composerLock['packages'] as $package) { 809 | $name = $package['name']; 810 | if ('symfony/symfony' !== $name && 'symfony/http-kernel' !== $name) { 811 | continue; 812 | } 813 | 814 | return (int) $package['version'][1] > 2 ? self::REQUIRED_PHP_VERSION : self::LEGACY_REQUIRED_PHP_VERSION; 815 | } 816 | 817 | return false; 818 | } 819 | } 820 | -------------------------------------------------------------------------------- /var/cache/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veloxy/purl/4ce902ba7197e0a9206df140173bb492366fce1f/var/cache/.gitkeep -------------------------------------------------------------------------------- /var/logs/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veloxy/purl/4ce902ba7197e0a9206df140173bb492366fce1f/var/logs/.gitkeep -------------------------------------------------------------------------------- /var/sessions/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veloxy/purl/4ce902ba7197e0a9206df140173bb492366fce1f/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 | unregister(); 18 | $apcLoader->register(true); 19 | */ 20 | 21 | $kernel = new AppKernel('prod', false); 22 | $kernel->loadClassCache(); 23 | //$kernel = new AppCache($kernel); 24 | 25 | // When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter 26 | //Request::enableHttpMethodParameterOverride(); 27 | $request = Request::createFromGlobals(); 28 | $response = $kernel->handle($request); 29 | $response->send(); 30 | $kernel->terminate($request, $response); 31 | -------------------------------------------------------------------------------- /web/app_dev.php: -------------------------------------------------------------------------------- 1 | loadClassCache(); 14 | $request = Request::createFromGlobals(); 15 | $response = $kernel->handle($request); 16 | $response->send(); 17 | $kernel->terminate($request, $response); 18 | -------------------------------------------------------------------------------- /web/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veloxy/purl/4ce902ba7197e0a9206df140173bb492366fce1f/web/apple-touch-icon.png -------------------------------------------------------------------------------- /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 | 42 | 43 | 124 | 125 | 126 |
127 |
128 | 131 | 132 | 152 |
153 | 154 |
155 |
156 |
157 |

Configuration Checker

158 |

159 | This script analyzes your system to check whether is 160 | ready to run Symfony applications. 161 |

162 | 163 | 164 |

Major problems

165 |

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

166 |
    167 | 168 |
  1. getTestMessage() ?> 169 |

    getHelpHtml() ?>

    170 |
  2. 171 | 172 |
173 | 174 | 175 | 176 |

Recommendations

177 |

178 | Additionally, toTo enhance your Symfony experience, 179 | it’s recommended that you fix the following: 180 |

181 |
    182 | 183 |
  1. getTestMessage() ?> 184 |

    getHelpHtml() ?>

    185 |
  2. 186 | 187 |
188 | 189 | 190 | hasPhpIniConfigIssue()): ?> 191 |

* 192 | getPhpIniConfigPath()): ?> 193 | Changes to the php.ini file must be done in "getPhpIniConfigPath() ?>". 194 | 195 | To change settings, create a "php.ini". 196 | 197 |

198 | 199 | 200 | 201 |

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

202 | 203 | 204 | 209 |
210 |
211 |
212 |
Symfony Standard Edition
213 |
214 | 215 | 216 | -------------------------------------------------------------------------------- /web/css/style.css: -------------------------------------------------------------------------------- 1 | body{padding-top:100px;background:url(/img/background.jpg) center center no-repeat fixed;-webkit-background-size:cover;-moz-background-size:cover;-o-background-size:cover;background-size:cover;font-family:'Open Sans',sans-serif}@media only screen and (-webkit-min-device-pixel-ratio:2){body{background:url(/img/background@2x.jpg) center center no-repeat fixed;-webkit-background-size:cover;-moz-background-size:cover;-o-background-size:cover;background-size:cover}}h1{font-size:50px;margin-bottom:20px}p.lead{margin-bottom:40px}.form-home{text-align:center;width:600px;margin:0 auto}.form-home input{display:inline;width:450px;border-radius:30px 0 0 30px;float:left;border-right:0}.form-home .btn{display:inline-block;border-radius:0 30px 30px 0;float:left;width:150px;background-color:#404040;border-color:#121213}a{color:#404040}a:active{color:#121213} -------------------------------------------------------------------------------- /web/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veloxy/purl/4ce902ba7197e0a9206df140173bb492366fce1f/web/favicon.ico -------------------------------------------------------------------------------- /web/img/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veloxy/purl/4ce902ba7197e0a9206df140173bb492366fce1f/web/img/background.jpg -------------------------------------------------------------------------------- /web/img/background@2x.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veloxy/purl/4ce902ba7197e0a9206df140173bb492366fce1f/web/img/background@2x.jpg -------------------------------------------------------------------------------- /web/js/scripts.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * clipboard.js v1.5.9 3 | * https://zenorocha.github.io/clipboard.js 4 | * 5 | * Licensed MIT © Zeno Rocha 6 | */ 7 | !function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Clipboard=t()}}(function(){var t,e,n;return function t(e,n,o){function r(c,s){if(!n[c]){if(!e[c]){var a="function"==typeof require&&require;if(!s&&a)return a(c,!0);if(i)return i(c,!0);var l=new Error("Cannot find module '"+c+"'");throw l.code="MODULE_NOT_FOUND",l}var u=n[c]={exports:{}};e[c][0].call(u.exports,function(t){var n=e[c][1][t];return r(n?n:t)},u,u.exports,t,e,n,o)}return n[c].exports}for(var i="function"==typeof require&&require,c=0;co;o++)n[o].fn.apply(n[o].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),o=n[t],r=[];if(o&&e)for(var i=0,c=o.length;c>i;i++)o[i].fn!==e&&o[i].fn._!==e&&r.push(o[i]);return r.length?n[t]=r:delete n[t],this}},e.exports=o},{}],8:[function(e,n,o){!function(r,i){if("function"==typeof t&&t.amd)t(["module","select"],i);else if("undefined"!=typeof o)i(n,e("select"));else{var c={exports:{}};i(c,r.select),r.clipboardAction=c.exports}}(this,function(t,e){"use strict";function n(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var r=n(e),i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},c=function(){function t(t,e){for(var n=0;n