Skip to content

Instantly share code, notes, and snippets.

View rossriley's full-sized avatar

Ross Riley rossriley

View GitHub Profile
<?php
class Deprecated
{
/**
* Shortcut for triggering a deprecation warning for a method.
*
* Example:
* class Foo
* {
@rossriley
rossriley / boltS3.php
Last active July 9, 2019 13:34
Adding an S3 filesystem for Bolt
<?php
use Aws\S3\S3Client;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\AwsS3 as Adapter;
$client = S3Client::factory(array(
'key' => '[your key]',
'secret' => '[your secret]',
'region' => '[aws-region]'
));
var CKEDITORPluginExtras = false;
if (typeof(CKEDITOR) != 'undefined' ) {
CKEDITOR.on('instanceReady',function(event, instance){
if (CKEDITORPluginExtras) {
return;
}
var config = event.editor.config;
CKEDITOR.instances.body.destroy();
<?php
namespace MyApp\Response;
use Symfony\Component\HttpFoundation\Response;
class CsvResponse extends Response
{
protected $data;
<?php
// This line needs to be called after initialize but before run
$app['upload'] = $app->extend(
'upload',
function ($handler, $app) {
if ($app['request']->get('contenttypeslug') && $app['request']->get('id')) {
$handler->setPrefix("/".$app['request']->get('contenttypeslug')."/".$app['request']->get('id'));
}
@rossriley
rossriley / uploadSanitiser.php
Last active January 26, 2018 12:41
Bolt: Extending the upload handler with custom sanitiser
$app['upload'] = $app->share(
$app->extend(
'upload',
function ($uploadHandler) {
$uploadHandler->setSanitizerCallback(
function ($filename) {
// Do things with filename string here.
return $filename;
}
);
@rossriley
rossriley / upload.extension.php
Created January 26, 2018 10:06
Overwrite default filesize for Bolt Uploads
$app['upload'] = $app->share(
$app->extend(
'upload',
function ($uploadHandler) {
$uploadHandler->addRule('size', ['max' => '2M'])
return $uploadHandler;
}
)
@rossriley
rossriley / TwigExtension.php
Last active December 12, 2017 16:16
Twig Extension to replace files with thumbnails
<?php
namespace MyApp\Twig;
use Twig_Extension;
use Twig_SimpleFilter;
class TwigExtension extends Twig_Extension
{
public $app;
@rossriley
rossriley / CustomisationExtension.php
Last active December 12, 2017 06:51
Modifying A Bolt Record on the Post Save Event
<?php
namespace Bundle\Site;
use Bolt\Storage\Entity\Content;
use Bolt\Extension\SimpleExtension;
use Bolt\Events\StorageEvent;
use Bolt\Events\StorageEvents;
/**
* Site bundle extension loader.
<?php
namespace MyNewApp\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Bolt\Application;