Пример #1
0
 /**
  * Check if fixing paths works correctly.
  *
  * @return void
  */
 public function testToolFixPath()
 {
     // test for invalid directory separators
     $this->assertEquals('foo' . DIRECTORY_SEPARATOR . 'bar.ext', Utils::fixPath('foo\\/bar.ext'));
     // test for multiple directory separators
     $this->assertEquals('foo' . DIRECTORY_SEPARATOR . 'ups' . DIRECTORY_SEPARATOR . 'bar.ext', Utils::fixPath('foo\\\\\\\\ups/////bar.ext'));
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function renderText($path, array $arguments = [])
 {
     if ($this->container['minion.useTwig']) {
         return $this->container['twig']->render($path, $arguments);
     } else {
         return Utils::renderPhpTemplate(Utils::fixPath($this->container->getRootDir() . '/src/' . $path), $arguments);
     }
 }
Пример #3
0
 /**
  * Return fixed asset's path.
  *
  * @param string $asset      Path to the asset
  * @param bool   $serverPath Server-related path or web-related
  *
  * @throws FileException File does not exist on server
  *
  * @return string
  */
 public function assetFunction($asset, $serverPath = false)
 {
     /** @var Request|null $request */
     $request = isset($this->container['request']) ? $this->container['request'] : null;
     $path = \ltrim($asset, '/\\');
     $assetPath = Utils::fixPath($this->container->getRootDir() . '/web/' . $path);
     if (!\file_exists($assetPath)) {
         throw new FileException("Asset '{$asset}' with path '{$assetPath}' not found");
     }
     if (!$serverPath) {
         if ($request instanceof Request) {
             $assetPath = $request->getSchemeAndHttpHost() . '/' . $path;
         } else {
             $assetPath = '/' . $path;
         }
     }
     return $assetPath;
 }
Пример #4
0
 /**
  * Console constructor.
  *
  * @param string $appNamespace Application namespace (autodetect, if empty)
  * @param array  $values       Default options
  * @param array  $fixPaths     Path fixes
  *
  * @return Console
  */
 public function __construct($appNamespace = '', array $values = [], array $fixPaths = [])
 {
     parent::__construct($appNamespace, $values, $fixPaths);
     $this->commandPath = isset($fixPaths['commandDir']) ? $fixPaths['commandDir'] : Utils::fixPath($this->getRootDir() . '/src/Command/');
     $this->loadCommands($this->getCommandPath());
     // load Propel commands
     if ($this['minion.usePropel']) {
         $this->loadCommands(Utils::fixPath(($this['environment'] === 'test' ? $this->getRootDir() . '/../' : $this->getRootDir()) . '/vendor/propel/propel/src/Propel/Generator/Command/'), 'propel');
         // replace default config-dir value command option
         /** @var Command $command */
         foreach ($this['console']->all('propel') as $command) {
             $def = $command->getDefinition();
             $old = $def->getOptions();
             foreach ($old as $i => $o) {
                 if ($o->getName() === 'config-dir') {
                     unset($old[$i]);
                     break;
                 }
             }
             $opt = new InputOption('config-dir', null, InputOption::VALUE_REQUIRED, 'The directory where the configuration file is placed.', $this->getPackageDir());
             $def->setOptions(\array_merge($old, [$opt]));
         }
     }
 }
Пример #5
0
 /**
  * Resolve paths to navigate through project.
  *
  * @param array $fixPaths User-defined path fixes
  *
  * @return void
  *
  * @throws \InvalidArgumentException Some paths are invalid
  */
 protected function resolvePaths(array $fixPaths)
 {
     $this->rootDir = \realpath(isset($fixPaths['rootDir']) ? $fixPaths['rootDir'] : __DIR__ . '/../../../../');
     $this->packageDir = \realpath(isset($fixPaths['packageDir']) ? $fixPaths['packageDir'] : __DIR__ . '/../');
     $this->configPath = Utils::fixPath(isset($fixPaths['configPath']) ? $fixPaths['configPath'] : '/app/');
     if ($this->rootDir === false || $this->packageDir === false) {
         throw new \InvalidArgumentException('Bootstrap directories do not exists or are not accessible');
     }
     if ($this['minion.usePropel']) {
         $this->propelConfigPath = \realpath(isset($fixPaths['propelConfigPath']) ? $fixPaths['propelConfigPath'] : Utils::fixPath($this->packageDir . '/propel.php'));
         if ($this->propelConfigPath === false) {
             throw new \InvalidArgumentException('Propel configuration file in vendor Minion not found');
         }
     }
 }
Пример #6
0
<?php

namespace Minion\Tests\Propel\Config;

use Minion\Utils;
/**
 * Test environment propel configuratin file
 *
 * @package Minion\Tests
 * @author Damian Szczerbiński <*****@*****.**>
 */
$root = __DIR__;
$arr = ['propel' => ['database' => ['connections' => ['test' => ['adapter' => 'sqlite', 'dsn' => 'sqlite::memory:', 'user' => '', 'password' => '']]], 'paths' => ['projectDir' => $root, 'schemaDir' => $root . Utils::fixPath('/app'), 'outputDir' => $root . Utils::fixPath('/src/Propel'), 'phpDir' => $root . Utils::fixPath('/src/Propel'), 'phpConfDir' => $root . Utils::fixPath('/app/propel/runtime'), 'migrationDir' => $root . Utils::fixPath('/app/propel/migration'), 'sqlDir' => $root . Utils::fixPath('/app/propel/sql')], 'runtime' => ['defaultConnection' => 'test', 'connections' => ['test']], 'generator' => ['defaultConnection' => 'test', 'connections' => ['test'], 'objectModel' => ['addHooks' => false]]]];
return $arr;
Пример #7
0
<?php

/**
 * This file is part of the Minion\Tests package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license MIT License
 */
namespace Minion\Propel\Config;

use Minion\Utils;
/**
 * Propel default configuration file.
 *
 * @package Minion
 * @author Damian Szczerbiński <*****@*****.**>
 */
$root = \realpath(__DIR__ . '/../../../');
$arr = \array_replace_recursive(['propel' => ['paths' => ['projectDir' => $root, 'schemaDir' => $root . Utils::fixPath('/app'), 'outputDir' => $root . Utils::fixPath('/src/Propel'), 'phpDir' => $root . Utils::fixPath('/src/Propel'), 'phpConfDir' => $root . Utils::fixPath('/app/propel/runtime'), 'migrationDir' => $root . Utils::fixPath('/app/propel/migration'), 'sqlDir' => $root . Utils::fixPath('/app/propel/sql')], 'runtime' => ['defaultConnection' => 'default', 'connections' => ['default'], 'log' => ['defaultLogger' => ['type' => 'stream', 'level' => 300, 'path' => $root . Utils::fixPath('/var/log/propel.log')]]], 'generator' => ['defaultConnection' => 'default', 'connections' => ['default'], 'objectModel' => ['addHooks' => false]]]], include $root . Utils::fixPath('/propel.php'));
return $arr;