예제 #1
0
 protected function getEnv()
 {
     try {
         $loader = new Loader('.env');
         $loader->parse()->putenv(true);
     } catch (\InvalidArgumentException $e) {
         //ignore
     }
     return ["GLOBAL_CLIENT_ID" => getenv('GLOBAL_CLIENT_ID'), "GLOBAL_CLIENT_SECRET" => getenv('GLOBAL_CLIENT_SECRET'), "APP_CLIENT_ID" => getenv('APP_CLIENT_ID'), "APP_CLIENT_SECRET" => getenv('APP_CLIENT_SECRET'), "DOMAIN" => getenv('DOMAIN')];
 }
예제 #2
0
파일: env.php 프로젝트: ysupr/lifehack
<?php

/**
 * Created by PhpStorm.
 * User: yogasukma
 * Date: 12/22/15
 * Time: 2:39 PM
 */
use josegonzalez\Dotenv\Loader;
$env = new Loader(__DIR__ . "/../.env");
$env->parse()->putenv(TRUE);
 /**
  * Changes the access level for a ShootProof gallery (event)
  *
  * If no event option is specified and a .shootproof file exists in the
  * directory, then event will be read from that file.
  *
  * @param string $dir The directory to process
  * @param Options $baseOptions
  * @param OptionsFactory $optionsFactory
  */
 protected function processDirectory($dir, Options $baseOptions, OptionsFactory $optionsFactory)
 {
     // Reload the options and read the directory config file
     $options = $optionsFactory->newInstance([], $this->getValidators());
     $configPath = new TildeExpander($dir) . '/.shootproof';
     $configLoader = new DotenvLoader((string) $configPath);
     try {
         $configData = $configLoader->parse()->toArray();
         $options->loadOptionData($configData, false);
         // don't overwrite CLI data
         $this->logger->addDebug('ShootProof settings file found', [$configPath, $configData]);
     } catch (\InvalidArgumentException $e) {
         // ignore
         $this->logger->addDebug('ShootProof settings file not found', [$configPath]);
     }
     // Make sure all required options are present
     $options->validateAllRequired();
     $options->validate('password', $options->password);
     // Set the event access level
     $this->logger->addNotice('Setting access level', ['event' => $options->event, 'level' => $options->accessLevel, 'password' => $options->password ? str_repeat('*', strlen($options->password)) : null]);
     if (!$baseOptions->preview) {
         $result = $this->api->setEventAccessLevel($options->event, $options->accessLevel, $options->password);
         $this->logger->addDebug('Operation completed', $result);
     }
 }
예제 #4
0
파일: env.php 프로젝트: themogwi/app
<?php

use Cake\Utility\Hash;
use josegonzalez\Dotenv\Loader;
$config = [];
if (!env('APP_NAME')) {
    $dotenv = new Loader([__DIR__ . DS . '.env', __DIR__ . DS . '.env.default']);
    $dotenv->setFilters(['josegonzalez\\Dotenv\\Filter\\LowercaseKeyFilter', 'josegonzalez\\Dotenv\\Filter\\UppercaseFirstKeyFilter', 'josegonzalez\\Dotenv\\Filter\\UnderscoreArrayFilter', function ($data) {
        $keys = ['Debug' => 'debug', 'Emailtransport' => 'EmailTransport', 'Database' => 'Datasources.default', 'Test.database' => 'Datasources.test', 'Test' => null, 'Cache.duration' => null, 'Cache.cakemodel' => 'Cache._cake_model_', 'Cache.cakecore' => 'Cache._cake_core_'];
        foreach ($keys as $key => $newKey) {
            if ($newKey === null) {
                $data = Hash::remove($data, $key);
                continue;
            }
            $value = Hash::get($data, $key);
            $data = Hash::remove($data, $key);
            $data = Hash::insert($data, $newKey, $value);
        }
        return $data;
    }]);
    $dotenv->parse();
    $dotenv->filter();
    $config = $dotenv->toArray();
}
return $config;
예제 #5
0
<?php

namespace App;

use App\Command\HelloWorldCommand;
use Choccybiccy\Telegram\ApiClient;
use Choccybiccy\Telegram\CommandHandler;
use Choccybiccy\Telegram\Entity\Message;
use Choccybiccy\Telegram\Entity\Update;
use josegonzalez\Dotenv\Loader;
use Slim\Slim;
require_once "../vendor/autoload.php";
// Load the .env file if it exists.
if (file_exists(__DIR__ . "/../.env")) {
    $loader = new Loader("../.env");
    $loader->parse()->define();
}
/**
 * Create and inject the ApiClient into the Slim app.
 */
$app = new Slim();
$app->telegram = function () {
    return new ApiClient(TELEGRAM_BOT_AUTH_TOKEN);
};
/**
 * Here's the endpoint where Telegram will send it's updates to. Register your
 * commands in the CommandHandler in here.
 */
$app->post("/webhook", function () use($app) {
    /** @var Update $update */
    $update = $app->telegram->entityFromBody($app->request->getBody(), new Update());
예제 #6
0
 /**
  * Pushes (uploads) files to ShootProof from the specified local directory
  *
  * @param string $dir The directory to process
  * @param Options $baseOptions
  * @param OptionsFactory $optionsFactory
  */
 protected function processDirectory($dir, Options $baseOptions, OptionsFactory $optionsFactory)
 {
     // Reload the options and read the directory config file
     $options = $optionsFactory->newInstance([], $this->getValidators(), $this->getDefaults());
     $configPath = new TildeExpander($dir) . '/.shootproof';
     $configLoader = new DotenvLoader((string) $configPath);
     try {
         $configData = $configLoader->parse()->toArray();
         $options->loadOptionData($configData, false);
         // don't overwrite CLI data
         $this->logger->addDebug('Config file found', [$configPath, $configData]);
     } catch (\InvalidArgumentException $e) {
         // ignore
         $this->logger->addDebug('Config file not found', [$configPath]);
     }
     // Make sure all required options are present
     $options->validateAllRequired();
     // Get local file list
     $localFiles = array_map('basename', $this->getFileList($dir));
     $eventId = $options->event ? $options->event : null;
     $albumId = $options->album ? $options->album : null;
     // Get remote file list
     switch ($options->target) {
         case 'album':
             // Create the album
             if (!$albumId) {
                 list($eventId, $albumId) = $this->createAlbum($options, basename($dir));
             }
             $this->logger->addDebug('Fetching album photos', [$albumId]);
             if ($baseOptions->preview) {
                 $remoteFiles = new \ArrayObject();
             } else {
                 $remoteFiles = new ResultPager(function ($page) use($albumId) {
                     $response = $this->api->getAlbumPhotos($albumId, $page + 1);
                     return [(int) $response['total_pages'], $response['photos']];
                 });
             }
             break;
         case 'event':
             // Create the event
             if (!$eventId) {
                 $eventId = $this->createEvent($options, basename($dir));
             }
             $this->logger->addDebug('Fetching event photos', [$eventId]);
             if ($baseOptions->preview) {
                 $remoteFiles = new \ArrayObject();
             } else {
                 $remoteFiles = new ResultPager(function ($page) use($eventId) {
                     $response = $this->api->getEventPhotos($eventId, $page + 1);
                     return [(int) $response['total_pages'], $response['photos']];
                 });
             }
             break;
     }
     // Turn the response into an array of stringifiable objects so we can compare file names
     $remoteFiles = array_map([new ShootProofFile(), 'arrayFactory'], $remoteFiles->getArrayCopy());
     // Compute files to add, remove, and replace
     $calculator = new FileSetCalculator($localFiles, $remoteFiles, $options->replace);
     foreach ($calculator->add() as $file) {
         $filePath = $dir . DIRECTORY_SEPARATOR . $file;
         $this->logger->addNotice('Uploading new file to ShootProof', [$filePath]);
         if (!$baseOptions->preview) {
             $this->uploadFile($filePath, $eventId, $albumId, $options->retryLimit);
         }
     }
     foreach ($calculator->remove() as $file) {
         $this->logger->addNotice('Deleting remote file', [$file->getId(), (string) $file]);
         if (!$baseOptions->preview) {
             $this->deleteFile($file->getId(), $options->retryLimit);
         }
     }
     foreach ($calculator->replace() as $file) {
         $filePath = $dir . DIRECTORY_SEPARATOR . $file;
         $this->logger->addNotice('Replacing remote file', [$file->getId(), $filePath]);
         if (!$baseOptions->preview) {
             $this->updateFile($filePath, $file->getId(), $options->retryLimit);
         }
     }
     // Write ShootProof metadata to the directory
     try {
         $writer = new ConfigWriter(['target' => $options->target, 'event' => $eventId, 'album' => $albumId]);
         if (!$baseOptions->preview) {
             $writer->write($configPath);
         }
         $this->logger->addDebug('ShootProof settings file saved', [$configPath]);
     } catch (\InvalidArgumentException $e) {
         $this->logger->addWarning('ShootProof settings file is unwritable', [$configPath]);
     } catch (\RuntimeException $e) {
         $this->logger->addWarning('Failed writing ShootProof settings file', [$configPath]);
     }
 }
예제 #7
0
 /**
  * Pulls (downloads) files from ShootProof to the specified local directory
  *
  * @param string $dir The directory to process
  * @param Options $baseOptions
  * @param OptionsFactory $optionsFactory
  * @throws ValidatorException if event or album options are not provided
  */
 protected function processDirectory($dir, Options $baseOptions, OptionsFactory $optionsFactory)
 {
     // If the directory doesn't exist, create it and any parent dirs
     if (!file_exists($dir)) {
         if ($baseOptions->preview || @mkdir($dir, 0777, true)) {
             $this->logger->addNotice('Created directory', [$dir]);
         } else {
             $this->logger->addError('Failed to create directory', [$dir]);
             return;
         }
     }
     // Reload the options and read the directory config file
     $options = $optionsFactory->newInstance([], $this->getValidators(), $this->getDefaults());
     $configPath = new TildeExpander($dir) . '/.shootproof';
     $configLoader = new DotenvLoader((string) $configPath);
     try {
         $configData = $configLoader->parse()->toArray();
         $options->loadOptionData($configData, false);
         // don't overwrite CLI data
         $this->logger->addDebug('ShootProof settings file found', [$configPath, $configData]);
     } catch (\InvalidArgumentException $e) {
         // ignore
         $this->logger->addDebug('ShootProof settings file not found', [$configPath]);
     }
     // Make sure all required options are present
     $options->validateAllRequired();
     if (!$options->event && !$options->album) {
         throw new ValidatorException('Either --event or --album is required');
     }
     // Get local file list
     $localFiles = array_map('basename', $this->getFileList($dir));
     // Get remote file list
     switch ($options->target) {
         case 'album':
             $this->logger->addDebug('Fetching album photos', [$options->album]);
             $remoteFiles = new ResultPager(function ($page) use($options) {
                 $response = $this->api->getAlbumPhotos($options->album, $page + 1);
                 return [(int) $response['total_pages'], $response['photos']];
             });
             break;
         case 'event':
             $this->logger->addDebug('Fetching event photos', [$options->event]);
             $remoteFiles = new ResultPager(function ($page) use($options) {
                 $response = $this->api->getEventPhotos($options->event, $page + 1);
                 return [(int) $response['total_pages'], $response['photos']];
             });
             break;
     }
     // Turn the response into an array of stringifiable objects so we can compare file names
     $remoteFiles = array_map([new ShootProofFile(), 'arrayFactory'], $remoteFiles->getArrayCopy());
     // Compute files to add, remove, and replace
     $calculator = new FileSetCalculator($remoteFiles, $localFiles, $options->replace);
     foreach ($calculator->add() as $file) {
         // download
         $filePath = $dir . DIRECTORY_SEPARATOR . $file;
         $this->logger->addNotice('Downloading new file from ShootProof', [$filePath]);
         if (!$baseOptions->preview) {
             $this->downloadFile($file->getUrl('original'), $filePath, $baseOptions);
         }
     }
     foreach ($calculator->remove() as $file) {
         $filePath = $dir . DIRECTORY_SEPARATOR . $file;
         $this->logger->addNotice('Deleting local file', [$filePath]);
         if (!$baseOptions->preview) {
             @unlink($filePath);
         }
     }
     foreach ($calculator->replace() as $file) {
         $filePath = $dir . DIRECTORY_SEPARATOR . $file;
         $this->logger->addNotice('Replacing local file', [$filePath]);
         if (!$baseOptions->preview) {
             @unlink($filePath);
             $this->downloadFile($file->getUrl('original'), $filePath, $baseOptions);
         }
     }
     // Write ShootProof metadata to the directory
     try {
         $writer = new ConfigWriter(['target' => $options->target, $options->target => $options->{$options->target}]);
         if (!$baseOptions->preview) {
             $writer->write($configPath);
         }
         $this->logger->addDebug('ShootProof settings file saved', [$configPath]);
     } catch (\InvalidArgumentException $e) {
         $this->logger->addWarning('ShootProof settings file is unwritable', [$configPath]);
     } catch (\RuntimeException $e) {
         $this->logger->addWarning('Failed writing ShootProof settings file', [$configPath]);
     }
 }
예제 #8
0
 public function loadEnvironment()
 {
     $env = new Loader(getcwd() . '/../.env');
     return $env->parse()->prefix('APP_')->define();
 }
예제 #9
0
 /**
  * Creates and returns a new Options instance
  *
  * @param array $getopt Options data
  * @param array $validators Validators to validate the options
  * @param array $defaults Default values for the options
  * @return Options
  */
 public function newInstance(array $getopt = [], array $validators = [], array $defaults = [])
 {
     $this->error = null;
     // Extend the base config
     if (isset($this->config['getopt'])) {
         $getopt = array_merge($this->config['getopt'], $getopt);
     }
     if (isset($this->config['validators'])) {
         $validators = array_merge($this->config['validators'], $validators);
     }
     if (isset($this->config['defaults'])) {
         $defaults = array_merge($this->config['defaults'], $defaults);
     }
     // Read command line
     $cli = $this->context->getopt($getopt);
     $data = new OptionTransformer($cli->get());
     // Create the options container instance
     $options = new Options($validators, $defaults);
     $options->loadOptionData($data->getArrayCopy());
     // initial load so we can access the config option
     // Read config file
     $configLoader = new DotenvLoader((string) new TildeExpander($options->config));
     try {
         $configData = $configLoader->parse()->toArray();
         $options->loadOptionData($configData, false);
         // don't overwrite CLI data
     } catch (\InvalidArgumentException $e) {
         $this->error = $e;
     }
     return $options;
 }