Fix a bug for image proxy and update dependencies

This commit is contained in:
Frédéric Guillot 2014-12-29 16:52:36 -05:00
parent 3fe424999f
commit c43d9dd773
12 changed files with 213 additions and 105 deletions

View File

@ -88,5 +88,5 @@ Router\get_action('proxy', function() {
} }
Response\content_type($type); Response\content_type($type);
echo $content; Response\raw($content);
}); });

View File

@ -29,10 +29,10 @@ function response(array $response)
// Fever authentication // Fever authentication
function auth() function auth()
{ {
if (!empty($_GET['database'])) { if (! empty($_GET['database'])) {
Model\Database\select($_GET['database']); Model\Database\select($_GET['database']);
} }
$credentials = Database::get('db')->table('config') $credentials = Database::get('db')->table('config')
->columns('username', 'fever_token') ->columns('username', 'fever_token')
->findOne(); ->findOne();

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer' . '/autoload_real.php'; require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e::getLoader(); return ComposerAutoloaderInitdeb23075faf85ef9ce52dd731739836e::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e class ComposerAutoloaderInitdeb23075faf85ef9ce52dd731739836e
{ {
private static $loader; private static $loader;
@ -19,9 +19,9 @@ class ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInitdeb23075faf85ef9ce52dd731739836e', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(); self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInitdeb23075faf85ef9ce52dd731739836e', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php'; $map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) { foreach ($map as $namespace => $path) {
@ -42,14 +42,14 @@ class ComposerAutoloaderInitafa19cf4aabbde48e28a8081b9102b7e
$includeFiles = require __DIR__ . '/autoload_files.php'; $includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) { foreach ($includeFiles as $file) {
composerRequireafa19cf4aabbde48e28a8081b9102b7e($file); composerRequiredeb23075faf85ef9ce52dd731739836e($file);
} }
return $loader; return $loader;
} }
} }
function composerRequireafa19cf4aabbde48e28a8081b9102b7e($file) function composerRequiredeb23075faf85ef9ce52dd731739836e($file)
{ {
require $file; require $file;
} }

View File

@ -77,84 +77,6 @@
"description": "A simple Json-RPC client/server library that just works", "description": "A simple Json-RPC client/server library that just works",
"homepage": "https://github.com/fguillot/JsonRPC" "homepage": "https://github.com/fguillot/JsonRPC"
}, },
{
"name": "fguillot/picodb",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoDb.git",
"reference": "ebe721de0002b7ff86b7f66df0065224bf896eb2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoDb/zipball/ebe721de0002b7ff86b7f66df0065224bf896eb2",
"reference": "ebe721de0002b7ff86b7f66df0065224bf896eb2",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2014-11-22 04:15:43",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoDb": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"WTFPL"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Minimalist database query builder",
"homepage": "https://github.com/fguillot/picoDb"
},
{
"name": "fguillot/picofarad",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoFarad.git",
"reference": "df30333d5bf3b02f8f654c988c7c43305d5e6662"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoFarad/zipball/df30333d5bf3b02f8f654c988c7c43305d5e6662",
"reference": "df30333d5bf3b02f8f654c988c7c43305d5e6662",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2014-11-01 15:01:02",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoFarad": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Unlicense"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Minimalist micro-framework",
"homepage": "https://github.com/fguillot/picoFarad"
},
{ {
"name": "fguillot/picofeed", "name": "fguillot/picofeed",
"version": "dev-master", "version": "dev-master",
@ -193,5 +115,83 @@
], ],
"description": "Modern library to write or read feeds (RSS/Atom)", "description": "Modern library to write or read feeds (RSS/Atom)",
"homepage": "http://fguillot.github.io/picoFeed" "homepage": "http://fguillot.github.io/picoFeed"
},
{
"name": "fguillot/picodb",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoDb.git",
"reference": "5d1d8d6e898975fc30a241614d9bf06d5728db7d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoDb/zipball/5d1d8d6e898975fc30a241614d9bf06d5728db7d",
"reference": "5d1d8d6e898975fc30a241614d9bf06d5728db7d",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2014-12-26 17:10:34",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoDb": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"WTFPL"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Minimalist database query builder",
"homepage": "https://github.com/fguillot/picoDb"
},
{
"name": "fguillot/picofarad",
"version": "dev-master",
"version_normalized": "9999999-dev",
"source": {
"type": "git",
"url": "https://github.com/fguillot/picoFarad.git",
"reference": "070e1a90d71f403e75ac5464109eb7904daed9f3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fguillot/picoFarad/zipball/070e1a90d71f403e75ac5464109eb7904daed9f3",
"reference": "070e1a90d71f403e75ac5464109eb7904daed9f3",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"time": "2014-12-29 21:34:25",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-0": {
"PicoFarad": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Unlicense"
],
"authors": [
{
"name": "Frédéric Guillot",
"homepage": "http://fredericguillot.com"
}
],
"description": "Minimalist micro-framework",
"homepage": "https://github.com/fguillot/picoFarad"
} }
] ]

View File

@ -1,7 +1,7 @@
PicoDb PicoDb
====== ======
PicoDb is a minimalist database query builder for PHP PicoDb is a minimalist database query builder for PHP.
**It's not an ORM**. **It's not an ORM**.
Features Features
@ -23,14 +23,14 @@ Requirements
Todo Todo
---- ----
- Add driver for Postgresql - Add support for Distinct and group by
- Add support for Distinct...
Documentation Documentation
------------- -------------
## Connect to your database ## Connect to your database
```php
use PicoDb\Database; use PicoDb\Database;
// Sqlite driver // Sqlite driver
@ -46,29 +46,38 @@ Documentation
'database' => 'my_db_name', 'database' => 'my_db_name',
'charset' => 'utf8', 'charset' => 'utf8',
)); ));
```
## Execute a SQL request ## Execute a SQL request
```php
$db->execute('CREATE TABLE toto (column1 TEXT)'); $db->execute('CREATE TABLE toto (column1 TEXT)');
```
## Insert some data ## Insert some data
```php
$db->table('toto')->save(['column1' => 'hey']); $db->table('toto')->save(['column1' => 'hey']);
```
## Transations ## Transations
```php
$db->transaction(function($db) { $db->transaction(function($db) {
$db->table('toto')->save(['column1' => 'foo']); $db->table('toto')->save(['column1' => 'foo']);
$db->table('toto')->save(['column1' => 'bar']); $db->table('toto')->save(['column1' => 'bar']);
}); });
```
## Fetch all data ## Fetch all data
```php
$records = $db->table('toto')->findAll(); $records = $db->table('toto')->findAll();
foreach ($records as $record) { foreach ($records as $record) {
var_dump($record['column1']); var_dump($record['column1']);
} }
```
## Update something ## Update something
@ -78,111 +87,158 @@ You just need to add a condition to perform an update.
## Remove rows ## Remove rows
```php
$db->table('toto')->lowerThan('column1', 10)->remove(); $db->table('toto')->lowerThan('column1', 10)->remove();
```
## Sorting ## Sorting
```php
$db->table('toto')->asc('column1')->findAll(); $db->table('toto')->asc('column1')->findAll();
```
or or
```php
$db->table('toto')->desc('column1')->findAll(); $db->table('toto')->desc('column1')->findAll();
```
## Limit and offset ## Limit and offset
```php
$db->table('toto')->limit(10)->offset(5)->findAll(); $db->table('toto')->limit(10)->offset(5)->findAll();
```
## Fetch only some columns ## Fetch only some columns
```php
$db->table('toto')->columns('column1', 'column2')->findAll(); $db->table('toto')->columns('column1', 'column2')->findAll();
```
## Conditions ## Conditions
### Equals condition ### Equals condition
```php
$db->table('toto') $db->table('toto')
->equals('column1', 'hey') ->equals('column1', 'hey')
->findAll(); ->findAll();
```
or or
```php
$db->table('toto') $db->table('toto')
->eq('column1', 'hey') ->eq('column1', 'hey')
->findAll(); ->findAll();
```
Yout got: 'SELECT * FROM toto WHERE column1=?' Yout got: 'SELECT * FROM toto WHERE column1=?'
### IN condition ### IN condition
```php
$db->table('toto') $db->table('toto')
->in('column1', ['hey', 'bla']) ->in('column1', ['hey', 'bla'])
->findAll(); ->findAll();
```
### Like condition ### Like condition
Case-sensitive (only Mysql and Postgres):
```php
$db->table('toto') $db->table('toto')
->like('column1', '%hey%') ->like('column1', '%Foo%')
->findAll(); ->findAll();
```
Not case-sensitive:
```php
$db->table('toto')
->ilike('column1', '%foo%')
->findAll();
```
### Lower than ### Lower than
```php
$db->table('toto') $db->table('toto')
->lowerThan('column1', 2) ->lowerThan('column1', 2)
->findAll(); ->findAll();
```
or or
```php
$db->table('toto') $db->table('toto')
->lt('column1', 2) ->lt('column1', 2)
->findAll(); ->findAll();
```
### Lower than or equals ### Lower than or equals
```php
$db->table('toto') $db->table('toto')
->lowerThanOrEquals('column1', 2) ->lowerThanOrEquals('column1', 2)
->findAll(); ->findAll();
```
or or
```php
$db->table('toto') $db->table('toto')
->lte('column1', 2) ->lte('column1', 2)
->findAll(); ->findAll();
```
### Greater than ### Greater than
```php
$db->table('toto') $db->table('toto')
->greaterThan('column1', 3) ->greaterThan('column1', 3)
->findAll(); ->findAll();
```
or or
```php
$db->table('toto') $db->table('toto')
->gt('column1', 3) ->gt('column1', 3)
->findAll(); ->findAll();
```
### Greater than or equals ### Greater than or equals
```php
$db->table('toto') $db->table('toto')
->greaterThanOrEquals('column1', 3) ->greaterThanOrEquals('column1', 3)
->findAll(); ->findAll();
```
or or
```php
$db->table('toto') $db->table('toto')
->gte('column1', 3) ->gte('column1', 3)
->findAll(); ->findAll();
```
### Multiple conditions ### Multiple conditions
Each condition is joined by a AND. Each condition is joined by a AND.
```php
$db->table('toto') $db->table('toto')
->like('column2', '%toto') ->like('column2', '%toto')
->gte('column1', 3) ->gte('column1', 3)
->findAll(); ->findAll();
```
How to make a OR condition: How to make a OR condition:
```php
$db->table('toto') $db->table('toto')
->beginOr() ->beginOr()
->like('column2', '%toto') ->like('column2', '%toto')
@ -190,6 +246,7 @@ How to make a OR condition:
->closeOr() ->closeOr()
->eq('column5', 'titi') ->eq('column5', 'titi')
->findAll(); ->findAll();
```
## Schema migrations ## Schema migrations
@ -201,6 +258,7 @@ How to make a OR condition:
Example: Example:
```php
namespace Schema; namespace Schema;
function version_1($pdo) function version_1($pdo)
@ -225,6 +283,7 @@ Example:
) )
'); ');
} }
```
### Run schema update automatically ### Run schema update automatically
@ -235,6 +294,7 @@ Example:
Example: Example:
```php
$last_schema_version = 5; $last_schema_version = 5;
$db = new PicoDb\Database(array( $db = new PicoDb\Database(array(
@ -250,11 +310,13 @@ Example:
die('Unable to migrate database schema.'); die('Unable to migrate database schema.');
} }
```
### Use a singleton to handle database instances ### Use a singleton to handle database instances
Setup a new instance: Setup a new instance:
```php
PicoDb\Database::bootstrap('myinstance', function() { PicoDb\Database::bootstrap('myinstance', function() {
$db = new PicoDb\Database(array( $db = new PicoDb\Database(array(
@ -269,7 +331,10 @@ Setup a new instance:
die('Unable to migrate database schema.'); die('Unable to migrate database schema.');
} }
}); });
```
Get this instance anywhere in your code: Get this instance anywhere in your code:
```php
PicoDb\Database::get('myinstance')->table(...) PicoDb\Database::get('myinstance')->table(...)
```

View File

@ -38,7 +38,6 @@ class Mysql extends PDO
} }
} }
public function getSchemaVersion() public function getSchemaVersion()
{ {
$this->exec("CREATE TABLE IF NOT EXISTS `".$this->schema_table."` (`version` INT DEFAULT '0')"); $this->exec("CREATE TABLE IF NOT EXISTS `".$this->schema_table."` (`version` INT DEFAULT '0')");
@ -57,22 +56,29 @@ class Mysql extends PDO
return 0; return 0;
} }
public function setSchemaVersion($version) public function setSchemaVersion($version)
{ {
$rq = $this->prepare('UPDATE `'.$this->schema_table.'` SET `version`=?'); $rq = $this->prepare('UPDATE `'.$this->schema_table.'` SET `version`=?');
$rq->execute(array($version)); $rq->execute(array($version));
} }
public function getLastId() public function getLastId()
{ {
return $this->lastInsertId(); return $this->lastInsertId();
} }
public function escapeIdentifier($value) public function escapeIdentifier($value)
{ {
return '`'.$value.'`'; return '`'.$value.'`';
} }
public function operatorLikeCaseSensitive()
{
return 'LIKE BINARY';
}
public function operatorLikeNotCaseSensitive()
{
return 'LIKE';
}
} }

View File

@ -9,7 +9,6 @@ class Postgres extends PDO
{ {
private $schema_table = 'schema_version'; private $schema_table = 'schema_version';
public function __construct(array $settings) public function __construct(array $settings)
{ {
$required_atttributes = array( $required_atttributes = array(
@ -34,7 +33,6 @@ class Postgres extends PDO
} }
} }
public function getSchemaVersion() public function getSchemaVersion()
{ {
$this->exec("CREATE TABLE IF NOT EXISTS ".$this->schema_table." (version SMALLINT DEFAULT 0)"); $this->exec("CREATE TABLE IF NOT EXISTS ".$this->schema_table." (version SMALLINT DEFAULT 0)");
@ -53,14 +51,12 @@ class Postgres extends PDO
return 0; return 0;
} }
public function setSchemaVersion($version) public function setSchemaVersion($version)
{ {
$rq = $this->prepare('UPDATE '.$this->schema_table.' SET version=?'); $rq = $this->prepare('UPDATE '.$this->schema_table.' SET version=?');
$rq->execute(array($version)); $rq->execute(array($version));
} }
public function getLastId() public function getLastId()
{ {
$rq = $this->prepare('SELECT LASTVAL()'); $rq = $this->prepare('SELECT LASTVAL()');
@ -68,9 +64,18 @@ class Postgres extends PDO
return $rq->fetchColumn(); return $rq->fetchColumn();
} }
public function escapeIdentifier($value) public function escapeIdentifier($value)
{ {
return $value; return $value;
} }
public function operatorLikeCaseSensitive()
{
return 'LIKE';
}
public function operatorLikeNotCaseSensitive()
{
return 'ILIKE';
}
} }

View File

@ -24,7 +24,6 @@ class Sqlite extends PDO
$this->exec('PRAGMA foreign_keys = ON'); $this->exec('PRAGMA foreign_keys = ON');
} }
public function getSchemaVersion() public function getSchemaVersion()
{ {
$rq = $this->prepare('PRAGMA user_version'); $rq = $this->prepare('PRAGMA user_version');
@ -38,21 +37,28 @@ class Sqlite extends PDO
return 0; return 0;
} }
public function setSchemaVersion($version) public function setSchemaVersion($version)
{ {
$this->exec('PRAGMA user_version='.$version); $this->exec('PRAGMA user_version='.$version);
} }
public function getLastId() public function getLastId()
{ {
return $this->lastInsertId(); return $this->lastInsertId();
} }
public function escapeIdentifier($value) public function escapeIdentifier($value)
{ {
return '"'.$value.'"'; return '"'.$value.'"';
} }
public function operatorLikeCaseSensitive()
{
return 'LIKE';
}
public function operatorLikeNotCaseSensitive()
{
return 'LIKE';
}
} }

View File

@ -376,7 +376,19 @@ class Table
break; break;
case 'like': case 'like':
$sql = sprintf('%s LIKE ?', $this->db->escapeIdentifier($column)); $sql = sprintf(
'%s %s ?',
$this->db->escapeIdentifier($column),
$this->db->getConnection()->operatorLikeCaseSensitive()
);
break;
case 'ilike':
$sql = sprintf(
'%s %s ?',
$this->db->escapeIdentifier($column),
$this->db->getConnection()->operatorLikeNotCaseSensitive()
);
break; break;
case 'eq': case 'eq':

View File

@ -151,6 +151,12 @@ Response\xml('<xml ... >');
Response\binary($my_file_content); Response\binary($my_file_content);
``` ```
### Send a raw response (no content-type)
```php
Response\raw($content);
```
### Force browser download ### Force browser download
```php ```php

View File

@ -90,6 +90,14 @@ function js($data, $status_code = 200)
} }
function raw($data, $status_code = 200)
{
status($status_code);
echo $data;
exit;
}
function binary($data, $status_code = 200) function binary($data, $status_code = 200)
{ {
status($status_code); status($status_code);