public function __toString()
 {
     $str = '';
     $reflection_object = new ReflectionObject($this);
     $str .= 'Start: ' . $reflection_object->getName() . "\n";
     $file_name_formatter = new Formatting_FileName($this->get_name());
     $str .= $file_name_formatter->get_pretty_name();
     $str .= 'End: ' . $reflection_object->getName() . "\n";
     return $str;
 }
Esempio n. 2
0
 /**
  * @param $object
  * @return $this
  */
 public function register($object)
 {
     /** @var ReflectionObject $reflectionClass */
     $reflectionObject = new \ReflectionObject($object);
     if (!$this->objectRegistered($reflectionObject->getName())) {
         $this->objects[$reflectionObject->getName()] = $object;
     }
     //injection
     $this->resolveInjection($object);
     return $this;
 }
 public function generate($obj)
 {
     $refObj = new \ReflectionObject($obj);
     if ($refObj->implementsInterface("\\hvasoares\\phplombok\\GeneratedClass")) {
         return $obj;
     }
     $oldClassName = array_pop(explode("\\", $refObj->getName()));
     $newClassName = $oldClassName . (time() + rand());
     if (!$this->c->classExists(get_class($obj))) {
         $this->c->generateAndLoadClassFile(get_class($obj), $this->t->generateInheritedClass($newClassName, $obj));
         $this->f->configure($refObj->getName(), $refObj->getNamespaceName() . "\\" . $newClassName);
     }
     return $this->f->get($obj);
 }
 public function __toString()
 {
     $str = '';
     $reflection_object = new ReflectionObject($this);
     $str .= 'Start: ' . $reflection_object->getName() . "\n";
     $str .= "\$this->mysql_user:\n";
     $str .= "\n";
     $str .= $this->mysql_user->__toString();
     $str .= "\n";
     $str .= "\$this->name:\n";
     $str .= $this->name;
     $str .= "\n";
     $str .= 'End: ' . $reflection_object->getName() . "\n";
     return $str;
 }
 function serializeObject($object)
 {
     if ($object instanceof Exception) {
         echo '<error>';
         $this->writeTag('code', $object->getCode());
         $this->writeTag('message', $object->getMessage());
         echo '</error>';
     } else {
         // get object class
         $reflectObject = new ReflectionObject($object);
         $class = $reflectObject->getName();
         // write the object type
         $this->writeTag('objectType', $class);
         // load class reflection
         $typeReflector = KalturaTypeReflectorCacher::get($class);
         if (!$typeReflector) {
             echo '<error>';
             $this->writeTag('message', 'Type reflector not found');
             echo '</error>';
             return;
         }
         $properties = $typeReflector->getProperties();
         foreach ($properties as $property) {
             $name = $property->getName();
             $value = $object->{$name};
             if ($this->_ignoreNull === true && $value === null) {
                 continue;
             }
             echo '<' . $name . '>';
             $this->serialize($value);
             echo '</' . $name . '>';
         }
     }
 }
Esempio n. 6
0
 /**
  * Processes the handler pre-run.
  * 
  * @param Glimpse $glimpse The current Glimpse instance.
  * @return string The rendered handler.
  */
 public function processPreRun(Glimpse $glimpse)
 {
     if (!isset($_REQUEST['glimpseFile']) || $_REQUEST['glimpseFile'] != 'Config') {
         return;
     }
     echo "<!DOCTYPE html><html><head><link rel=\"shortcut icon\" href=\"http://getglimpse.com/favicon.ico\" />";
     echo "<style>body { margin: 0px; text-align:center; font-family:\"avante garde\", \"Century Gothic\", Serif; font-size:0.8em; line-height:1.4em; } .important { font-size:1.4em; } .content { position:absolute; left:50%; margin-left:-450px; text-align:left; width:900px; } h1, h2, h3, h4 { line-height:1.2em; font-weight:normal; } h1 { font-size:4em; } h2 { font-size:2.5em; } h3 { font-size:2em; } .logo { font-family: \"TitilliumMaps\", helvetica, sans-serif; margin:0 0 40px; position:relative; background: url(?glimpseFile=logo.png) -10px -15px no-repeat; padding: 0 0 0 140px; } .logo h1 { color:transparent; } .logo div { font-size:1.5em; margin: 25px 0 0 -10px; } .logo blockquote { width:350px; position:absolute; right:0; top:10px; } blockquote { font: 1.2em/1.6em \"avante garde\", \"Century Gothic\", Serif; width: 400px; background: url(http://getglimpse.com/Content/close-quote.gif) no-repeat right bottom; padding-left: 18px; text-indent: -18px; } .footer { text-align:center; margin-bottom:30px; } blockquote:first-letter { background: url(http://getglimpse.com/Content/open-quote.gif) no-repeat left top; padding-left: 18px; font: italic 1.4em \"avante garde\", \"Century Gothic\", Serif; } .myButton{width:175px; line-height: 1.2em; margin:0.25em 0; text-align:center; -moz-box-shadow:inset 0 1px 0 0 #fff;-webkit-box-shadow:inset 0 1px 0 0 #fff;box-shadow:inset 0 1px 0 0 #fff;background:-webkit-gradient(linear,left top,left bottom,color-stop(0.05,#ededed),color-stop(1,#dfdfdf));background:-moz-linear-gradient(center top,#ededed 5%,#dfdfdf 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed',endColorstr='#dfdfdf');background-color:#ededed;-moz-border-radius:6px;-webkit-border-radius:6px;border-radius:6px;border:1px solid #dcdcdc;display:inline-block;color:#777;font-family:arial;font-size:24px;padding:10px 41px;text-decoration:none;text-shadow:1px 1px 0 #fff}.myButton:hover{background:-webkit-gradient(linear,left top,left bottom,color-stop(0.05,#dfdfdf),color-stop(1,#ededed));background:-moz-linear-gradient(center top,#dfdfdf 5%,#ededed 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf',endColorstr='#ededed');background-color:#dfdfdf}.myButton:active{position:relative;top:1px}</style>";
     echo "<title>Glimpse Config</title>";
     echo "<script>function toggleCookie(){var mode = document.getElementById('glimpseState'); if (mode.innerHTML==='On'){mode.innerHTML='Off';document.cookie='glimpseState=Off; path=/;';}else{mode.innerHTML='On';document.cookie='glimpseState=On; path=/;';}}</script>";
     echo "<head><body>";
     if (isset($_COOKIE["glimpseState"]) && $_COOKIE["glimpseState"] == 'On') {
         echo "<div style='background-color: #B5CDA4; border-bottom: thin solid #486E25; color: #486E25; padding: 6px; font-size: 1.2em; position: fixed; width: 100%; z-index: 499;'><strong>Glimpse is now ON</strong> - When you <a href='javascript:history.back(1);'>go back</a> to your site you should see Glimpse at the bottom right of the page.</div>";
     }
     echo "<div class=\"content\"><div class=\"logo\"><blockquote>What Firebug is for the client, Glimpse does for the server... in other words, a client side Glimpse into whats going on in your server.</blockquote><h1>Glimpse</h1><div>A client side Glimpse to your server</div></div>";
     echo "<table width=\"100%\"><tr align=\"center\"><td width=\"33%\"><a class=\"myButton\" href=\"javascript:(function(){document.cookie='glimpseState=On; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Turn Glimpse On</a></td><td width=\"34%\"><a class=\"myButton\" href=\"javascript:(function(){document.cookie='glimpseState=; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Turn Glimpse Off</a></td><td><a class=\"myButton\" href=\"javascript:(function(){document.cookie='glimpseClientName='+ prompt('Client Name?') +'; path=/; expires=Sat, 01 Jan 2050 12:00:00 GMT;'; window.location.reload();})();\">Set Glimpse Session Name</a></td></tr></table>";
     echo "<p style=\"text-align:center\">Drag the above button to your favorites bar for quick and easy access to Glimpse.</p>";
     echo "<h2>Your Settings:</h2><p>This section tells you how Glimpse sees your requests.</p><ul><li>glimpseState = <label for='gChk' id='glimpseState'>" . (isset($_COOKIE['glimpseState']) && $_COOKIE['glimpseState'] != '' ? $_COOKIE['glimpseState'] : 'Off') . "</label></li></ul>";
     echo "<h2>Plugins:</h2><p>This is the list of Glimpse plugins for this web application. Glimpse plugins show up as individual tabs in the Glimpse client. You can stop a plugin from being loaded by setting the <em>plugins-disabled</am> value in <em>glimpse.ini</em>.</p><ul>";
     foreach ($glimpse->retrievePlugins() as $plugin) {
         $pluginClass = new ReflectionObject($plugin);
         echo "<li>" . $pluginClass->getName() . "</li>";
     }
     echo "</ul>";
     echo "<h2>More Info:</h2>";
     echo "<div class=\"footer\"><span class=\"important\">For more info see <a href=\"http://getGlimpse.com\" />getGlimpse.com</a></span><br /><br /><img src=\"http://getglimpse.com/content/uservoice-icon.png\" width=\"16\" /> Have a <em>feature</em> request? <a href=\"http://getglimpse.uservoice.com\">Submit the idea</a>. &nbsp; &nbsp; <img src=\"http://getglimpse.com/content/github.gif\" /> Found an <em>error</em>? <a href=\"https://github.com/glimpse/glimpse/issues\">Help us improve</a>. &nbsp; &nbsp;<img src=\"http://getglimpse.com/content/twitter.png\" /> Have a <em>question</em>? <a href=\"http://twitter.com/#search?q=%23glimpse\">Tweet us using #glimpse</a>.</div>";
     echo "</body></html>";
     $glimpse->endRequest();
 }
Esempio n. 7
0
File: Creator.php Progetto: cwcw/cms
 /**
  * Set the creation parameters
  *
  * @param array $creationParams
  * @return void
  */
 public function setCreationParams(array $creationParams)
 {
     if (empty($creationParams)) {
         return;
     }
     $r = new ReflectionObject($this);
     $class = $r->getName();
     $constants = $r->getConstants();
     $parameterConstants = array_filter(array_keys($constants), array($this, '_getParameterConstants'));
     $supportedParameters = array();
     for ($i = 0, $n = count($parameterConstants); $i < $n; $i++) {
         $constant = $parameterConstants[$i];
         $supportedParameters[] = constant($class . '::' . $constant);
     }
     if (empty($supportedParameters)) {
         return;
     }
     foreach ($creationParams as $param => $value) {
         if (in_array($param, $supportedParameters)) {
             $method = 'set' . ucfirst($param);
             if (method_exists($this, $method)) {
                 $this->{$method}($value);
             }
         }
     }
 }
Esempio n. 8
0
 /**
  * Replace placeholder one by one
  *
  * @param string $template hystack
  * @param string $value replacement
  * @param int $position placeholder position
  * @return string
  */
 protected function replace($template, $value, $position = 1)
 {
     $arrayToString = new ArrayToString();
     $needle = sprintf($this->configTemplate, (int) $position);
     if (strpos($template, $needle) !== false) {
         if (is_array($value)) {
             $string = $arrayToString->filter($value);
         } else {
             if ($value instanceof \Exception) {
                 $obj = new \ReflectionObject($value);
                 $string = "Exception Object: " . $obj->getName();
                 $string .= "\n Message: " . $value->getMessage();
                 $string .= "\n Trace: " . $value->getTraceAsString();
             } else {
                 if (is_object($value)) {
                     $obj = new \ReflectionObject($value);
                     $string = "Object with name : " . $obj->getName();
                 } else {
                     $string = (string) $value;
                 }
             }
         }
         return str_replace($needle, $string, $template);
     }
     return $template;
 }
Esempio n. 9
0
 function serializeObject($object)
 {
     if ($object instanceof Exception) {
         $this->writeStartTag("error");
         $this->writeTag("code", $object->getCode());
         $this->writeTag("message", $object->getMessage());
         $this->writeEndTag("error");
     } else {
         // get object class
         $reflectObject = new ReflectionObject($object);
         $class = $reflectObject->getName();
         // load class reflection
         $typeReflector = KalturaTypeReflectorCacher::get($class);
         $properties = $typeReflector->getProperties();
         // write the object type
         $this->writeTag("objectType", $class);
         foreach ($properties as $property) {
             $name = $property->getName();
             $value = $object->{$name};
             if ($this->_ignoreNull === true && $value === null) {
                 continue;
             }
             $this->writeStartTag($name);
             $this->serialize($value);
             $this->writeEndTag($name);
         }
     }
 }
Esempio n. 10
0
function QcodoHandleException(Exception $__exc_objException)
{
    QApplication::$ErrorFlag = true;
    global $__exc_strType;
    if (isset($__exc_strType)) {
        return;
    }
    $__exc_objReflection = new ReflectionObject($__exc_objException);
    $__exc_strType = "Exception";
    $__exc_strMessage = $__exc_objException->getMessage();
    $__exc_strObjectType = $__exc_objReflection->getName();
    if ($__exc_objException instanceof QDatabaseExceptionBase) {
        $__exc_objErrorAttribute = new QErrorAttribute("Database Error Number", $__exc_objException->ErrorNumber, false);
        $__exc_objErrorAttributeArray[0] = $__exc_objErrorAttribute;
        if ($__exc_objException->Query) {
            $__exc_objErrorAttribute = new QErrorAttribute("Query", $__exc_objException->Query, true);
            $__exc_objErrorAttributeArray[1] = $__exc_objErrorAttribute;
        }
    }
    $__exc_strFilename = $__exc_objException->getFile();
    $__exc_intLineNumber = $__exc_objException->getLine();
    $__exc_strStackTrace = trim($__exc_objException->getTraceAsString());
    if (ob_get_length()) {
        $__exc_strRenderedPage = ob_get_contents();
        ob_clean();
    }
    // Call to display the Error Page (as defined in configuration.inc.php)
    require __DOCROOT__ . ERROR_PAGE_PATH;
    exit;
}
 public function getName()
 {
     if (null === $this->name) {
         $r = new \ReflectionObject($this);
         $this->name = strtolower(preg_replace(['/(.+?)Kernel$/', '/([A-Z]+)([A-Z][a-z])/', '/([a-z\\d])([A-Z])/'], ['\\1', '\\1_\\2', '\\1_\\2'], $r->getName()));
     }
     return $this->name;
 }
Esempio n. 12
0
 public function testReaderResultIsCached()
 {
     $testCase = new TestsCases\BaseTestCase();
     $classInformation = Reader::getClassInformation($testCase);
     $reflectionObject = new \ReflectionObject($testCase);
     $cacheId = md5("classInformation:" . $reflectionObject->getName());
     $this->assertEquals($classInformation, Reader::getFromCache($cacheId));
 }
 public function __toString()
 {
     $str = '';
     $reflection_object = new ReflectionObject($this);
     $str .= 'Start: ' . $reflection_object->getName() . "\n";
     $str .= "\$this->project_directories:\n";
     if (count($this->project_directories) == 0) {
         $str .= "<Empty List>\n";
     } else {
         foreach ($this->project_directories as $p_d) {
             $str .= $p_d;
             $str .= "\n";
         }
     }
     $str .= 'End: ' . $reflection_object->getName() . "\n";
     return $str;
 }
Esempio n. 14
0
 public function generateInheritedClass($newClassName, $obj)
 {
     $refObj = new \ReflectionObject($obj);
     $innerCode = $this->s->generateCode($newClassName, $obj);
     $innerCode = str_replace("\n", "\n\t", $innerCode);
     $className = array_pop(explode("\\", $refObj->getName()));
     $namespace = $refObj->getNamespaceName();
     return "<?php\nnamespace {$namespace};\nclass {$newClassName} extends {$className} implements \\hvasoares\\phplombok\\GeneratedClass{\n\tpublic function setAnnotatedObject(\$object){\n\t\t\$this->annotatedObject = \$object;\n\t\t\$this->reflectedObject = new \\ReflectionObject(\$object);\n\t}\n\n\tpublic function getAnnotatedObject(){\n\t\treturn \$this->annotatedObject;\n\t}\n\t{$innerCode}\t\n}\n?>";
 }
 protected function _getExceptionClass()
 {
     $reflection = new \ReflectionObject($this);
     // Elastica\Test\Exception\RuntimeExceptionTest => Elastica\Exception\RuntimeExceptionTest
     $name = preg_replace('/^Elastica\\\\Test/', 'Elastica', $reflection->getName());
     // Elastica\Exception\RuntimeExceptionTest => Elastica\Exception\RuntimeException
     $name = preg_replace('/Test$/', '', $name);
     return $name;
 }
Esempio n. 16
0
 /**
  * RegisterDataExtension() - Register a new data extension in the core, providing a distinct set of data
  *
  * RegisterDataExtension() is designed for public use, since any extension/plugin can register new data extensions. 
  * An extension object should be registered ONCE (else this will cause useless dupes of extensions in memory).
  *
  * @param $extension bbDataExtension  Data extension object to register
  */
 public function RegisterDataExtension(bbDataExtension $extension)
 {
     $reflexion = new ReflectionObject($extension);
     if (defined('BB_DEBUG')) {
         $this->DebugOutput("RegisterDataExtension(): Registering data extension " . $reflexion->getName());
     }
     $object->coreReference = $this;
     $this->datastreams[] = $extension;
 }
Esempio n. 17
0
 public function commit()
 {
     foreach ($this->persisted as $k => $entity) {
         $reflection = new \ReflectionObject($entity);
         $persister = $this->getEnityPersister($reflection->getName());
         $persister->save($entity);
         unset($this->persisted[$k]);
     }
 }
 /**
  * Convert an object using the getter of this one, and if it has some foreign relationship, we use also the id of the foreign objects
  *
  * @param unknown $object  The object to convert
  * @param string  $format  Not used here, keeped for compatibility
  * @param array   $context Not used here, keeped for compatibility
  *
  * @return multitype:multitype:multitype:mixed
  */
 public function normalize($object, $format = null, array $context = array())
 {
     $reflectionObject = new \ReflectionObject($object);
     $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC);
     $attributes = array();
     foreach ($reflectionMethods as $method) {
         if ($this->isGetMethod($method)) {
             $attributeName = lcfirst(substr($method->name, 3));
             //we sub the set or get
             if (in_array($attributeName, $this->ignoredAttributes)) {
                 continue;
             }
             $attributeValue = $method->invoke($object);
             if (array_key_exists($attributeName, $this->callbacks)) {
                 $attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue);
             }
             if (null !== $attributeValue && !is_scalar($attributeValue)) {
                 if (get_class($attributeValue) == 'Doctrine\\ORM\\PersistentCollection') {
                     //memorize the list of persistent collections
                     $attributeValues = $attributeValue;
                     $attributeValue = array();
                     foreach ($attributeValues as $obj) {
                         $attributeReflectionObject = new \ReflectionObject($obj);
                         $identifiers = $this->doctrine->getManager()->getMetadataFactory()->getMetadataFor($attributeReflectionObject->getName())->getIdentifier();
                         //the ids to add
                         $tempAttribute = array();
                         foreach ($identifiers as $identifier) {
                             $attribute = call_user_func(array($obj, 'get' . ucfirst($identifier)));
                             //the attribute is itself an object
                             if (is_object($attribute)) {
                                 //we look for the ids
                                 $attributeIdentifierReflectionObject = new \ReflectionObject($attribute);
                                 $attributeIdentifiers = $this->doctrine->getManager()->getMetadataFactory()->getMetadataFor($attributeIdentifierReflectionObject->getName())->getIdentifier();
                                 foreach ($attributeIdentifiers as $index => $attributeIdentifier) {
                                     $attributeIdentifierAttribute = call_user_func(array($attribute, 'get' . ucfirst($attributeIdentifier)));
                                     //@todo use reflection to know the identifier
                                     //we add each of the ids
                                     $tempAttribute[$identifier] = $attributeIdentifierAttribute;
                                 }
                             } else {
                                 //we memorise the array of ids
                                 $tempAttribute[$identifier] = $attribute;
                             }
                         }
                         //we add the id to the array of the attribute
                         $attributeValue[] = $tempAttribute;
                     }
                 } else {
                     $attributeValue = $attributeValue->getId();
                     //@todo use reflection to know the identifier
                 }
             }
             $attributes[$attributeName] = $attributeValue;
         }
     }
     return $attributes;
 }
 /**
  * Processes an incoming request, executes it and builds a response.
  *
  * @since 5.1
  * @param ModuleServerRequest $request Incoming request.
  * @param ModuleServerResponse $response Outcoming response.
  * @return void
  */
 public function process(ModuleServerRequest $request, ModuleServerResponse $response)
 {
     $command = explode(' ', $request->getCommand());
     $module_location = $command[1];
     if (!strlen($module_location)) {
         $response->sendWarning(ModuleServerResponse::SC_NOT_FOUND, 'Module location not defined.', ModuleServerRsponse::ERROR_CLASSNAME_MISSING);
         return;
     }
     try {
         $locator = new ModuleLocator('module://' . $request->getHeader('User') . ':' . $request->getHeader('Password') . '@/' . $module_location);
         $sessionId = $request->getHeader('Session');
         if ($sessionId) {
             $this->module = ModuleFactory::getSessionModule($locator, $sessionId);
         } else {
             $this->module = ModuleFactory::getModule($locator);
         }
     } catch (ModuleException $e) {
         $response->sendWarning(ModuleServerResponse::SC_INTERNAL_SERVER_ERROR, $e->__toString());
         return;
     } catch (\Exception $e) {
         $response->sendWarning(ModuleServerResponse::SC_INTERNAL_SERVER_ERROR, $e->__toString());
         return;
     }
     if (!($xmlrpc_server = xmlrpc_server_create())) {
         $response->sendWarning(ModuleServerResponse::SC_INTERNAL_SERVER_ERROR, 'Internal error: Could not create an XML-RPC server.', ModuleServerResponse::ERROR_XMLRPC_ERROR);
         return;
     }
     $theClass = new \ReflectionObject($this->module);
     $methods = $theClass->getMethods();
     foreach ($methods as $method) {
         // Ignore private methods
         $theMethod = new \ReflectionMethod($theClass->getName(), $method->getName());
         if (!$theMethod->isPublic()) {
             continue;
         }
         // Expose only methods beginning with "module" prefix
         if (!(substr($method->getName(), 0, 6) == 'module')) {
             continue;
         }
         xmlrpc_server_register_method($xmlrpc_server, strtolower($method->getName()), array($this, 'xmlrpcGateway'));
     }
     xmlrpc_server_register_introspection_callback($xmlrpc_server, array($this, 'introspectionGateway'));
     try {
         $buffer = xmlrpc_server_call_method($xmlrpc_server, $request->getPayload(), '', array('output_type' => 'xml'));
         $response->addHeader('Module/1.0 ' . ModuleServerResponse::SC_OK);
         $response->setBuffer($buffer);
     } catch (\Exception $e) {
         $response->addHeader('Module/1.0 ' . ModuleServerResponse::SC_INTERNAL_ERROR);
         $response->setBuffer($buffer);
     }
     xmlrpc_server_destroy($xmlrpc_server);
     $context = new ModuleContext($module_location);
     $session = new \Innomatic\Module\Session\ModuleSession($context, $sessionId);
     $session->save($this->module);
     $response->addHeader('Session: ' . $session->getId());
 }
 public function castEvent(\FS\Context\ApplicationEventInterface $event)
 {
     $reflected = new \ReflectionObject($event);
     $eventName = $reflected->getName();
     foreach ($this->listeners as $listener) {
         if ($eventName == $listener->getSupportedEvent()) {
             return $this->invokeListener($listener, $event);
         }
     }
 }
Esempio n. 21
0
 protected function objectType($value, $maxIterations)
 {
     $reflector = new \ReflectionObject($value);
     $class = $reflector->getName();
     $traversableSubTypes = '';
     if ($value instanceof \Traversable) {
         $traversableSubTypes = $this->traversableSubTypes($value, $maxIterations);
     }
     return \sprintf('%s%s', $class, $traversableSubTypes);
 }
Esempio n. 22
0
 function doStartTag($application, $parentHandler, $args)
 {
     error_log('fbRequestFormHandler->doStartTag()');
     $obj = new ReflectionObject($parentHandler);
     error_log('parent handler: ' . $obj->getName());
     $this->type = $args['type'];
     $this->payment = $args['payment'];
     echo '<form id="form-friend-select" action="">';
     return array('fb:multi-friend-selector');
 }
 /**
  * Loads definitions and translations from provided context.
  *
  * @param ContextInterface $context
  * @param StepNode         $step
  *
  * @return DefinitionSnippet
  */
 public function propose(ContextInterface $context, StepNode $step)
 {
     $contextRefl = new \ReflectionObject($context);
     $contextClass = $contextRefl->getName();
     $replacePatterns = array("/(?<= |^)\\\\'(?:((?!\\').)*)\\\\'(?= |\$)/", '/(?<= |^)\\"(?:[^\\"]*)\\"(?= |$)/', '/(\\d+)/');
     $text = $step->getText();
     $text = preg_replace('/([\\/\\[\\]\\(\\)\\\\^\\$\\.\\|\\?\\*\\+\'])/', '\\\\$1', $text);
     $regex = preg_replace($replacePatterns, array("\\'([^\\']*)\\'", "\"([^\"]*)\"", "(\\d+)"), $text);
     preg_match('/' . $regex . '/', $step->getText(), $matches);
     $count = count($matches) - 1;
     $methodName = preg_replace($replacePatterns, '', $text);
     $methodName = Transliterator::transliterate($methodName, ' ');
     $methodName = preg_replace('/[^a-zA-Z\\_\\ ]/', '', $methodName);
     $methodName = str_replace(' ', '', ucwords($methodName));
     if (0 !== strlen($methodName)) {
         $methodName[0] = strtolower($methodName[0]);
     } else {
         $methodName = 'stepDefinition1';
     }
     // get method number from method name
     $methodNumber = 2;
     if (preg_match('/(\\d+)$/', $methodName, $matches)) {
         $methodNumber = intval($matches[1]);
     }
     // check that proposed method name isn't arelady defined in context
     while ($contextRefl->hasMethod($methodName)) {
         $methodName = preg_replace('/\\d+$/', '', $methodName);
         $methodName .= $methodNumber++;
     }
     // check that proposed method name haven't been proposed earlier
     if (isset(self::$proposedMethods[$contextClass])) {
         foreach (self::$proposedMethods[$contextClass] as $proposedRegex => $proposedMethod) {
             if ($proposedRegex !== $regex) {
                 while ($proposedMethod === $methodName) {
                     $methodName = preg_replace('/\\d+$/', '', $methodName);
                     $methodName .= $methodNumber++;
                 }
             }
         }
     }
     self::$proposedMethods[$contextClass][$regex] = $methodName;
     $args = array();
     for ($i = 0; $i < $count; $i++) {
         $args[] = "\$arg" . ($i + 1);
     }
     foreach ($step->getArguments() as $argument) {
         if ($argument instanceof PyStringNode) {
             $args[] = "PyStringNode \$string";
         } elseif ($argument instanceof TableNode) {
             $args[] = "TableNode \$table";
         }
     }
     $description = $this->generateSnippet($regex, $methodName, $args);
     return new DefinitionSnippet($step, $description);
 }
Esempio n. 24
0
 /**
  * Loads definitions and translations from provided context.
  *
  * @param ContextInterface $context
  */
 public function load(ContextInterface $context)
 {
     $reflection = new \ReflectionObject($context);
     foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodRefl) {
         foreach ($this->readMethodAnnotations($reflection->getName(), $methodRefl) as $annotation) {
             if ($annotation instanceof HookInterface) {
                 $this->hookDispatcher->addHook($annotation);
             }
         }
     }
 }
Esempio n. 25
0
 /**
  * Gets the plugin data that should be rendered on the output protocol stream.
  * 
  * @param Glimpse $glimpse The current Glimpse instance.
  * @return array Array conforming to the Glimpse protocol definition.
  */
 public function getData(Glimpse $glimpse)
 {
     $data = array();
     $plugins = $glimpse->retrievePlugins();
     foreach ($plugins as $plugin) {
         $reflectedObject = new ReflectionObject($plugin);
         $pluginName = basename('/' . str_replace('_', '/', $reflectedObject->getName()));
         $data[$pluginName] = array('helpUrl' => !is_null($plugin->getHelpUrl()) ? $plugin->getHelpUrl() : '');
     }
     return array("plugins" => $data);
 }
Esempio n. 26
0
 /**
  * Displays an information about single aspect
  *
  * @param SymfonyStyle $io Input-output style
  * @param Aspect $aspect Instance of aspect
  */
 private function showAspectInfo(SymfonyStyle $io, Aspect $aspect)
 {
     $refAspect = new \ReflectionObject($aspect);
     $aspectName = $refAspect->getName();
     $io->section($aspectName);
     $io->writeln('Defined in: <info>' . $refAspect->getFileName() . '</info>');
     $docComment = $refAspect->getDocComment();
     if ($docComment) {
         $io->writeln($this->getPrettyText($docComment));
     }
     $this->showAspectPointcutsAndAdvisors($io, $aspect);
 }
Esempio n. 27
0
 function templateFileName($templateName)
 {
     if ($templateName != null) {
         if (!StringHelper::endsWith($templateName, '.html')) {
             $templateName .= '.html';
         }
         return $templateName;
     }
     $rc = new ReflectionObject($this);
     $filename = $rc->getName() . '.html';
     return $filename;
 }
Esempio n. 28
0
 /**
  * Get the child controller object.
  *
  * Gets the new child controller object from the child controller class
  * method. If the method does not exist, or the returned value is not a
  * controller object, a \RuntimeException is thrown.
  *
  * @throws \RuntimeException
  * @param $controllerName
  * @return Controller
  */
 public function getChildController($controllerName)
 {
     $methodName = $this->parseControllerName($controllerName);
     if (!$this->reflection->hasMethod($methodName)) {
         throw new \RuntimeException("{$this->reflection->getName()}::{$methodName} does not exist");
     }
     $controller = $this->reflection->getMethod($methodName)->invokeArgs($this->controller, []);
     if (!is_object($controller) || !$controller instanceof Controller) {
         throw new \RuntimeException("{$this->reflection->getName()}::{$methodName} did not return a Controller");
     }
     return $controller;
 }
Esempio n. 29
0
 /**
  * Make an array of keys->values (eventually filtered by $modifier) from
  * object's properties.
  *
  * @param mixed $modifier Filtering callable
  *
  * @return array The resulting array
  */
 public function toArray($modifier = null)
 {
     $this->getReflector();
     $final = array();
     $props = $this->getClassProperties($this->reflector->getName());
     foreach ($props as $property) {
         $value = $this->get($property->getName());
         if (\is_callable($modifier)) {
             $value = \call_user_func_array($modifier, array($value));
         }
         $final[$property->getName()] = $value;
     }
     return $final;
 }
Esempio n. 30
0
 private function getParameterClassName($setter)
 {
     $object = new ReflectionObject($this);
     $className = $object->getName();
     $method = new ReflectionMethod($className, $setter);
     $parameter = $method->getParameters();
     $parameter = $parameter[0];
     $parameterClass = $parameter->getClass();
     if (!$parameter->isArray() && is_null($parameterClass)) {
         //throw new Exception("O paramentro \"\${$parameter->getName()}\" do metodo \"{$className}->{$setter}\" nao possui um tipo definido!");
         return "undefined";
     }
     $parameterClassName = $parameter->isArray() ? "array" : $parameterClass->getName();
     return $parameterClassName;
 }