class HttpAuthFilterSoap extends CFilter
{
public $realm;
public function preFilter($filterChain)
{
if(!array_key_exists('PHP_AUTH_USER', $_SERVER)){
$this->sendAuthHeaders();
}
if(!$this->login()) {
$this->sendAuthHeaders();
}
return true;
}
protected function sendAuthHeaders()
{
if($this->realm === null)
$this->realm = Yii::app()->name;
$this->realm = addcslashes($this->realm, '"\\');
header(sprintf('WWW-Authenticate: Basic realm="%s"', $this->realm));
throw new CHttpException(401);
}
private function login()
{
return SoapAuth::AUTH_USERNAME === $_SERVER['PHP_AUTH_USER'] && SoapAuth::AUTH_PASSWORD === $_SERVER['PHP_AUTH_PW'];
}
}
public function beforeAction($action)
{
parent::beforeAction($action);
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401_1 U_Unauthorized');
echo "Вы должны ввести корректный логин и пароль для получения доступа к ресурсу";
exit;
} else {
if (SoapAuth::AUTH_USERNAME === $_SERVER['PHP_AUTH_USER'] && SoapAuth::AUTH_PASSWORD === $_SERVER['PHP_AUTH_PW']) {
return true;
}
else {
// throw new Exception($_SERVER['PHP_AUTH_USER'] . ':' .$_SERVER['PHP_AUTH_PW']);
return false;
}
}
}
trait ImageManager()
{
public function setPhotoAttribute($value) {
if ($value instanceOf UploadedFile) {
$fileNameWithExt = $value->getClientOriginalName();
$filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
$extension = $value->getClientOriginalExtension();
$fileNameToStore = $filename . '_' . time() . '.' . $extension;
// $this->path вместо явного 'public/articles'
$file->storeAs( $this->path , $fileNameToStore);
return $this->attributes['photo'] = $fileNameToStore;
}
}
}
$request = $this->saveImage($request);
dump($request->all());
private function saveImage(ArticleRequest $request)
{
if ($request->hasFile('photo')) {
$file = $request->file('photo'); // ->isValid()
$fileNameWithExt = $file->getClientOriginalName();
$filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
$extension = $file->getClientOriginalExtension();
$fileNameToStore = $filename . '_' . time() . '.' . $extension;
$file->storeAs('public/images', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
$request->merge(['photo' => $fileNameToStore]);
return $request;
}
Логируется только finish;
К сожалению не нашел списка событийкомпонента. В процессе. Думаю мне нужно что-то типа onBeforeRequest, но на такое ругается.