Ejemplo n.º 1
0
 /**
  * @param int|null $code
  * @param string $value
  *
  * @return string
  */
 public function transform($code, $value)
 {
     if ($value === '}') {
         $this->getTransformer()->setMode(Transformer::MODE_FILE);
     } else {
         switch ($code) {
             case T_STATIC:
                 $this->static = true;
                 break;
             case T_PUBLIC:
             case T_PROTECTED:
             case T_PRIVATE:
                 $this->visibility = $code;
                 break;
             case T_ABSTRACT:
             case T_FINAL:
                 $this->attribute = $code;
                 break;
             case T_VARIABLE:
                 $this->reset();
                 break;
             case T_FUNCTION:
                 $method = new MethodMetaInfo();
                 $method->setIsStatic($this->static);
                 $method->setAttribute($this->attribute);
                 $method->setVisibility($this->visibility);
                 $this->getTransformer()->getClassMetaInfo()->addMethod($method);
                 $this->getTransformer()->setMode($code);
                 $this->reset();
                 break;
         }
     }
     return $value;
 }
Ejemplo n.º 2
0
    /**
     * @param MethodMetaInfo $metaInfo
     *
     * @return string
     */
    private function getInjectedCode(MethodMetaInfo $metaInfo)
    {
        static $namespace = '\\Influence\\RemoteControl::';
        if ($metaInfo->getIsStatic() or $metaInfo->isConstructor()) {
            $hasMethod = $namespace . 'hasStatic(get_called_class(), __FUNCTION__)';
            $getMethod = $namespace . 'getStatic(get_called_class())';
        } else {
            $hasMethod = $namespace . 'hasObject($this, __FUNCTION__)';
            $getMethod = $namespace . 'getObject($this)';
        }
        $scope = $metaInfo->getIsStatic() ? '__CLASS__' : '$this';
        $manifest = uniqid('$manifest_');
        $code = <<<EOL
if ({$hasMethod}) {
    {$manifest} = {$getMethod}->get(__FUNCTION__);
    if ({$manifest}->log(func_get_args())->hasValue()) {
        return {$manifest}->getValue(func_get_args(), {$scope});
    }
}
EOL;
        return preg_replace('/\\s+/', '', $code);
    }