{"id":28238727,"url":"https://github.com/pstephenson02/silex-doctrine-orm-starter","last_synced_at":"2025-08-09T16:19:11.027Z","repository":{"id":191929515,"uuid":"79063468","full_name":"pstephenson02/silex-doctrine-orm-starter","owner":"pstephenson02","description":"An opinionated starter project for Silex and Doctrine ORM","archived":false,"fork":false,"pushed_at":"2017-02-08T20:54:52.000Z","size":47,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-19T01:13:23.529Z","etag":null,"topics":["doctrine-orm","php","silex"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pstephenson02.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-01-15T22:22:20.000Z","updated_at":"2020-03-22T17:23:27.000Z","dependencies_parsed_at":null,"dependency_job_id":"3816c8b3-710f-4811-916c-d63f9fd57f86","html_url":"https://github.com/pstephenson02/silex-doctrine-orm-starter","commit_stats":null,"previous_names":["pstephenson02/silex-doctrine-orm-starter"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pstephenson02%2Fsilex-doctrine-orm-starter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pstephenson02%2Fsilex-doctrine-orm-starter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pstephenson02%2Fsilex-doctrine-orm-starter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pstephenson02%2Fsilex-doctrine-orm-starter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pstephenson02","download_url":"https://codeload.github.com/pstephenson02/silex-doctrine-orm-starter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pstephenson02%2Fsilex-doctrine-orm-starter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259186386,"owners_count":22818550,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["doctrine-orm","php","silex"],"created_at":"2025-05-19T01:13:21.550Z","updated_at":"2025-06-11T02:31:56.631Z","avatar_url":"https://github.com/pstephenson02.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# silex-doctrine-orm-starter\n\n**Project Requirements**: PHP7, Composer\n\n[Silex](http://silex.sensiolabs.org/) is a PHP micro-framework based on Symfony components. Silex can be a pleasure to work with for developers that enjoy more control over the structure of their applications. However, large projects that use Silex often require more disciplined patterns and sometimes need a full-fledged ORM. While Silex does not officially support [Doctrine ORM](http://www.doctrine-project.org/projects/orm.html), [dflydev-doctrine-orm-service-provider](https://github.com/dflydev/dflydev-doctrine-orm-service-provider) is an excellent extension for which to provide your Silex app with ORM behavior. This project goes a step futher. Silex-doctrine-orm-starter provides examples of extendible patterns and methods that I have found useful in my experience using Silex and Doctrine ORM. A few highlights include:\n\n  - Doctrine ORM annotation mapping\n  - Doctrine lifecycle event hooks in the form of a TimestampableEntity trait, and a UserSubscriber\n  - A bootstrapped, custom Doctrine cli with an example custom command using the Symfony console component.\n  - A test case class that provides easy integration with the doctrine-fixtures library.\n\nThe starter also includes some Silex specific goodies:\n  - Defining controllers as services\n  - Integration with the Silex web debug toolbar (also includes Doctrine DBAL queries)\n\n### How should I use this project?\n\nIt is unlikely that you will need every component of this starter package. If you have an existing Silex app, you may decide to use this project as a reference guide for how to structure your application code or for how to utilize some of Doctrine ORM's high level features. For more information on Doctrine's features, check out its [excellent documentation](http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/).\n\nYou may also decide to use silex-doctrine-orm-starter as a skeleton project for a new Silex app. It makes a great starting point specificically for JSON-based REST APIs backed by a MySQL database. To begin a new project, follow the installation instructions below.\n\n### Installation\n\n1. Clone this repository:\n\n    ```\n    $ git clone git@github.com:pstephenson02/silex-doctrine-orm-starter.git\n    $ cd silex-doctrine-orm-starter/\n    ```\n2. Install dependencies:\n\n    ```\n    $ composer install -o\n    ```\n3. Configure app parameters:\n    ```\n    $ cp app/parameters.dist.php app/parameters.php\n    ```\n    Open the `parameters.php` file with your text editor of choice and replace the defaults with your own database settings. Changing `debug` to `true` will provide the Silex Web Profiler toolbar on requests - this is very useful during development. If you have not already created a new MySQL database, you should do so now. If you are unsure how to do this, refer to these DigitalOcean tutorials [^1], [^2].\n    \n4. Create the database schema:\n    ```\n    $ ./bin/doctrine orm:schema-tool:create\n    ```\n5. Profit! Your app is now installed, configured and ready to be used. Continue on to the usage section for some tips for getting started.\n\n### Usage\nYou will need a web server to negotiate requests and responses to your app. For development purposes, the simplest option is to use the PHP built-in webserver:\n```\n$ php -S localhost:8000 -t public/\n```\nIn a production environment, you should use something more reliable (Apache, nginx, etc.)\nYou can now make requests to your API. Let's create a new user:\n```\n$ curl -H 'Content-Type: application/json' -X POST '{\"email\":\"bob@loblaw.org\"}' localhost:8000/user/\n{\"id\":1,\"email\":\"bob@loblaw.org\"}\n```\n\nIf we now call the `getUsers` endpoint at /user/ we'll see our user:\n```\ncurl -v localhost:8000/user/\n*   Trying 127.0.0.1...\n* Connected to localhost (127.0.0.1) port 8000 (#0)\n\u003e GET /user/ HTTP/1.1\n\u003e Host: localhost:8000\n\u003e User-Agent: curl/7.47.0\n\u003e Accept: */*\n\u003e \n\u003c HTTP/1.1 200 OK\n\u003c Host: localhost:8000\n\u003c Connection: close\n\u003c X-Powered-By: PHP/7.0.13-0ubuntu0.16.04.1\n\u003c Cache-Control: no-cache, private\n\u003c Content-Type: application/json\n\u003c X-Debug-Token: 0ec09f\n\u003c X-Debug-Token-Link: http://localhost:8000/_profiler/0ec09f\n\u003c Date: Wed, 08 Feb 2017 19:46:08 GMT\n\u003c \n* Closing connection 0\n[{\"id\":1,\"email\":\"bob@loblaw.org\"}]\n```\nIn this case, I passed the `-v` curl flag to show the HTTP headers. Because I set `debug` to `true` in my `app/parameters.php` file, notice that I now get the header `X-Debug-Token-Link`. If we follow the link shown in this header with a web browser, we'll find the web profiler page with helpful information about this request.\n\n**Seeding Users**\n\nYou can also create users with the command line tool by using the `orm:seed:users` command:\n```\n$ ./bin/doctrine orm:seed:users\nHow many users would you like to create? 100\nSuccessfully generated 100 new users!\n```\nThis command creates new users with random string email addresses. For more information on how this command works, see `UserSeeder.php` and Symfony's Console Component [documentation](http://symfony.com/doc/current/components/console.html).\n\n### Running tests\nTo run the test suite, simply run phpunit from the vendor folder:\n```\n$ vendor/bin/phpunit\n```\nFor more control over testing, use the `phpunit.xml.dist` file as a template and configure phpunit:\n```\n$ cp phpunit.xml.dist phpunit.xml\n```\n\n### What now?\n\nThat's all for now! I hope this project and this README contains some useful info for your own projects. I encourage you to play around with the features found here and tweak them to meet your own needs. This project was designed around my own needs for past (and current) Silex projects. You may (probably will) find your own requirements to be different.\n\nIn the future, I will write more documentation explaining other features found in silex-orm-doctrine-starter and I plan to write about why I chose to do things the way I've done here. I will also continue to build on this project to integrate more common tool sets. Specifically, in the future I would like to include:\n* Data migrations with the [Doctrine Migrations library](https://github.com/doctrine/migrations)\n* Integration with [Swagger](http://swagger.io/)\n\n\n[^1]: https://www.digitalocean.com/community/tutorials/a-basic-mysql-tutorial\n[^2]: https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpstephenson02%2Fsilex-doctrine-orm-starter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpstephenson02%2Fsilex-doctrine-orm-starter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpstephenson02%2Fsilex-doctrine-orm-starter/lists"}