Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
vesparny committed Nov 24, 2013
1 parent 1d71f59 commit 3db85b5
Show file tree
Hide file tree
Showing 41 changed files with 2,003 additions and 407 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

[*]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
vendor
composer.phar
composer.lock
.DS_Store
app/logs/*.log
*~
.settings
.project
.buildpath
.idea
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
language: php

php:
- 5.3
- 5.4

env:
- APP_ENV=dev


before_script:
- wget http://getcomposer.org/composer.phar
- composer install --prefer-source
21 changes: 17 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
Copyright (c) 2012 Alessandro Arnodo alessandro@arnodo.net
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Copyright (c) 2013 Alessandro Arnodo

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
78 changes: 35 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,52 @@
# Silex Simple REST [![Build Status](https://secure.travis-ci.org/vesparny/silex-simple-rest.png)](http://travis-ci.org/vesparny/silex-simple-rest)
# Silex Simple REST
[![Latest Stable Version](https://poser.pugx.org/vesparny/silex-simple-rest/v/stable.png)](https://packagist.org/packages/nesbot/carbon) [![Total Downloads](https://poser.pugx.org/vesparny/silex-simple-rest/downloads.png)](https://packagist.org/packages/nesbot/carbon) [![Build Status](https://secure.travis-ci.org/vesparny/silex-simple-rest.png)](http://travis-ci.org/vesparny/silex-simple-rest)

A simple silex skeleton application for writing RESTful API. Developed and maintained by [Alessandro Arnodo](http://alessandro.arnodo.net).

**This project wants to be a starting point to writing scalable and maintainable REST api in with Silex micro-framework**

Continuous Integration is provided by [Travis-CI](http://travis-ci.org/).

## Setup

Install as a project via composer:
####How do I run it?
From this folder run the following commands to install the php and bower dependencies, import some data, and run a local php server.

curl -s http://getcomposer.org/installer | php
php composer.phar create-project vesparny/silex-simple-rest
You need at least php **5.4.*** with **SQLite extension** enabled and **Composer**

or just download the tarball from github and install dependencies via composer:

php composer.phar install

## Configuration

- Configure `RewriteBase /path/to/app` in `/web/.htaccess`
- Create a database (an example mysql database is provided in `/docs/` folder).
- Configure database access information in `/app/config/dev.json`.

## Features

Take a look to `/src/boot.php` to see how does it works.

Every files in the project follows [PSR-0 standards](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md).

In order to don't screw up autoloading it's important naming and declaring classes in `StudlyCaps`.
composer install
sqlite3 app.db < resources/sql/schema.sql
php -S 0:9001 -t web/

Your api is now available at http://localhost:9001/api/v1.

- Every route file place in `/app/Classes/Routes/` is automatically loaded. (an example Api.php Route class is provided)
- Same thing for file places in `/app/Classes/Business/`.
- `/app/config/default.json` is overwritten by any configuration you place in `/app/config/$env.json`.
- A logging file is created in `/app/logs/`, every day a new file is created (logging level is configurable).
The requests will be proxied to this url from the connect middleware.

## Run tests
####Run tests
Some tests were written, and all CRUD operations are fully tested :)

phpunit is required for the tests, place your own in `/tests/` folder, following the namespace structure.
From the root folder run the following command to run tests.

vendor/bin/phpunit

phpunit

## Used packages
####How does it work
The api will respond to

Refer to single package documentation for more accurate support.
GET -> http://localhost:9001/api/v1/notes
POST -> http://localhost:9001/api/v1/notes/{id}
POST -> http://localhost:9001/api/v1/notes
DELETE -> http://localhost:9001/api/v1/notes/{id}

Take a look at the source code, it's self explanatory :)

"silex/silex": "1.0.*",
"symfony/browser-kit": "2.1.*",
"symfony/css-selector": "2.1.*",
"symfony/finder": "2.1.*",
"symfony/process": "2.1.*",
"monolog/monolog": "1.2.*",
"symfony/validator": "2.1.*",
"igorw/config-service-provider": "1.0",
"doctrine/dbal": "2.2.*"
Under the resource folder you can find a .htaccess file to put the api in production.

## Contributing
####Contributing

Fell free to contribute, fork, pull request, hack. Thanks!

## Author
####Author

####Alessandro Arnodo

+ [@vesparny](https://twitter.com/vesparny)

Expand All @@ -71,3 +57,9 @@ Fell free to contribute, fork, pull request, hack. Thanks!
## License

see LICENSE file.






Binary file added app.db
Binary file not shown.
Empty file removed app/Classes/Business/.gitkeep
Empty file.
18 changes: 0 additions & 18 deletions app/Classes/Business/Api.php

This file was deleted.

Empty file removed app/Classes/Routes/.gitkeep
Empty file.
31 changes: 0 additions & 31 deletions app/Classes/Routes/Api.php

This file was deleted.

Empty file removed app/cache/.gitkeep
Empty file.
6 changes: 0 additions & 6 deletions app/config/default.json

This file was deleted.

10 changes: 0 additions & 10 deletions app/config/dev.json

This file was deleted.

3 changes: 0 additions & 3 deletions app/config/prod.json

This file was deleted.

Empty file removed app/logs/.gitkeep
Empty file.
61 changes: 31 additions & 30 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
{
"name": "vesparny/silex-simple-rest",
"type": "library",
"description": "A simple silex skeleton for rest api",
"keywords": [
"framework", "silex", "rest", "api"
],
"homepage": "http://github.com/vesparny/silex-simple-rest",
"license": "MIT",
"authors": [
{
"name": "Alessandro Arnodo",
"email": "alessandro@arnodo.net"
}
],
"require": {
"php": ">=5.3.3",
"silex/silex": "1.0.*",
"symfony/browser-kit": "2.1.*",
"symfony/css-selector": "2.1.*",
"symfony/finder": "2.1.*",
"symfony/process": "2.1.*",
"monolog/monolog": "1.2.*",
"symfony/validator": "2.1.*",
"igorw/config-service-provider": "1.2.*@dev",
"doctrine/dbal": "2.2.*"
},
"minimum-stability": "dev",
"autoload": {
"psr-0": {"Vesparny": "src/", "Classes" : "app/"}
}
"name": "vesparny/silex-simple-rest",
"type": "library",
"description": "A simple silex skeleton for rest api",
"keywords": [
"framework", "silex", "rest", "api"
],
"homepage": "http://github.com/vesparny/silex-simple-rest",
"license": "MIT",
"authors": [{
"name": "Alessandro Arnodo",
"email": "alessandro@arnodo.net"
}],
"require": {
"php": ">=5.3.0"
},
"require": {
"silex/silex": "~1.1",
"monolog/monolog": "~1.6",
"twig/twig": "~1.14",
"doctrine/dbal": "~2.4",
"nesbot/Carbon": "~1.6"
},
"require-dev": {
"phpunit/phpunit": "~3.7",
"mockery/mockery": "~0.8.0"
},
"autoload": {
"psr-0": {
"App": "src/"
}
}
}
Loading

0 comments on commit 3db85b5

Please sign in to comment.