-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug #1, initial PHP-based AccessifyWiki API server
* built on the Slim PHP framework; * Google App Engine & portable PHP web application; * Travis web-hook, GitHub, DotEnv libraries; * initial tests and Travis-CI configuration;
- Loading branch information
0 parents
commit 0424256
Showing
15 changed files
with
904 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
|
||
.htaccess | ||
|
||
.env | ||
.env.example | ||
app.yaml | ||
|
||
src/p2.php | ||
|
||
composer.lock | ||
vendor/* | ||
test/node_modules/* | ||
|
||
*BAK* | ||
.DS_Store | ||
|
||
|
||
#End. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# see http://about.travis-ci.org/docs/user/languages/php/ | ||
language: php | ||
php: | ||
- 5.5 | ||
#- 5.6 | ||
#- 7.0 | ||
#- hhvm | ||
|
||
before_install: | ||
- composer self-update | ||
- composer --version | ||
|
||
install: | ||
- composer install | ||
- composer install-npm | ||
|
||
script: | ||
- composer test | ||
|
||
notifications: | ||
#- iet-webmaster@open.ac.uk | ||
|
||
#End. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
# AccessifyWiki-API | ||
|
||
Portable/ Google App Engine hosted PHP-based API for AccessifyWiki accessibility fixes. | ||
|
||
* <http://accessifywiki-2.appspot.com/fix?url=X> | ||
* <http://accessifywiki.github.io> | ||
|
||
## Useful commands | ||
|
||
```sh | ||
cp app.TEMPLATE.yaml app.yaml | ||
``` | ||
|
||
Install, serve, test, deploy: | ||
|
||
``` | ||
composer install-npm | ||
composer test | ||
composer serve | ||
composer serve-php | ||
composer ps | ||
composer deploy | ||
``` | ||
|
||
## The repos | ||
|
||
* [@accessifywiki/accessifywiki-api][] | ||
* [@accessifywiki/accessifywiki.github.io][] | ||
* [@yatil/accessifyhtml5.js][] | ||
* [@nfreear/accessify-wiki][] | ||
* [@nfreear/wp-accessify][] | ||
* [@nfreear/accessify-client-php][] | ||
|
||
|
||
[@accessifywiki/accessifywiki-api]: https://github.com/accessifywiki/accessifywiki-api | ||
[@accessifywiki/accessifywiki.github.io]: https://github.com/accessifywiki/accessifywiki.github.io | ||
[@yatil/accessifyhtml5.js]: https://github.com/yatil/accessifyhtml5.js | ||
[@nfreear/accessify-wiki]: https://github.com/nfreear/accessify-wiki "Legacy Python/webapp2-based service" | ||
[@nfreear/wp-accessify]: https://github.com/nfreear/wp-accessify "WordPress plugin" | ||
[@nfreear/accessify-client-php]: https://github.com/nfreear/accessify-client-php "PHP client library" | ||
|
||
|
||
[End]: //end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
application: accessifywiki-2 | ||
version: 1 | ||
runtime: php55 | ||
api_version: 1 | ||
#threadsafe: yes | ||
|
||
handlers: | ||
- url: /favicon\.ico | ||
static_files: favicon.ico | ||
upload: favicon\.ico | ||
|
||
- url: /.* | ||
script: index.php | ||
|
||
|
||
# Ignore files. | ||
skip_files: | ||
- ^(.*/)?#.*#$ | ||
- ^(.*/)?.*~$ | ||
- ^(.*/)?.*\.py[co]$ | ||
- ^(.*/)?.*/RCS/.*$ | ||
- ^(.*/)?\..*$ | ||
- Makefile | ||
- .*\.md | ||
- composer\.(json|lock) | ||
- .*(BAK|bak).* | ||
- .*\.diff | ||
- .*\.TEMPLATE.* | ||
- vendor/(bin|squizlabs)/.* | ||
- vendor/.*/(php-parallel-lint|php_codesniffer)/.* | ||
|
||
|
||
env_variables: | ||
foo: 'bar' | ||
aw_use_dotenv: false | ||
|
||
REDIRECT_URL: http://accessifywiki.github.io/ | ||
FIX_INDEX_URL: http://accessifywiki.github.io/fix/index.json | ||
AW_WIKI_SEARCH_URL: false | ||
# Travis-CI Web Hook. | ||
TRAVIS_REPO_SLUG: accessifywiki/accessifywiki.github.io | ||
TRAVIS_TOKEN: "{{ X-EDIT ME }}" | ||
TRAVIS_LOG_DIR: "./logs/{{ EDIT ME }}" | ||
|
||
|
||
#End. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"name": "accessifywiki/accessifywiki-api", | ||
"description": "Todo ...", | ||
"type": "project", | ||
"minimum-stability": "beta", | ||
"keywords": [ "accessibility", "wiki", "fix" ], | ||
"homepage": "http://accessifywiki.org", | ||
"time": "2016-02-11", | ||
"license": "proprietary", | ||
"require": { | ||
"php": ">=5.4.0", | ||
"vlucas/phpdotenv": "^2.2", | ||
"slim/slim": "^3.0", | ||
"guzzlehttp/guzzle": "^6.1", | ||
"kzykhys/yaml-front-matter": "^1.0", | ||
"symfony/yaml": "^2.8" | ||
}, | ||
"require-dev": { | ||
"squizlabs/php_codesniffer": "^2.5", | ||
"jakub-onderka/php-parallel-lint": "^0.9.2" | ||
}, | ||
"suggest": { | ||
"slim/slim": "^2.6", | ||
"slim/slim::3": "^3.0; Requires PHP >=5.5 :(", | ||
"silex/silex": "^1.3", | ||
"devster/frontmatter": "^1.0@dev", | ||
"kzykhys/yaml-front-matter": "^1.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"AccessifyWiki\\Api\\": "src/" | ||
} | ||
}, | ||
"scripts": { | ||
"test": [ | ||
"# composer validate --no-interaction", | ||
"cd test/ && node validate-app-yaml.js", | ||
"parallel-lint src/*", | ||
"parallel-lint index.php", | ||
"phpcs --standard=PSR2 -n --encoding=utf-8 --extensions=php src/*", | ||
"phpcs --standard=PSR2 -n --encoding=utf-8 --extensions=php test/*", | ||
"phpcs --standard=PSR2 -n --encoding=utf-8 --extensions=php index.php" | ||
], | ||
"test-gae": "/usr/local/bin/appcfg.py $*", | ||
"install-npm": "cd test/ && npm install", | ||
"test-yaml": "cd test/ && node validate-app-yaml.js", | ||
"test-yaml-0": "php test/validate-app-yaml.php", | ||
"serve": [ | ||
"# Serving http://localhost:8080 ...", | ||
"/usr/local/bin/dev_appserver.py ." | ||
], | ||
"serve-php": "php -S localhost:8080", | ||
"deploy": "/usr/local/bin/appcfg.py update .", | ||
"ps": "ps -af | grep python", | ||
"kill": [ | ||
"# pkill -fx '.*_php_runtime.py' #( killall python )", | ||
"pkill -fx '.*_php_runtime.py'" | ||
] | ||
}, | ||
"extra": { | ||
"//": [ | ||
"/Applications/MAMP/bin/php/php5.5.3/bin/php ../../composer.phar require guzzlehttp/guzzle \"^6.1\"", | ||
" 503 78002 1 0 Tue12pm ttys000 0:08.97 /usr/bin/python /usr/local/bin/_php_runtime.py", | ||
"http://unix.stackexchange.com/questions/50555/kill-many-instances-of-a-running-process-with-one-command" | ||
] | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
/** | ||
* Front controller for AccessifyWiki API. | ||
* | ||
* @author Nick Freear, 11 February 2016. | ||
* @link http://nikic.github.io/2014/02/18/Fast-request-routing-using-regular-expressions.html | ||
*/ | ||
|
||
use \Psr\Http\Message\ServerRequestInterface as Request; | ||
use \Psr\Http\Message\ResponseInterface as Response; | ||
|
||
require_once __DIR__ . '/vendor/autoload.php'; | ||
|
||
|
||
$app = \AccessifyWiki\Api\App::getInstance(); | ||
|
||
$app->get('/', function (Request $request, Response $response) { | ||
|
||
$url = getenv('REDIRECT_URL'); | ||
if ($url) { | ||
header('Location: '. $url); | ||
exit; | ||
} else { | ||
return $response->withStatus(500)->write('Woops! No redirect URL: '. $url); | ||
} | ||
//return $response->withRedirect(getenv('REDIRECT_URL')); | ||
}); | ||
|
||
$app->get('/hello/{name}', function (Request $request, Response $response) { | ||
$name = $request->getAttribute('name'); | ||
$response->getBody()->write("Hello, $name"); | ||
|
||
return $response; | ||
}); | ||
|
||
$app->get('/fix', function (Request $request, Response $response, $args) use ($app) { | ||
|
||
$response = $response->withHeader('Access-Control-Allow-Origin', '*'); | ||
|
||
$url = $app->getRequiredUrl($response); | ||
if (! $url) { | ||
//Error! | ||
return $response; | ||
} | ||
|
||
return $response->withJson([ 'stat' => 200, 'url' => $url ]); | ||
|
||
//return $app->json([ 'url' => $url ], $response); | ||
}); | ||
|
||
$app->map(['GET', 'POST'], '/travis-hook', function (Request $request, Response $response, $args) use ($app) { | ||
|
||
$response = $response->withHeader('Content-Type', 'text/plain'); | ||
|
||
$travis_hook = new \AccessifyWiki\Api\TravisWebHook(); | ||
$result = $travis_hook->run(); | ||
|
||
if ($travis_hook->shouldSkip()) { | ||
$response->getBody()->write('OK, SKIP request detected [aw skip]'); | ||
|
||
} else if ($travis_hook->isTravisRequest()) { | ||
//OK. | ||
$response->getBody()->write('OK, this IS a travis request.'); | ||
|
||
$github = new \AccessifyWiki\Api\GitHub(); | ||
$resp = $github->getIndexJson(); | ||
|
||
// DO MORE .... | ||
|
||
} else { | ||
$response->getBody()->write('Warning, NOT a travis request.'); | ||
} | ||
|
||
$response->getBody()->write(print_r([ | ||
//$request->getAttribute('route')->name(), | ||
//$request->getResourceUri(), | ||
$app->server('REQUEST_URI'), | ||
$_SERVER[ 'REQUEST_URI' ], $request->getMethod(), | ||
$request->getHeaderLine('Accept'), $request->getParsedBody() ], true)); | ||
|
||
return $response; | ||
}); | ||
|
||
$app->get('/fix-index.json', function ($request, $response, $args) { | ||
$github = new AccessifyWiki\Api\GitHub(); | ||
//$resp = $client->request('GET', getenv('FIX_INDEX_URL')); | ||
$resp = $github->getIndexJson(); | ||
|
||
//$response->getBody()->write($resp->getParsedBody()); | ||
|
||
$resp = $resp->withHeader('X-AW-Passthru', 1); | ||
|
||
return $resp; | ||
}); | ||
|
||
$app->get('/fix/{fix_id}', function (Request $request, Response $response, $args) use ($app) { | ||
|
||
//$file = '_fixes/ou-news.md'; | ||
$fix_id = $args[ 'fix_id' ]; | ||
|
||
$github = new AccessifyWiki\Api\GitHub(); | ||
$result = $github->getFix($fix_id); | ||
|
||
var_dump('FIX', $fix_id, $result->fix); | ||
|
||
//return $result->response; | ||
}); | ||
|
||
$app->get('/github/diff', function (Request $request, Response $response, $args) use ($app) { | ||
|
||
$commit = '2e30ab485a08d30c0806c73c5e8501ddbe4009de'; | ||
|
||
$github = new AccessifyWiki\Api\GitHub(); | ||
$result = $github->getDiff($commit); | ||
|
||
return $response; | ||
}); | ||
|
||
|
||
//require_once 'lib/p2.php'; | ||
|
||
$app->run(); | ||
|
||
|
||
#End. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
; This is a simple php.ini file on App Engine | ||
; https://cloud.google.com/appengine/docs/php/config/php_ini | ||
|
||
|
||
;;error_reporting = E_ALL | ||
display_errors = "stdout" | ||
|
||
|
||
google_app_engine.enable_functions = "phpversion, phpinfo" | ||
|
||
|
||
;;End. |
Oops, something went wrong.