Skip to content

Commit c55ddf8

Browse files
committed
Initial commit, added support for hstore, uuid
0 parents  commit c55ddf8

File tree

19 files changed

+387
-0
lines changed

19 files changed

+387
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- hhvm
9+
10+
before_script:
11+
- composer self-update
12+
- composer install --prefer-source --no-interaction --dev
13+
14+
script: phpunit

composer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "bosnadev/foundation",
3+
"description": "",
4+
"authors": [
5+
{
6+
"name": "Mirza Pasic",
7+
"email": "mirza.pasic@edu.fit.ba"
8+
}
9+
],
10+
"require": {
11+
"php": ">=5.4.0",
12+
"illuminate/support": "4.2.*"
13+
},
14+
"autoload": {
15+
"classmap": [
16+
"src/migrations"
17+
],
18+
"psr-0": {
19+
"Bosnadev\\Foundation\\": "src/"
20+
}
21+
},
22+
"minimum-stability": "stable"
23+
}

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

public/.gitkeep

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php namespace Bosnadev\Foundation\Database;
2+
3+
/**
4+
* Class Connection
5+
* @package Bosnadev\Foundation\Database
6+
*/
7+
class Connection extends \Illuminate\Database\Connection {
8+
9+
/**
10+
* Get a schema builder instance for the connection.
11+
*
12+
* @return Schema\Builder
13+
*/
14+
public function getSchemaBuilder()
15+
{
16+
if (is_null($this->schemaGrammar)) { $this->useDefaultSchemaGrammar(); }
17+
18+
return new Schema\Builder($this);
19+
}
20+
21+
/**
22+
*
23+
*/
24+
public function useDefaultSchemaGrammar()
25+
{
26+
$this->schemaGrammar = $this->getDefaultSchemaGrammar();
27+
}
28+
29+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php namespace Bosnadev\Foundation\Database\Connectors;
2+
3+
use PDO;
4+
use Illuminate\Container\Container;
5+
use Illuminate\Database\MySqlConnection;
6+
use Illuminate\Database\SQLiteConnection;
7+
use Illuminate\Database\SqlServerConnection;
8+
use Bosnadev\Foundation\Database\PostgresConnection;
9+
10+
/**
11+
* Class ConnectionFactory
12+
* @package Bosnadev\Foundation\Database\Connectors
13+
*/
14+
class ConnectionFactory extends \Illuminate\Database\Connectors\ConnectionFactory {
15+
16+
/**
17+
* @param string $driver
18+
* @param PDO $connection
19+
* @param string $database
20+
* @param string $prefix
21+
* @param array $config
22+
* @return PostgresConnection|MySqlConnection|SQLiteConnection|SqlServerConnection|mixed|object
23+
* @throws \InvalidArgumentException
24+
*/
25+
protected function createConnection($driver, PDO $connection, $database, $prefix = '', array $config = array())
26+
{
27+
if ($this->container->bound($key = "db.connection.{$driver}"))
28+
{
29+
return $this->container->make($key, array($connection, $database, $prefix, $config));
30+
}
31+
32+
switch ($driver)
33+
{
34+
case 'mysql':
35+
return new MySqlConnection($connection, $database, $prefix, $config);
36+
37+
case 'pgsql':
38+
return new PostgresConnection($connection, $database, $prefix, $config);
39+
40+
case 'sqlite':
41+
return new SQLiteConnection($connection, $database, $prefix, $config);
42+
43+
case 'sqlsrv':
44+
return new SqlServerConnection($connection, $database, $prefix, $config);
45+
}
46+
47+
throw new \InvalidArgumentException("Unsupported driver [$driver]");
48+
}
49+
50+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php namespace Bosnadev\Foundation\Database;
2+
3+
use Illuminate\Database\Eloquent\Model;
4+
use Illuminate\Support\ServiceProvider;
5+
use Bosnadev\Foundation\Database\Connectors\ConnectionFactory;
6+
use Illuminate\Database\DatabaseManager;
7+
8+
/**
9+
* Class DatabaseServiceProvider
10+
* @package Bosnadev\Foundation\Database
11+
*/
12+
class DatabaseServiceProvider extends \Illuminate\Database\DatabaseServiceProvider {
13+
14+
/**
15+
* Register the service provider.
16+
*
17+
* @return void
18+
*/
19+
public function register()
20+
{
21+
// The connection factory is used to create the actual connection instances on
22+
// the database. We will inject the factory into the manager so that it may
23+
// make the connections while they are actually needed and not of before.
24+
$this->app->bindShared('db.factory', function($app)
25+
{
26+
return new ConnectionFactory($app);
27+
});
28+
29+
// The database manager is used to resolve various connections, since multiple
30+
// connections might be managed. It also implements the connection resolver
31+
// interface which may be used by other components requiring connections.
32+
$this->app->bindShared('db', function($app)
33+
{
34+
return new DatabaseManager($app, $app['db.factory']);
35+
});
36+
}
37+
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php namespace Bosnadev\Foundation\Database;
2+
3+
/**
4+
* Class PostgresConnection
5+
*
6+
* @package Bosnadev\Foundation\Database
7+
*/
8+
class PostgresConnection extends Connection {
9+
10+
/**
11+
* Get the default query grammar instance.
12+
*
13+
* @return \Illuminate\Database\Grammar
14+
*/
15+
protected function getDefaultQueryGrammar()
16+
{
17+
return $this->withTablePrefix(new \Illuminate\Database\Query\Grammars\PostgresGrammar);
18+
}
19+
20+
21+
/**
22+
* Get the default schema grammar instance.
23+
*
24+
* @return \Illuminate\Database\Grammar
25+
*/
26+
protected function getDefaultSchemaGrammar()
27+
{
28+
return $this->withTablePrefix(new Schema\Grammars\PostgresGrammar);
29+
}
30+
31+
32+
/**
33+
* Get the default post processor instance.
34+
*
35+
* @return \Illuminate\Database\Query\Processors\PostgresProcessor
36+
*/
37+
protected function getDefaultPostProcessor()
38+
{
39+
return new \Illuminate\Database\Query\Processors\PostgresProcessor;
40+
}
41+
42+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php namespace Bosnadev\Foundation\Database\Schema;
2+
3+
/**
4+
* Class Blueprint
5+
* @package Bosnadev\Foundation\Database\Schema
6+
*/
7+
class Blueprint extends \Illuminate\Database\Schema\Blueprint
8+
{
9+
10+
/**
11+
* Create a new character column on the table.
12+
*
13+
* @param string $column
14+
* @param int $length
15+
* @return \Illuminate\Support\Fluent
16+
*/
17+
public function character($column, $length = 255)
18+
{
19+
return $this->addColumn('character', $column, compact('length'));
20+
}
21+
22+
/**
23+
* @param $column
24+
* @return \Illuminate\Support\Fluent
25+
*/
26+
public function hstore($column) {
27+
return $this->addColumn('hstore', $column);
28+
}
29+
30+
/**
31+
* @param $column
32+
* @return \Illuminate\Support\Fluent
33+
*/
34+
public function uuid($column) {
35+
return $this->addColumn('uuid', $column);
36+
}
37+
}

0 commit comments

Comments
 (0)