forked from zachleigh/yarak
-
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.
- Loading branch information
Showing
48 changed files
with
9,187 additions
and
182 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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/vendor | ||
.env | ||
|
||
tests/_output/* |
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
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,15 @@ | ||
<?php | ||
/** | ||
* The app directory is here for testing purposes only. | ||
* This file bootstraps the Codeception test suite. | ||
*/ | ||
|
||
$config = include __DIR__ . '/config.php'; | ||
|
||
include __DIR__ . '/loader.php'; | ||
|
||
$di = new \Phalcon\DI\FactoryDefault(); | ||
|
||
include __DIR__ . '/services.php'; | ||
|
||
return new \Phalcon\Mvc\Application($di); |
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,30 @@ | ||
<?php | ||
/* | ||
* Modified: prepend directory path of current file, because of this file own different ENV under between Apache and command line. | ||
* NOTE: please remove this comment. | ||
*/ | ||
defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..')); | ||
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app'); | ||
|
||
return new \Phalcon\Config([ | ||
'database' => [ | ||
'adapter' => 'Mysql', | ||
'host' => '127.0.0.1', | ||
'username' => 'root', | ||
'password' => 'password', | ||
'dbname' => 'yarak', | ||
'charset' => 'utf8', | ||
], | ||
'application' => [ | ||
'appDir' => APP_PATH . '/', | ||
'controllersDir' => APP_PATH . '/controllers/', | ||
'modelsDir' => APP_PATH . '/models/', | ||
'migrationsDir' => APP_PATH . '/database/migrations/', | ||
'viewsDir' => APP_PATH . '/views/', | ||
'pluginsDir' => APP_PATH . '/plugins/', | ||
'servicesDir' => APP_PATH . '/services/', | ||
'cacheDir' => BASE_PATH . '/cache/', | ||
'formsDir' => APP_PATH . '/forms', | ||
'baseUri' => '/', | ||
] | ||
]); |
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,17 @@ | ||
<?php | ||
|
||
use Phalcon\Loader; | ||
use Phalcon\Di\FactoryDefault; | ||
|
||
$loader = new Loader(); | ||
|
||
$loader->registerNamespaces([ | ||
'App\Models' => APP_PATH.'/models', | ||
]); | ||
|
||
$loader->register(); | ||
|
||
/** | ||
* Composer | ||
*/ | ||
// require_once BASE_PATH . '/vendor/autoload.php'; |
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,134 @@ | ||
<?php | ||
|
||
use Yarak\Kernel; | ||
use Phalcon\Mvc\View; | ||
use Phalcon\Security; | ||
use Sonohini\Acl\Acl; | ||
use Sonohini\Auth\Auth; | ||
use Phalcon\Mvc\Dispatcher; | ||
use Elasticsearch\ClientBuilder; | ||
use Phalcon\Flash\Direct as Flash; | ||
use Phalcon\Mvc\Url as UrlResolver; | ||
use Phalcon\Mvc\View\Engine\Php as PhpEngine; | ||
use Phalcon\Mvc\View\Engine\Volt as VoltEngine; | ||
use Phalcon\Mvc\Model\Manager as ModelsManager; | ||
use Phalcon\Session\Adapter\Files as SessionAdapter; | ||
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter; | ||
|
||
$di->setShared('config', function () { | ||
return include APP_PATH.'/config/config.php'; | ||
}); | ||
|
||
$di->setShared('url', function () { | ||
$config = $this->getConfig(); | ||
|
||
$url = new UrlResolver(); | ||
$url->setBaseUri($config->application->baseUri); | ||
|
||
return $url; | ||
}); | ||
|
||
$di->setShared('view', function () { | ||
$config = $this->getConfig(); | ||
|
||
$view = new View(); | ||
$view->setDI($this); | ||
$view->setViewsDir($config->application->viewsDir); | ||
|
||
$view->registerEngines([ | ||
'.volt' => function ($view) { | ||
$config = $this->getConfig(); | ||
|
||
$volt = new VoltEngine($view, $this); | ||
|
||
$volt->setOptions([ | ||
'compiledPath' => $config->application->cacheDir, | ||
'compiledSeparator' => '_', | ||
]); | ||
|
||
return $volt; | ||
}, | ||
'.phtml' => PhpEngine::class, | ||
|
||
]); | ||
|
||
return $view; | ||
}); | ||
|
||
$di->setShared('db', function () { | ||
$config = $this->getConfig(); | ||
|
||
$class = 'Phalcon\Db\Adapter\Pdo\\'.$config->database->adapter; | ||
|
||
$params = [ | ||
'host' => $config->database->host, | ||
'username' => $config->database->username, | ||
'password' => $config->database->password, | ||
'dbname' => $config->database->dbname, | ||
'charset' => $config->database->charset, | ||
]; | ||
|
||
if ($config->database->adapter == 'Postgresql') { | ||
unset($params['charset']); | ||
} | ||
|
||
$connection = new $class($params); | ||
|
||
$connection->setNestedTransactionsWithSavepoints(true); | ||
|
||
return $connection; | ||
}); | ||
|
||
$di->setShared('modelsMetadata', function () { | ||
return new MetaDataAdapter(); | ||
}); | ||
|
||
$di->set('flash', function () { | ||
return new Flash([ | ||
'error' => 'alert alert-danger', | ||
'success' => 'alert alert-success', | ||
'notice' => 'alert alert-info', | ||
'warning' => 'alert alert-warning', | ||
]); | ||
}); | ||
|
||
$di->set('session', function () { | ||
$session = new SessionAdapter(); | ||
$session->start(); | ||
|
||
return $session; | ||
}); | ||
|
||
$di->set('dispatcher', function () { | ||
$dispatcher = new Dispatcher(); | ||
$dispatcher->setDefaultNamespace('Sonohini\Controllers'); | ||
|
||
return $dispatcher; | ||
}); | ||
|
||
$di->set('security', function () { | ||
return new Security(); | ||
}); | ||
|
||
$di->set('modelsManager', function() { | ||
return new ModelsManager(); | ||
}); | ||
|
||
$di->setShared('yarak', function () { | ||
$config = $this->getConfig(); | ||
|
||
return new Kernel([ | ||
'application' => [ | ||
'databaseDir' => APP_PATH.'/database/', | ||
], | ||
'database' => [ | ||
'adapter' => $config->database->adapter, | ||
'host' => $config->database->host, | ||
'username' => $config->database->username, | ||
'password' => $config->database->password, | ||
'dbname' => $config->database->dbname, | ||
'charset' => $config->database->charset, | ||
], | ||
]); | ||
}); | ||
|
36 changes: 36 additions & 0 deletions
36
app/database/migrations/2017_03_13_224917_create_test_table.php
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,36 @@ | ||
<?php | ||
|
||
use Phalcon\Db\Index; | ||
use Phalcon\Db\Column; | ||
use Phalcon\Db\Reference; | ||
use Phalcon\Db\Adapter\Pdo; | ||
use Yarak\Migrations\Migration; | ||
|
||
class CreateTestTable implements Migration | ||
{ | ||
/** | ||
* Run the migration. | ||
* | ||
* @param Pdo $connection | ||
*/ | ||
public function up(Pdo $connection) | ||
{ | ||
$connection->createTable( | ||
'test', | ||
null, | ||
[ | ||
// | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Reverse the migration. | ||
* | ||
* @param Pdo $connection | ||
*/ | ||
public function down(Pdo $connection) | ||
{ | ||
$connection->dropTable('test'); | ||
} | ||
} |
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 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Phalcon\Mvc\Model; | ||
|
||
class Posts extends Model | ||
{ | ||
public function initialize() | ||
{ | ||
$this->hasOne( | ||
'users_id', | ||
'App\Models\Users', | ||
'id', | ||
['alias' => 'users'] | ||
); | ||
} | ||
} |
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 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Phalcon\Mvc\Model; | ||
|
||
class Users extends Model | ||
{ | ||
public function initialize() | ||
{ | ||
$this->hasMany( | ||
'id', | ||
'App\Models\Posts', | ||
'users_id', | ||
['alias' => 'posts'] | ||
); | ||
} | ||
} |
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,21 @@ | ||
actor: Tester | ||
paths: | ||
tests: tests | ||
log: tests/_output | ||
data: tests/_data | ||
support: tests/_support | ||
envs: tests/_envs | ||
settings: | ||
bootstrap: _bootstrap.php | ||
colors: true | ||
memory_limit: 1024M | ||
extensions: | ||
enabled: | ||
- Codeception\Extension\RunFailed | ||
modules: | ||
config: | ||
Db: | ||
dsn: 'mysql:host=127.0.0.1;dbname=yarak' | ||
user: 'root' | ||
password: 'password' | ||
dump: tests/_data/dump.sql |
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
Oops, something went wrong.