Instantly share code, notes, and snippets.

View CronException.php
<?php
namespace console\components;
use Throwable;
use yii\base\Action;
class CronException extends \RuntimeException
{
/**
View streamBase64EncodeFilter.php
<?php
class Base64Encode extends \php_user_filter
{
private $bufferHandle;
private $tail = '';
public function filter($in, $out, &$consumed, $closing)
{
View tooltip-over-select2.js
/**
* Declate title attribute on target select element.
* Initialize tooltip:
*/
jQuery("div.select2-container").tooltip({
title: function() {
return $(this).next().attr("title");
},
});
View FindOrCreate.php
<?php
namespace common\traits;
trait FindOrCreate
{
/**
* @param mixed $key Primary key or array with condition for \yii\db\Query::where(condition)
* @return static
* @throws \Exception
View Writer.php
<?php
class Writer
{
public function saveFile()
{
file_put_contents('/var/www/file.pdf', '123');
}
}
View SerializeAttributeBehavior.php
<?php
use yii\base\Behavior;
use yii\db\ActiveRecord;
class SerializeAttributeBehavior extends Behavior
{
/**
* @var string[]
*/
View CantSave.php
<?php
namespace common\exception;
use e96\sentry\ErrorHandler;
use yii\base\Exception;
use yii\db\ActiveRecord;
class CantSave extends Exception
View telegram icon.txt
To convert this svg to web font – just upload `telegram-single-path*.svg` to http://fontello.com service!
Use `telegram-source-240px.svg` as source file.
View date_diff.php
<?php
$date1 = new \DateTime('2017-01-01');
$date2 = new \DateTime('2017-01-10');
$dateInterval = $date1->diff($date2); // this is not date1-date2, but date2-date1 :-(
var_dump($dateInterval->format('%r%a') > 3); // :-(
View WithoutTrait.php
<?php
namespace common\ActiveRecordTrait;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
trait WithoutTrait
{