Skip to content

Instantly share code, notes, and snippets.

@VictorFursa
Created February 4, 2017 19:28
Show Gist options
  • Save VictorFursa/154cbf7ba64a2376d4fd3779a9fc03a5 to your computer and use it in GitHub Desktop.
Save VictorFursa/154cbf7ba64a2376d4fd3779a9fc03a5 to your computer and use it in GitHub Desktop.
event
<?php
namespace common\service;
use yii\base\Component;
class RequestCrawlerService extends Component
{
const EVENT_INFO_AFTER_SAVE = 'infoAfterSave';
/** @var object $serializer */
public $serializer;
/** @var string $pathToSave */
public $pathToSave;
/**
* RequestCrawlerService constructor.
* @param SerializerInterface $serializer
* @param array $config
*/
public function __construct(SerializerInterface $serializer, $config = [])
{
$this->serializer = $serializer;
// можно так $this->on(self::EVENT_INFO_AFTER_SAVE, [Test::className(), 'info']);
parent::__construct($config);
}
/**
* @param $encoded
*/
public function encodedAndSaveFile($encoded)
{
file_put_contents($this->pathToSave . '/' . time() . '.txt', $encoded, FILE_APPEND | LOCK_EX);
$this->trigger(self::EVENT_INFO_AFTER_SAVE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment