Skip to content

Instantly share code, notes, and snippets.

@maxxer
Created March 13, 2015 16:19
Show Gist options
  • Save maxxer/219e8147eb4647ac2a44 to your computer and use it in GitHub Desktop.
Save maxxer/219e8147eb4647ac2a44 to your computer and use it in GitHub Desktop.
app\components\YSoapModelBehavior for mongosoft/yii2-soap-server
<?php
/**
* Behavior for assigning SOAP properties
* @author Lorenzo Milesi <maxxer@yetopen.it>
* @copyright 2015 YetOpen S.r.l.
*/
namespace app\components;
use yii\base\Behavior;
use yii\db\ActiveRecord;
use Wingu\OctopusCore\Reflection\ReflectionClass;
class YSoapModelBehavior extends Behavior {
public function events()
{
return [
ActiveRecord::EVENT_AFTER_FIND => 'afterFind',
];
}
/**
* Gather soap tagged attributes and reassign values to them
*/
public function afterFind() {
$ref = new ReflectionClass($this->owner->className());
foreach ($ref->getProperties() as $prop) {
if ($prop->getReflectionDocComment()->getAnnotationsCollection()->hasAnnotationTag('soap')) {
$propname = $prop->getName();
$this->owner->$propname = $this->owner->getAttribute($propname);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment