/**
  * {@inheritDoc}
  */
 public function convert(ReplyInterface $reply)
 {
     $headers = $statusCode = $content = null;
     if ($reply instanceof SymfonyHttpResponse) {
         $response = $reply->getResponse();
         $statusCode = $response->getStatusCode();
         $headers = $response->headers->all();
         $content = $response->getContent();
     } else {
         if ($reply instanceof HttpPostRedirect) {
             $statusCode = $reply->getStatusCode();
             $headers = $reply->getHeaders();
             $content = $this->preparePostRedirectContent($reply);
         } else {
             if ($reply instanceof HttpResponse) {
                 $statusCode = $reply->getStatusCode();
                 $headers = $reply->getHeaders();
                 $content = $reply->getContent();
             } else {
                 $ro = new \ReflectionObject($reply);
                 throw new LogicException(sprintf('Cannot convert reply %s to http response.', $ro->getShortName()), null, $reply);
             }
         }
     }
     $fixedHeaders = [];
     foreach ($headers as $name => $value) {
         $fixedHeaders[str_replace('- ', '-', ucwords(str_replace('-', '- ', $name)))] = $value;
     }
     $fixedHeaders['Content-Type'] = 'application/vnd.payum+json';
     return new JsonResponse(['status' => $statusCode, 'headers' => $fixedHeaders, 'content' => $content], $statusCode, ['X-Status-Code' => $statusCode]);
 }
Esempio n. 2
0
 /**
  * @param \Wehup\AMI\Request\RequestInterface $request
  * @return \Wehup\AMI\Factory\FactoryInterface
  */
 public static function getFactoryByRequest(Request\RequestInterface $request)
 {
     $reflection = new \ReflectionObject($request);
     $classname = substr($reflection->getShortName(), 0, -7);
     // remove "Request" suffix
     $fqcn = "\\Wehup\\AMI\\Factory\\{$classname}Factory";
     if (!class_exists($fqcn)) {
         throw new Exception\NoFactoryClassAvailableException("There is no available Factory class for \"{$classname}\"", $fqcn);
     }
     return new $fqcn($request);
 }
Esempio n. 3
0
 /**
  * @param mixed $value
  * @param bool $shortClass
  *
  * @return string
  */
 public static function value($value, $shortClass = true)
 {
     if (is_object($value)) {
         if ($shortClass) {
             $ro = new \ReflectionObject($value);
             return $ro->getShortName();
         }
         return get_class($value);
     }
     return gettype($value);
 }
 /**
  * Resolves an instance of the handler class
  * corresponding to $command.
  *
  * @param Command $command
  *
  * @return CommandHandler
  * @throws \Exception
  */
 private function resolveHandlerClass(Command $command)
 {
     $reflectionObject = new \ReflectionObject($command);
     $shortName = $reflectionObject->getShortName();
     $className = $reflectionObject->getNamespaceName() . '\\Handlers\\' . $shortName . 'Handler';
     if (!class_exists($className)) {
         throw new \Exception("Command handler {$className} not found.");
     }
     // Let the container resolve the instance and inject the required dependencies.
     return $this->container->get($className);
 }
 /**
  * @param ReplyInterface $reply
  *
  * @return Response
  */
 public function convert(ReplyInterface $reply)
 {
     if ($reply instanceof SymfonyHttpResponse) {
         return $reply->getResponse();
     } elseif ($reply instanceof HttpResponse) {
         $headers = $reply->getHeaders();
         $headers['X-Status-Code'] = $reply->getStatusCode();
         return new Response($reply->getContent(), $reply->getStatusCode(), $headers);
     }
     $ro = new \ReflectionObject($reply);
     throw new LogicException(sprintf('Cannot convert reply %s to http response.', $ro->getShortName()), null, $reply);
 }
 /**
  * @param ReplyInterface $reply
  *
  * @return Response
  */
 public function convert(ReplyInterface $reply)
 {
     if ($reply instanceof SymfonyHttpResponse) {
         return $reply->getResponse();
     } elseif ($reply instanceof HttpResponse) {
         return new Response($reply->getContent());
     } elseif ($reply instanceof HttpRedirect) {
         return new RedirectResponse($reply->getUrl());
     }
     $ro = new \ReflectionObject($reply);
     throw new LogicException(sprintf('Cannot convert reply %s to http response.', $ro->getShortName()), null, $reply);
 }
Esempio n. 7
0
 public function handleException(\CExceptionEvent $event)
 {
     if (false == $event->exception instanceof ReplyInterface) {
         return;
     }
     $reply = $event->exception;
     if ($reply instanceof HttpRedirect) {
         $this->redirect($reply->getUrl(), true);
         $event->handled = true;
         return;
     }
     $ro = new \ReflectionObject($reply);
     $event->exception = new LogicException(sprintf('Cannot convert reply %s to Yii response.', $ro->getShortName()), null, $reply);
 }
 /**
  * @test
  */
 public function registersMappingFilesInTheSpecifiedDirectories()
 {
     $container = new ContainerBuilder(new ParameterBag(array('kernel.debug' => false, 'kernel.bundles' => array('FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle', 'PieceValidationDirectoryLoaderBundle' => 'Piece\\Bundle\\ValidationDirectoryLoaderBundle\\PieceValidationDirectoryLoaderBundle'), 'kernel.cache_dir' => __DIR__)));
     $container->registerExtension(new FrameworkExtension());
     $container->registerExtension(new PieceValidationDirectoryLoaderExtension());
     $container->loadFromExtension('framework', array('secret' => '154F520832A9BC66316C259EEC70E4FA671A12F5', 'validation' => array('enable_annotations' => false)));
     $container->loadFromExtension('piece_validationdirectoryloader', array('mapping_dirs' => array(__DIR__ . '/Fixtures/validation/a', __DIR__ . '/Fixtures/validation/b')));
     $container->getCompilerPassConfig()->setOptimizationPasses(array());
     $container->getCompilerPassConfig()->setRemovingPasses(array());
     $container->compile();
     foreach (array(new Foo(), new Bar(), new Baz()) as $entity) {
         $violations = $container->get('validator')->validate($entity);
         $this->assertEquals(1, count($violations));
         $this->assertSame($entity, $violations[0]->getRoot());
         $entityClass = new \ReflectionObject($entity);
         $this->assertEquals(strtolower($entityClass->getShortName()), $violations[0]->getPropertyPath());
     }
 }
Esempio n. 9
0
    /**
     * Extract and map properties for the metadata
     *
     * @param ClassMetadata $metadata
     */
    protected function exportProperties(ClassMetadata $metadata)
    {
        $map = array();

        foreach ($metadata->getFields() as $name => $field) {
            $ref = new \ReflectionObject($field);
            $class = $ref->getShortName();
            $method = sprintf('exportField%s', $class);
            $map[$name] = $this->$method($field);
        }

        foreach ($metadata->getEmbeds() as $name => $embed) {
            $embedMetadata = $metadata->getEmbeddedMetadata($name);
            $map[$name]['type'] = 'object';
            $map[$name]['properties'] = $this->exportProperties($embedMetadata);
        }

        return $map;
    }
 /**
  * {@inheritDoc}
  */
 public function boot()
 {
     $this->package('payum/payum-laravel-package');
     \View::addNamespace('payum/payum', __DIR__ . '/../../views');
     $this->app->error(function (ReplyInterface $reply) {
         $response = null;
         if ($reply instanceof SymfonyHttpResponse) {
             $response = $reply->getResponse();
         } elseif ($reply instanceof HttpResponse) {
             $response = new Response($reply->getContent());
         } elseif ($reply instanceof HttpRedirect) {
             $response = new RedirectResponse($reply->getUrl());
         }
         if ($response) {
             return $response;
         }
         $ro = new \ReflectionObject($reply);
         throw new LogicException(sprintf('Cannot convert reply %s to Laravel response.', $ro->getShortName()), null, $reply);
     });
     \Route::any('/payment/authorize/{payum_token}', array('as' => 'payum_authorize_do', 'uses' => 'Payum\\LaravelPackage\\Controller\\AuthorizeController@doAction'));
     \Route::any('/payment/capture/{payum_token}', array('as' => 'payum_capture_do', 'uses' => 'Payum\\LaravelPackage\\Controller\\CaptureController@doAction'));
     \Route::any('/payment/refund/{payum_token}', array('as' => 'payum_refund_do', 'uses' => 'Payum\\LaravelPackage\\Controller\\RefundController@doAction'));
     \Route::get('/payment/notify/{payum_token}', array('as' => 'payum_notify_do', 'uses' => 'Payum\\LaravelPackage\\Controller\\NotifyController@doAction'));
     \Route::get('/payment/notify/unsafe/{payment_name}', array('as' => 'payum_notify_do_unsafe', 'uses' => 'Payum\\LaravelPackage\\Controller\\NotifyController@doUnsafeAction'));
     $this->app['payum'] = $this->app->share(function ($app) {
         //TODO add exceptions if invalid payments and storages options set.
         $payum = new ContainerAwareRegistry(\Config::get('payum-laravel-package::payments'), \Config::get('payum-laravel-package::storages'));
         $payum->setContainer($app);
         return $payum;
     });
     $this->app['payum.security.token_storage'] = $this->app->share(function ($app) {
         //TODO add exceptions if invalid payments and storages options set.
         $tokenStorage = \Config::get('payum-laravel-package::token_storage');
         return is_object($tokenStorage) ? $tokenStorage : $app[$tokenStorage];
     });
     $this->app['payum.security.token_factory'] = $this->app->share(function ($app) {
         return new TokenFactory($app['payum.security.token_storage'], $app['payum'], 'payum_capture_do', 'payum_notify_do', 'payum_authorize_do', 'payum_refund_do');
     });
     $this->app['payum.security.http_request_verifier'] = $this->app->share(function ($app) {
         return new HttpRequestVerifier($app['payum.security.token_storage']);
     });
 }
 /**
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (false == $event->getException() instanceof InteractiveRequestInterface) {
         return;
     }
     $interactiveRequest = $event->getException();
     if ($interactiveRequest instanceof SymfonyResponseInteractiveRequest) {
         $event->setResponse($interactiveRequest->getResponse());
     } elseif ($interactiveRequest instanceof ResponseInteractiveRequest) {
         $event->setResponse(new Response($interactiveRequest->getContent()));
     } elseif ($interactiveRequest instanceof RedirectUrlInteractiveRequest) {
         $event->setResponse(new RedirectResponse($interactiveRequest->getUrl()));
     }
     if ($event->getResponse()) {
         if (false == $event->getResponse()->headers->has('X-Status-Code')) {
             $event->getResponse()->headers->set('X-Status-Code', $event->getResponse()->getStatusCode());
         }
         return;
     }
     $ro = new \ReflectionObject($interactiveRequest);
     $event->setException(new LogicException(sprintf('Cannot convert interactive request %s to symfony response.', $ro->getShortName()), null, $interactiveRequest));
 }
 /**
  * @test
  */
 public function shouldLogReplyWhenSetOnPostExecute()
 {
     $action = new FooAction();
     $replyMock = $this->createReplyMock();
     $ro = new \ReflectionObject($replyMock);
     $logger = $this->createLoggerMock();
     $logger->expects($this->at(0))->method('debug')->with('[Payum] 1# FooAction::execute(string) throws reply ' . $ro->getShortName());
     $context = new Context($this->createGatewayMock(), 'string', array());
     $context->setAction($action);
     $context->setReply($replyMock);
     $extension = new LogExecutedActionsExtension($logger);
     $extension->onPostExecute($context);
 }
Esempio n. 13
0
 private function getAnalyzeHtml_Object($obj, $index)
 {
     $reflector = new \ReflectionObject($obj);
     $result = '';
     $result .= '<h4>About</h4>';
     $result .= '<table class="aboutTable">';
     $result .= '<tbody>';
     $result .= '<tr>';
     $result .= '<td class="colLeft"><strong>Name</strong></td>';
     $result .= '<td class="colRight">' . htmlentities($reflector->getShortName()) . '</td>';
     $result .= '</tr>';
     $result .= '<tr>';
     $result .= '<td class="colLeft"><strong>Namespace</strong></td>';
     $result .= '<td class="colRight">' . htmlentities($reflector->getNamespaceName()) . '</td>';
     $result .= '</tr>';
     $result .= '</tbody>';
     $result .= '<tr>';
     $result .= '<td class="colLeft"><strong>File</strong></td>';
     $result .= '<td class="colRight">' . htmlentities($reflector->getFileName()) . '</td>';
     $result .= '</tr>';
     $result .= '</tbody>';
     $result .= '</table>';
     $result .= '<h4>Members</h4>';
     $result .= '<ul class="accordion" data-accordion>';
     $accId = "objConstants{$index}";
     $constants = $reflector->getConstants();
     uksort($constants, function ($x, $y) {
         return strcmp(trim(strtolower($x)), trim(strtolower($y)));
     });
     $content = 'No constants found.';
     if (!empty($constants)) {
         $content = '<table class="memberTable">';
         $content .= '<thead>';
         $content .= '<tr>';
         $content .= '<th class="memberName">Name</th>';
         $content .= '<th>Value</th>';
         $content .= '</tr>';
         $content .= '</thead>';
         $content .= '<tbody>';
         foreach ($constants as $name => $value) {
             $content .= '<tr>';
             $content .= '<td>' . htmlentities($name) . '</td>';
             $content .= '<td>' . htmlentities(var_export($value, true)) . '</td>';
             $content .= '</tr>';
         }
         $content .= '</tbody>';
         $content .= '</table>';
     }
     $result .= '<li class="accordion-navigation">';
     $result .= '<a href="#' . $accId . '" aria-expanded="false">Constants (' . trim(count($constants)) . ')</a>';
     $result .= '<div id="' . $accId . '" class="content">' . $content . '</div>';
     $result .= '</li>';
     $accId = "objMethods{$index}";
     $methods = $reflector->getMethods();
     usort($methods, function (\ReflectionMethod $x, \ReflectionMethod $y) {
         return strcmp(trim(strtolower($x->getName())), trim(strtolower($y->getName())));
     });
     foreach ($methods as $i => $m) {
         if (!$m->isPublic()) {
             unset($methods[$i]);
         }
     }
     $content = 'No methods found.';
     if (!empty($methods)) {
         $content = '<table class="memberTable">';
         $content .= '<thead>';
         $content .= '<tr>';
         $content .= '<th class="memberName">Name</th>';
         $content .= '</tr>';
         $content .= '</thead>';
         $content .= '<tbody>';
         foreach ($methods as $m) {
             $content .= '<tr>';
             $content .= '<td>' . htmlentities($m->getName()) . '</td>';
             $content .= '</tr>';
         }
         $content .= '</tbody>';
         $content .= '</table>';
     }
     $result .= '<li class="accordion-navigation">';
     $result .= '<a href="#' . $accId . '" aria-expanded="false">Methods (' . trim(count($methods)) . ')</a>';
     $result .= '<div id="' . $accId . '" class="content">' . $content . '</div>';
     $result .= '</li>';
     $accId = "objProperties{$index}";
     $properties = $reflector->getProperties();
     usort($properties, function (\ReflectionProperty $x, \ReflectionProperty $y) {
         return strcmp(trim(strtolower($x->getName())), trim(strtolower($y->getName())));
     });
     foreach ($properties as $i => $p) {
         if (!$p->isPublic()) {
             unset($properties[$i]);
         }
     }
     $content = 'No properties found.';
     if (!empty($properties)) {
         $content = '<table class="memberTable">';
         $content .= '<thead>';
         $content .= '<tr>';
         $content .= '<th class="memberName">Name</th>';
         $content .= '<th>Current value</th>';
         $content .= '</tr>';
         $content .= '</thead>';
         $content .= '<tbody>';
         foreach ($properties as $p) {
             $content .= '<tr>';
             $content .= '<td>' . htmlentities($p->getName()) . '</td>';
             $content .= '<td>' . htmlentities(var_export($p->getValue($obj), true)) . '</td>';
             $content .= '</tr>';
         }
         $content .= '</tbody>';
         $content .= '</table>';
     }
     $result .= '<li class="accordion-navigation">';
     $result .= '<a href="#' . $accId . '" aria-expanded="false">Properties (' . trim(count($properties)) . ')</a>';
     $result .= '<div id="' . $accId . '" class="content">' . $content . '</div>';
     $result .= '</li>';
     $result .= '</ul>';
     return $result;
 }
Esempio n. 14
0
 protected final function get_tracking_file_name()
 {
     $obj = new ReflectionObject($this);
     return "test-results/" . $obj->getShortName() . ".json";
 }
 /**
  * @test
  */
 public function shouldLogOnInteractiveRequest()
 {
     $action = new FooAction();
     $interactiveRequest = $this->createInteractiveRequestMock();
     $ro = new \ReflectionObject($interactiveRequest);
     $logger = $this->createLoggerMock();
     $logger->expects($this->at(0))->method('debug')->with('[Payum] 1# FooAction::execute(string) throws interactive ' . $ro->getShortName());
     $extension = new LogExecutedActionsExtension($logger);
     $extension->onPreExecute('string');
     $extension->onInteractiveRequest($interactiveRequest, 'string', $action);
 }
Esempio n. 16
0
 /**
  * Recursively convert and add data to XML
  * 
  * @param \DOMDocument $xml			document to add data to
  * @param string $id				id of the data
  * @param mixed $object				data
  * 
  * @throws \Exception
  */
 public static function addToXML(\DOMDocument &$xml, $id, $object)
 {
     $object_xml = null;
     // no value, no mas!
     if ($object == "") {
         return null;
     } elseif ($object instanceof \DOMDocument) {
         $object_xml = $object;
     } elseif ($object instanceof \SimpleXMLElement) {
         // @todo: use convertToDOMDocument above
         $simple_xml = $object->asXML();
         if ($simple_xml != "") {
             if (!strstr($simple_xml, "<")) {
                 throw new \Exception("SimpleXMLElement was malformed");
             }
             $object_xml = new \DOMDocument();
             $object_xml->loadXML($simple_xml);
         }
     } elseif (is_object($object)) {
         // this object defines its own toXML method, so use that
         if (method_exists($object, "toXML")) {
             $object_xml = $object->toXML();
         } else {
             $reflection = new \ReflectionObject($object);
             // no id supplied, likely because this object was part of an array,
             // so take class name (no namespace) as id
             if (is_int($id)) {
                 $id = strtolower($reflection->getShortName());
             }
             // this object has a toArray method, so use that
             if (method_exists($object, "toArray")) {
                 // make it an array and feed it back
                 return self::addToXML($xml, $id, $object->toArray());
             } else {
                 $object_xml = new \DOMDocument();
                 $object_xml->loadXML("<{$id} />");
                 // only public properties, though
                 foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
                     self::addToXML($object_xml, $property->name, $property->getValue($object));
                 }
             }
         }
     } elseif (is_array($object)) {
         if (count($object) == 0) {
             return null;
         }
         $doc_element = "<{$id} />";
         if (is_int($id)) {
             $doc_element = "<object position=\"{$id}\" />";
         }
         $object_xml = new \DOMDocument();
         $object_xml->loadXML($doc_element);
         foreach ($object as $property => $value) {
             // if the name of the array is plural, then make the childen singular
             // if this is an array of objects, then the object may override this
             if (is_int($property) && substr($id, -1) == "s") {
                 if (substr($id, -3) == "ies") {
                     $property = substr($id, 0, -3) . 'y';
                 } else {
                     $property = substr($id, 0, -1);
                 }
             }
             self::addToXML($object_xml, $property, $value);
         }
     } else {
         // no id supplied, likely from array, so give it a proper name
         $attr = "";
         if (is_int($id)) {
             $attr = $id;
             $id = "object";
         }
         $str = self::escapeXml($object);
         // don't try to process empty strings
         if ($str == '') {
             return $xml;
         }
         // just create a simple new element and return this thing
         $element = '';
         // see if our id has no-no characters
         if (preg_match('/\\W/', $id)) {
             // make it an attribute instead
             $node_id = preg_replace('/\\W/', '', $id);
             $element = $xml->createElement($node_id, $str);
             $element->setAttribute('name', $id);
         } else {
             $element = $xml->createElement($id, $str);
         }
         if ($attr != '') {
             $element->setAttribute('position', $attr);
         }
         if ($element instanceof \DOMElement) {
             $xml->documentElement->appendChild($element);
         }
         return $xml;
     }
     // whoops!
     if (!$object_xml instanceof \DOMDocument) {
         throw new \Exception("Recursion error.");
     }
     // if we got this far, then we've got a domdocument to add
     $import = $xml->importNode($object_xml->documentElement, true);
     $xml->documentElement->appendChild($import);
     return $xml;
 }
Esempio n. 17
0
 public function getValidations()
 {
     $validations = array();
     /** @var Validation $validator */
     $validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();
     $class = get_class($this);
     $metadata = $validator->getMetadataFor(new $class());
     $constrainedProperties = $metadata->getConstrainedProperties();
     // loop for all properties' that has constraints / rules
     foreach ($constrainedProperties as $constrainedProperty) {
         $propertyMetadata = $metadata->getPropertyMetadata($constrainedProperty);
         $constraints = $propertyMetadata[0]->constraints;
         $outputConstraintsCollection = array();
         // loop for all constraints / rules
         foreach ($constraints as $constraint) {
             $class = new \ReflectionObject($constraint);
             $constraintName = $class->getShortName();
             switch ($constraintName) {
                 case "NotBlank":
                     $param = "notBlank";
                     break;
                 case "Type":
                     $param = $constraint->type;
                     break;
                 case "Choice":
                     $param = $constraint->choices;
                     break;
                 case "Url":
                     $param = $constraint->protocols;
                     break;
                 default:
                     $param = $constraint;
                     break;
             }
             $outputConstraintsCollection[$constraintName] = $param;
         }
         $sourceProp = preg_replace('/^_/', '', $this->convertToNonCamelCase($constrainedProperty));
         $validations[$sourceProp] = $outputConstraintsCollection;
     }
     return $validations;
 }
Esempio n. 18
0
 /**
  * Returns the name of the opened algorithm
  *
  * This function returns the name of the algorithm.
  *
  * @param \phpseclib\Crypt\Base $td
  * @return string|bool
  * @access public
  */
 function phpseclib_mcrypt_enc_get_algorithms_name(Base $td)
 {
     $reflection = new \ReflectionObject($td);
     switch ($reflection->getShortName()) {
         case 'Rijndael':
             return 'RIJNDAEL-' . $td->getBlockLength();
         case 'Twofish':
             return 'TWOFISH';
         case 'Blowfish':
             return 'BLOWFISH';
             // what about BLOWFISH-COMPAT?
         // what about BLOWFISH-COMPAT?
         case 'DES':
             return 'DES';
         case 'RC2':
             return 'RC2';
         case 'TripleDES':
             return 'TRIPLEDES';
         case 'RC4':
             return 'ARCFOUR';
     }
     return false;
 }
Esempio n. 19
0
 /**
  * Returns name representation of this class 
  *
  * @return string
  */
 public function className()
 {
     $ref = new \ReflectionObject($this);
     return $ref->getShortName();
 }
    /**
     * @test
     */
    public function shouldLogOnReply()
    {
        $action = new FooAction();
        $replyMock = $this->createReplyMock();

        $ro = new \ReflectionObject($replyMock);

        $logger = $this->createLoggerMock();
        $logger
            ->expects($this->at(0))
            ->method('debug')
            ->with('[Payum] 1# FooAction::execute(string) throws reply '.$ro->getShortName())
        ;

        $extension = new LogExecutedActionsExtension($logger);

        $extension->onPreExecute('string');
        $extension->onReply($replyMock, 'string', $action);
    }
Esempio n. 21
0
 /**
  * Return request xml root name
  * @return string
  */
 public function getXmlRootName()
 {
     $reflexion = new \ReflectionObject($this);
     return $reflexion->getShortName();
 }
 /**
  * @param EloquentModel $model
  * @param Relation $relation
  * @return string
  */
 protected function createMethodBody(EloquentModel $model, Relation $relation)
 {
     $reflectionObject = new \ReflectionObject($relation);
     $name = Str::camel($reflectionObject->getShortName());
     $arguments = [$model->getNamespace()->getNamespace() . '\\' . Str::singular(Str::studly($relation->getTableName()))];
     if ($relation instanceof BelongsToMany) {
         $defaultJoinTableName = $this->helper->getDefaultJoinTableName($model->getTableName(), $relation->getTableName());
         $joinTableName = $relation->getJoinTable() === $defaultJoinTableName ? null : $relation->getJoinTable();
         $arguments[] = $joinTableName;
         $arguments[] = $this->resolveArgument($relation->getForeignColumnName(), $this->helper->getDefaultForeignColumnName($model->getTableName()));
         $arguments[] = $this->resolveArgument($relation->getLocalColumnName(), $this->helper->getDefaultForeignColumnName($relation->getTableName()));
     } elseif ($relation instanceof HasMany) {
         $arguments[] = $this->resolveArgument($relation->getForeignColumnName(), $this->helper->getDefaultForeignColumnName($model->getTableName()));
         $arguments[] = $this->resolveArgument($relation->getLocalColumnName(), EmgHelper::DEFAULT_PRIMARY_KEY);
     } else {
         $arguments[] = $this->resolveArgument($relation->getForeignColumnName(), $this->helper->getDefaultForeignColumnName($relation->getTableName()));
         $arguments[] = $this->resolveArgument($relation->getLocalColumnName(), EmgHelper::DEFAULT_PRIMARY_KEY);
     }
     return sprintf('return $this->%s(%s);', $name, $this->prepareArguments($arguments));
 }
 /**
  * @param Relation $relation
  * @return string
  * @throws GeneratorException
  */
 protected function createMethodBody(Relation $relation)
 {
     $reflectionObject = new \ReflectionObject($relation);
     $name = Str::camel($reflectionObject->getShortName());
     $arguments = [Str::studly($relation->getTableName())];
     if ($relation instanceof BelongsToMany) {
         $defaultJoinTableName = TitleHelper::getDefaultJoinTableName($this->tableName, $relation->getTableName());
         $joinTableName = $relation->getJoinTable() === $defaultJoinTableName ? null : $relation->getJoinTable();
         $arguments[] = $joinTableName;
         $arguments[] = $this->resolveArgument($relation->getForeignColumnName(), TitleHelper::getDefaultForeignColumnName($this->getTableName()));
         $arguments[] = $this->resolveArgument($relation->getLocalColumnName(), TitleHelper::getDefaultForeignColumnName($relation->getTableName()));
     } elseif ($relation instanceof HasMany) {
         $arguments[] = $this->resolveArgument($relation->getForeignColumnName(), TitleHelper::getDefaultForeignColumnName($this->getTableName()));
         $arguments[] = $this->resolveArgument($relation->getLocalColumnName(), TitleHelper::$defaultPrimaryKey);
     } else {
         $arguments[] = $this->resolveArgument($relation->getForeignColumnName(), TitleHelper::getDefaultForeignColumnName($relation->getTableName()));
         $arguments[] = $this->resolveArgument($relation->getLocalColumnName(), TitleHelper::$defaultPrimaryKey);
     }
     return sprintf('return $this->%s(%s);', $name, $this->prepareArguments($arguments));
 }
Esempio n. 24
0
 /**
  * Retrieves default view path - which is PATH_TO_COMPONENT/View/__CLASS__/
  * @return string
  */
 protected function getDefaultViewPath()
 {
     $reflection = new \ReflectionObject($this);
     return Path::join(dirname($reflection->getFileName()), self::VIEW_DIR, $reflection->getShortName());
 }
Esempio n. 25
0
 /**
  * {@inheritdoc}
  */
 public function getName()
 {
     $reflection = new \ReflectionObject($this->exception);
     return $reflection->getShortName();
 }