Skip to content

Commit

Permalink
Merge pull request #6892 from GawainLynch/hotfix/bolt-common
Browse files Browse the repository at this point in the history
[3.4] Implement use of bolt/common
  • Loading branch information
GwendolenLynch committed Aug 19, 2017
2 parents 1989fd8 + a9077a9 commit d26a516
Show file tree
Hide file tree
Showing 88 changed files with 264 additions and 515 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"license": "MIT",
"require": {
"bolt/collection": "^1.1",
"bolt/common": "^1.0",
"bolt/filesystem": "^2.3.1",
"bolt/pathogen": "~0.6",
"bolt/requirements": "^1.0@dev",
Expand Down
3 changes: 2 additions & 1 deletion src/AccessControl/PermissionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bolt\AccessControl;

use Bolt\Common\Json;
use Bolt\Exception\PermissionLexerException;
use Bolt\Exception\PermissionParserException;

Expand Down Expand Up @@ -259,7 +260,7 @@ private static function expect($expected, $token)
if ($token['match']) {
$actualStr .= " ('" . addslashes($token['match']) . "')";
}
$actualStr .= ' <<< ' . json_encode($token) . ' >>> ';
$actualStr .= ' <<< ' . Json::dump($token) . ' >>> ';
throw new PermissionParserException("Parser error: expected $expectedStr, but found $actualStr");
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/AccessControl/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bolt\AccessControl;

use Bolt\Common\Json;
use Bolt\Exception\AccessControlException;
use Bolt\Legacy\Content;
use Bolt\Storage\Entity;
Expand Down Expand Up @@ -551,11 +552,11 @@ public function isAllowed($what, $user, $content = null, $contentId = null)

$cacheKey = "_permission_rule:$what";
if ($this->app['cache']->contains($cacheKey)) {
$rule = json_decode($this->app['cache']->fetch($cacheKey), true);
$rule = Json::parse($this->app['cache']->fetch($cacheKey));
} else {
$parser = new PermissionParser();
$rule = $parser->run($what);
$this->app['cache']->save($cacheKey, json_encode($rule));
$this->app['cache']->save($cacheKey, Json::dump($rule));
}
$userRoles = $this->getEffectiveRolesForUser($user);
$isAllowed = $this->isAllowedRule($rule, $user, $userRoles, $content, $contenttypeSlug, $contentId);
Expand Down
2 changes: 1 addition & 1 deletion src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Bolt;

use Bolt\Common\Deprecated;
use Bolt\Events\ControllerEvents;
use Bolt\Events\MountEvent;
use Bolt\Helpers\Deprecated;
use Bolt\Legacy\AppSingleton;
use Bolt\Provider\LoggerServiceProvider;
use Bolt\Provider\PathServiceProvider;
Expand Down
22 changes: 11 additions & 11 deletions src/Asset/Injector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\Asset;

use Bolt\Helpers\Str;
use Bolt\Common\Str;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down Expand Up @@ -81,7 +81,7 @@ protected function headTagStart(AssetInterface $asset, $rawHtml)
if ($matches = $this->getMatches($rawHtml, '<head', true, false)) {
$replacement = sprintf("%s\n%s\t%s", $matches[0], $matches[1], (string) $asset);

return Str::replaceFirst($matches[0], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0], $replacement);
}

return $this->tagSoup($asset, $rawHtml);
Expand All @@ -101,7 +101,7 @@ protected function headTagEnd(AssetInterface $asset, $rawHtml)
if ($matches = $this->getMatches($rawHtml, '</head', false, false)) {
$replacement = sprintf("%s\t%s\n%s", $matches[1], (string) $asset, $matches[0]);

return Str::replaceFirst($matches[0], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0], $replacement);
}

return $this->tagSoup($asset, $rawHtml);
Expand All @@ -121,7 +121,7 @@ protected function bodyTagStart(AssetInterface $asset, $rawHtml)
if ($matches = $this->getMatches($rawHtml, '<body', true, false)) {
$replacement = sprintf("%s\n%s\t%s", $matches[0], $matches[1], (string) $asset);

return Str::replaceFirst($matches[0], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0], $replacement);
}

return $this->tagSoup($asset, $rawHtml);
Expand All @@ -141,7 +141,7 @@ protected function bodyTagEnd(AssetInterface $asset, $rawHtml)
if ($matches = $this->getMatches($rawHtml, '</body', false, false)) {
$replacement = sprintf("%s\t%s\n%s", $matches[1], $asset, $matches[0]);

return Str::replaceFirst($matches[0], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0], $replacement);
}

return $this->tagSoup($asset, $rawHtml);
Expand All @@ -161,7 +161,7 @@ protected function htmlTagEnd(AssetInterface $asset, $rawHtml)
if ($matches = $this->getMatches($rawHtml, '</html', false, false)) {
$replacement = sprintf("%s\t%s\n%s", $matches[1], $asset, $matches[0]);

return Str::replaceFirst($matches[0], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0], $replacement);
}

return $this->tagSoup($asset, $rawHtml);
Expand All @@ -181,7 +181,7 @@ protected function metaTagsAfter(AssetInterface $asset, $rawHtml)
$last = count($matches[0]) - 1;
$replacement = sprintf("%s\n%s%s", $matches[0][$last], $matches[1][$last], (string) $asset);

return Str::replaceFirst($matches[0][$last], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0][$last], $replacement);
}

return $this->headTagEnd($asset, $rawHtml);
Expand All @@ -201,7 +201,7 @@ protected function cssTagsAfter(AssetInterface $asset, $rawHtml)
$last = count($matches[0]) - 1;
$replacement = sprintf("%s\n%s%s", $matches[0][$last], $matches[1][$last], (string) $asset);

return Str::replaceFirst($matches[0][$last], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0][$last], $replacement);
}

return $this->headTagEnd($asset, $rawHtml);
Expand All @@ -220,7 +220,7 @@ protected function cssTagsBefore(AssetInterface $asset, $rawHtml)
if ($matches = $this->getMatches($rawHtml, '<link', true, false)) {
$replacement = sprintf("%s%s\n%s\t%s", $matches[1], $asset, $matches[0], $matches[1]);

return Str::replaceFirst($matches[0], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0], $replacement);
}

return $this->tagSoup($asset, $rawHtml);
Expand All @@ -239,7 +239,7 @@ protected function jsTagsBefore(AssetInterface $asset, $rawHtml)
if ($matches = $this->getMatches($rawHtml, '<script', true, false)) {
$replacement = sprintf("%s%s\n%s\t%s", $matches[1], $asset, $matches[0], $matches[1]);

return Str::replaceFirst($matches[0], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0], $replacement);
}

return $this->tagSoup($asset, $rawHtml);
Expand Down Expand Up @@ -271,7 +271,7 @@ protected function jsTagsAfter($asset, $rawHtml, $insidehead = false)
$last = count($matches[0]) - 1;
$replacement = sprintf("%s\n%s%s", $matches[0][$last], $matches[1][$last], (string) $asset);

return Str::replaceFirst($matches[0][$last], $replacement, $rawHtml);
return Str::replaceFirst($rawHtml, $matches[0][$last], $replacement);
} elseif ($insidehead) {
// Second attempt: entire document
return $this->jsTagsAfter($asset, $rawHtml, false);
Expand Down
6 changes: 4 additions & 2 deletions src/Asset/Snippet/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Bolt\Asset\Snippet;

use Bolt\Common\Exception\DumpException;
use Bolt\Common\Serialization;
use Bolt\Controller\Zone;
use Twig\Markup;

Expand Down Expand Up @@ -150,8 +152,8 @@ private function getCallableResult()
}

try {
$msg = sprintf('Snippet loading failed with callable %s', serialize($this->callback));
} catch (\Exception $e) {
$msg = sprintf('Snippet loading failed with callable %s', Serialization::dump($this->callback));
} catch (DumpException $e) {
$msg = sprintf('Snippet loading failed with an unknown callback.');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Asset/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\Asset;

use Bolt\Helpers\Deprecated;
use Bolt\Common\Deprecated;

/**
* Bolt Snippet target location.
Expand Down
19 changes: 3 additions & 16 deletions src/Asset/Widget/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use Bolt\Asset\QueueInterface;
use Bolt\Asset\Snippet\Snippet;
use Bolt\Asset\Target;
use Bolt\Common\Deprecated;
use Bolt\Common\Thrower;
use Bolt\Controller\Zone;
use Bolt\Helpers\Deprecated;
use Bolt\Render;
use Doctrine\Common\Cache\CacheProvider;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -203,22 +204,8 @@ protected function getHtml(WidgetAssetInterface $widget)
return $html;
}

/** @var \Exception $e */
$e = null;
set_error_handler(
function ($errno, $errstr) use (&$e) {
return $e = new \Exception($errstr, $errno);
}
);

// Get the HTML from object cast and rethrow an exception if present
$html = (string) $widget;
$html = Thrower::call([$widget, '__toString']);

restore_error_handler();

if ($e instanceof \Exception) {
throw $e;
}
if ($widget->getCacheDuration() !== null) {
$this->cache->save($key, $html, $widget->getCacheDuration());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Bolt;

use Bolt\Common\Deprecated;
use Bolt\Filesystem\CompositeFilesystemInterface;
use Bolt\Filesystem\Exception\IOException;
use Bolt\Filesystem\Handler\DirectoryInterface;
use Bolt\Filesystem\Handler\HandlerInterface;
use Bolt\Helpers\Deprecated;
use Doctrine\Common\Cache\FilesystemCache;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Composer/Script/BootstrapYamlUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Bolt\Composer\Script;

use Bolt\Collection\MutableBag;
use Bolt\Helpers\Str;
use Bolt\Common\Str;
use Composer\IO\IOInterface;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
Expand Down Expand Up @@ -219,7 +219,7 @@ public function updatePaths(MutableBag $paths)
continue;
}
if ($appPathToTrim && strpos($path, $appPathToTrim) === 0) {
$path = Str::replaceFirst($appPathToTrim, '', $path);
$path = Str::replaceFirst($path, $appPathToTrim, '');
if ($path === $key) {
$paths->remove($key);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Bolt;

use Bolt\Collection\Arr;
use Bolt\Common\Deprecated;
use Bolt\Controller\Zone;
use Bolt\Filesystem\Exception\FileNotFoundException;
use Bolt\Filesystem\Exception\IOException;
Expand All @@ -11,7 +12,6 @@
use Bolt\Filesystem\Handler\Image;
use Bolt\Filesystem\Handler\JsonFile;
use Bolt\Filesystem\Handler\ParsableInterface;
use Bolt\Helpers\Deprecated;
use Bolt\Helpers\Html;
use Bolt\Helpers\Str;
use Bolt\Storage\Database;
Expand Down Expand Up @@ -703,7 +703,7 @@ protected function parseDatabase(array $options)
$options = array_replace($options, $master);

// Add platform specific random functions
$driver = Str::replaceFirst('pdo_', '', $options['driver']);
$driver = \Bolt\Common\Str::replaceFirst($options['driver'], 'pdo_', '');
if ($driver === 'sqlite') {
$options['driver'] = 'pdo_sqlite';
$options['randomfunction'] = 'RANDOM()';
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Check/BaseCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\Configuration\Check;

use Bolt\Helpers\Deprecated;
use Bolt\Common\Deprecated;
use Silex\Application;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Check/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\Configuration\Check;

use Bolt\Helpers\Deprecated;
use Bolt\Common\Deprecated;

/**
* A container class for a check result.
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\Configuration;

use Bolt\Helpers\Deprecated;
use Bolt\Common\Deprecated;
use Symfony\Component\HttpFoundation\Request;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/LowlevelChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Bolt\Configuration;

use Bolt\Common\Deprecated;
use Bolt\Exception\BootException;
use Bolt\Helpers\Deprecated;

/**
* @deprecated Deprecated since 3.1, to be removed in 4.0.
Expand Down Expand Up @@ -45,7 +45,7 @@ public function __construct($config = null)

$this->config = $config;
$this->magicQuotes = get_magic_quotes_gpc();
$this->safeMode = ini_get('safe_mode');
$this->safeMode = false;
$this->isApache = (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false);
$this->postgresLoaded = extension_loaded('pdo_pgsql');
$this->sqliteLoaded = extension_loaded('pdo_sqlite');
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/PathsProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\Configuration;

use Bolt\Helpers\Deprecated;
use Bolt\Common\Deprecated;

/**
* Bolt\Configuration\ResourceManager::getPaths() is proxied here, which used to return a simple array.
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Bolt\Configuration;

use Bolt\Helpers\Deprecated;
use Bolt\Common\Deprecated;
use Bolt\Legacy\AppSingleton;
use Bolt\Pager\PagerManager;
use Composer\Autoload\ClassLoader;
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/YamlUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace Bolt\Configuration;

use Bolt\Collection\MutableBag;
use Bolt\Common\Deprecated;
use Bolt\Filesystem\Exception\IOException;
use Bolt\Filesystem\Handler\FileInterface;
use Bolt\Helpers\Deprecated;
use Silex\Application;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Inline;
Expand Down
14 changes: 6 additions & 8 deletions src/Controller/Backend/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Bolt\Controller\Backend;

use Bolt\Common\Str;
use Bolt\Exception\FileNotStackableException;
use Bolt\Filesystem\Exception\ExceptionInterface;
use Bolt\Filesystem\Exception\FileNotFoundException;
Expand All @@ -14,7 +15,6 @@
use Bolt\Form\FormType\FileUploadType;
use Bolt\Form\Validator\Constraints;
use Bolt\Helpers\Input;
use Bolt\Helpers\Str;
use Bolt\Translation\Translator as Trans;
use Silex\ControllerCollection;
use Symfony\Component\Form\Form;
Expand All @@ -24,6 +24,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Parser;
use Webmozart\PathUtil\Path;

/**
* Backend controller for file/directory management routes.
Expand Down Expand Up @@ -330,16 +331,13 @@ private function getRelatedFiles(FileInterface $file)
{
// Match foo(_local).*(.dist)
$base = $file->getFilename();
if (Str::endsWith($base, '.dist')) {
$base = substr($base, 0, -5);
}
$ext = pathinfo($base, PATHINFO_EXTENSION);
$base = Str::replaceLast(".$ext", '', $base);
$base = Str::replaceLast('_local', '', $base);
$ext = Path::getExtension($base);
$base = Path::getFilenameWithoutExtension($base);
$base = Str::replaceLast($base, '_local', '');

$dir = $file->getParent();
$related = [];
foreach ([".$ext", "_local.$ext", ".$ext.dist"] as $tail) {
foreach ([".$ext", "_local.$ext"] as $tail) {
$f = $dir->getFile($base . $tail);
if ($f->getFilename() !== $file->getFilename() && $f->exists()) {
$related[] = $f;
Expand Down
Loading

0 comments on commit d26a516

Please sign in to comment.