Skip to content

Instantly share code, notes, and snippets.

<?php
class DownloadJob implements \yii\queue\JobInterface
{
public $url;
public $file;
public function execute($queue)
{
file_put_contents($this->file, file_get_contents($this->url));
@lav45
lav45 / speechkit.php
Created December 17, 2017 08:35
Озвучка текста с помощью API yandex speechkit
#!/usr/bin/env php
<?php
/**
* Using
* ~$ php speechkit.php book.txt
*
* @see https://tech.yandex.ru/speechkit/cloud/doc/guide/concepts/tts-http-request-docpage/
*/
$apiUrl = 'https://tts.voicetech.yandex.net/generate';
@lav45
lav45 / models\Category.php
Last active October 23, 2017 20:44
Product->getCategoryList() - работа со связанными списками.
<?php
namespace common\models;
use yii\db\ActiveRecord;
class Category extends ActiveRecord
{
/**
* @return array
<?php
// opcache.validate_timestamps = Off
opcache_reset();
@lav45
lav45 / Module.php
Last active May 5, 2017 21:45
XmlResponseFormatter useObjectTags
<?php
namespace api\modules\v0;
use Yii;
class Module extends \yii\base\Module
{
public function init()
{
parent::init();
@lav45
lav45 / SiteController.php
Last active April 20, 2017 18:10
Setting frontendUrlManager
<?php
// backend/controllers/SiteController.php
namespace backend\controllers;
class SiteController extends Controller
{
public function actionIndex()
{
Yii::$app->frontendUrlManager
@lav45
lav45 / flespi.io.php
Created April 10, 2017 07:52
Test flespi.io gateway
<?php
$url = 'https://flespi.io/gw/channels/{channels}/messages';
$channels = implode(',', [136]);
$url = str_replace('{channels}', $channels, $url);
// $data = ['timeout' => 10];
// $data = json_encode($data);
// $url .= '?' . http_build_query(['data' => $data]);
<?php
$secret = 'secret key';
list($hashAlgo, $signature) = explode('=', $_SERVER['HTTP_X_HUB_SIGNATURE']);
$payload = $HTTP_RAW_POST_DATA ?: file_get_contents('php://input');
$compute = hash_hmac($hashAlgo, $payload, $secret);
$valid = hash_equals($compute, $signature);
if ($valid === false) {
<?php
/**
* Created by PhpStorm.
* User: lav45
* Date: 28.12.16
* Time: 21:18
*/
namespace demo;
@lav45
lav45 / FormBuilder.php
Last active February 26, 2018 17:37
MultipleInput verification through Model
<?php
use yii\base\Model;
use yii\base\Widget;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveField;
use yii\widgets\InputWidget;
class FormBuilder extends Widget