Created
March 13, 2015 16:19
-
-
Save maxxer/219e8147eb4647ac2a44 to your computer and use it in GitHub Desktop.
app\components\YSoapModelBehavior for mongosoft/yii2-soap-server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Behavior for assigning SOAP properties | |
* @author Lorenzo Milesi <[email protected]> | |
* @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