예제 #1
0
 /**
  * Initialize testing environment
  *
  * @return void
  */
 public static function init()
 {
     if (is_file(__DIR__ . '/config/.env')) {
         Dotenv::load(['filepath' => __DIR__ . '/config/.env', 'toEnv' => true]);
     }
     // Define application environment
     if (!isset($_ENV['WELLCART_APPLICATION_ENV'])) {
         $_ENV['WELLCART_APPLICATION_ENV'] = getenv('WELLCART_APPLICATION_ENV') ?: 'testing';
     }
     // Load the user-defined test configuration file, if it exists; otherwise, load
     if (is_readable(__DIR__ . '/config/application.config.php')) {
         $testConfig = __DIR__ . '/config/application.config.php';
     } else {
         $testConfig = __DIR__ . '/config/application.config.php.dist';
     }
     static::initAutoloader();
     defined('WELLCART_ROOT') || define('WELLCART_ROOT', getenv('WELLCART_ROOT') ? getenv('WELLCART_ROOT') : str_replace('\\', '/', __DIR__) . '/');
     defined('WELLCART_BIN_PATH') || define('WELLCART_BIN_PATH', getenv('WELLCART_BIN_PATH') ? getenv('WELLCART_BIN_PATH') : static::findParentPath('bin'));
     defined('WELLCART_PUBLIC_PATH') || define('WELLCART_PUBLIC_PATH', static::findParentPath('public'));
     // Define application context
     if (!is_file(WELLCART_ROOT . 'config/autoload/installed.php')) {
         $_ENV['WELLCART_APPLICATION_CONTEXT'] = Application::CONTEXT_SETUP;
     } elseif (empty($_ENV['WELLCART_APPLICATION_CONTEXT'])) {
         $_ENV['WELLCART_APPLICATION_CONTEXT'] = Application::CONTEXT_GLOBAL;
     }
     /**
      * Setup initial PHP environment
      */
     PHPEnvironment::initialize();
     $app = Application::init(Config::application(include $testConfig));
     application($app);
 }
예제 #2
0
function loadDotEnv($dir = __DIR__)
{
    /**
     * alternatively, Dotenv::load(dirname(__DIR__) . DIRECTORY_SEPARATOR . '.env');
     */
    Dotenv::load(['filepath' => dirname($dir) . DIRECTORY_SEPARATOR . '.env', 'toEnv' => true]);
}
예제 #3
0
 /**
  * {@inheritdoc}
  */
 protected function configure()
 {
     $dotEnvPath = dirname(dirname(__DIR__)) . '/.env';
     if (file_exists($dotEnvPath) && is_readable($dotEnvPath)) {
         Dotenv::load(['filepath' => $dotEnvPath, 'toEnv' => true]);
     }
     $this->install(new PackageModule());
     $this->bind(ClientInterface::class)->to(Client::class);
     $this->bind(GlobeApiClientInterface::class)->to(GlobeApiClient::class);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 protected function configure()
 {
     Dotenv::load(['filepath' => dirname(dirname(__DIR__)) . '/.env', 'expect' => ['DB_DSN', 'DB_USER', 'DB_PASS'], 'toEnv' => true]);
     $this->install(new PackageModule());
     $this->install(new DbAppPackage($_ENV['DB_DSN'], $_ENV['DB_USER'], $_ENV['DB_PASS'], $_ENV['DB_READ']));
     $this->bind('Doctrine\\ORM\\EntityManager')->annotatedWith("manager")->toProvider('InakaPhper\\Lunchlog\\Module\\Provider\\DoctrineORMProvider');
     // Entity
     $this->bind('InakaPhper\\Lunchlog\\Entity\\Shop')->annotatedWith("shop")->toInstance(new Shop());
     $this->bind('InakaPhper\\Lunchlog\\Entity\\Menu')->annotatedWith("menu")->toInstance(new Menu());
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 protected function configure()
 {
     $dotEnvPath = dirname(dirname(__DIR__)) . '/.env';
     if (file_exists($dotEnvPath) && is_readable($dotEnvPath)) {
         Dotenv::load(['filepath' => $dotEnvPath, 'toEnv' => true]);
     }
     $this->install(new PackageModule());
     $this->bind(ClientInterface::class)->to(Client::class);
     $this->bind(ChatWorkApiClientInterface::class)->to(ChatWorkApiClient::class);
     $this->bind(SchemeCollectionInterface::class)->toProvider(SchemeCollectionProvider::class);
     $this->bind(ResourceInterface::class)->to(Resource::class);
 }
예제 #6
0
<?php

use josegonzalez\Dotenv\Loader as Dotenv;
require dirname(__DIR__) . '/vendor/autoload.php';
Dotenv::load(['filepath' => dirname(__DIR__) . '/.env', 'expect' => ['DB_DSN', 'DB_USER'], 'toEnv' => true]);
preg_match("/(.*?):(.*)/", $_ENV['DB_DSN'], $parts);
$type = $parts[1];
preg_match("/host=(\\w+)/", $_ENV['DB_DSN'], $parts);
$host = $parts[1];
preg_match("/dbname=(\\w+)/", $_ENV['DB_DSN'], $parts);
$dbName = $parts[1];
$dsn = sprintf('%s:host=%s', $type, $host);
try {
    $pdo = new \PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASS']);
    $pdo->exec("CREATE DATABASE IF NOT EXISTS {$dbName}");
    $pdo->exec("CREATE DATABASE IF NOT EXISTS {$dbName}_test");
    error_log("Database [{$dbName}] and [{$dbName}_test] are created.");
} catch (PDOException $e) {
    echo $e->getMessage() . PHP_EOL;
    exit(1);
}
예제 #7
0
<?php

use josegonzalez\Dotenv\Loader as Dotenv;
use Radar\Adr\Boot;
use Relay\Middleware\ExceptionHandler;
use Relay\Middleware\ResponseSender;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
require_once '../db.php';
/**
 * Bootstrapping
 */
require '../vendor/autoload.php';
Dotenv::load(['filepath' => dirname(__DIR__) . DIRECTORY_SEPARATOR . '.env', 'toEnv' => true]);
$boot = new Boot();
$adr = $boot->adr();
/**
 * Middleware
 */
$adr->middle(new ResponseSender());
$adr->middle(new ExceptionHandler(new Response()));
$adr->middle('Radar\\Adr\\Handler\\RoutingHandler');
$adr->middle('Radar\\Adr\\Handler\\ActionHandler');
/**
 * Routes
 */
// Just gets all the names of users in the database
$adr->get('AllUserNames', '/allUserNames', function (array $input) {
    global $conn;
    // the database connection I know globals are bad but I'm pretty new at this
    $sql = "SELECT `name` FROM `user`";
예제 #8
0
<?php

use josegonzalez\Dotenv\Loader as Dotenv;
Dotenv::load(['filepath' => dirname(dirname(__DIR__)) . '/.env', 'toEnv' => true]);
$pdo = new PDO($_ENV['DB_DSN'], $_ENV['DB_USER'], $_ENV['DB_PASS']);
preg_match("/dbname=(\\w+)/i", $_ENV['DB_DSN'], $parts);
$name = $parts[1];
return ["paths" => ["migrations" => __DIR__], "environments" => ["default_migration_table" => "phinxlog", "default_database" => "default", "default" => ["name" => $name, "connection" => $pdo], "test" => ["name" => $name . '_test', "connection" => $pdo]]];
예제 #9
0
<?php

use josegonzalez\Dotenv\Loader as DotenvLoader;
use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;
/**
 * @var Composer\Autoload\ClassLoader
 */
$loader = (require __DIR__ . '/../app/autoload.php');
// include_once __DIR__.'/../app/bootstrap.php.cache';
DotenvLoader::load(['filepath' => __DIR__ . '/../.env', 'putenv' => true, 'toEnv' => true, 'toServer' => true]);
if ('prod' === $_SERVER['SYMFONY_ENV'] && extension_loaded('apc')) {
    $apcLoader = new ApcClassLoader(sha1(__FILE__), $loader);
    $loader->unregister();
    $apcLoader->register(true);
}
if ('dev' === $_SERVER['SYMFONY_ENV']) {
    Debug::enable();
}
$kernel = new AppKernel($_SERVER['SYMFONY_ENV'], (bool) $_SERVER['SYMFONY_DEBUG']);
// $kernel->loadClassCache();
if ('prod' === $_SERVER['SYMFONY_ENV'] && true === (bool) $_SERVER['SYMFONY___USE_REVERSE_PROXY']) {
    $kernel = new AppCache($kernel);
    Request::enableHttpMethodParameterOverride();
}
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);