Esempio n. 1
0
 /**
  * Gets the Module namespace.
  *
  * @return string The Module namespace
  *
  * @api
  */
 public function getNamespace()
 {
     if (null === $this->reflected) {
         $this->reflected = new \ReflectionObject($this);
     }
     return $this->reflected->getNamespaceName();
 }
Esempio n. 2
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?>";
 }
 /**
  * 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);
 }
 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);
 }
Esempio n. 5
0
 /**
  * @param $interface
  * @param array $data
  * @param array|null $mappings
  * @return mixed
  * @throws RuntimeException
  */
 protected function _mapObject($interface, array $data, array $mappings)
 {
     $object = $this->getObjectInstance($interface);
     $reflectionObject = new \ReflectionObject($object);
     $this->logger->debug(sprintf('Map object %s from interface %s', $reflectionObject->getNamespaceName(), $interface), array('data' => $data, 'mappings' => $mappings));
     foreach ($mappings as $attribute => $definition) {
         $property = $reflectionObject->getProperty($attribute);
         if ($property->isPrivate() || $property->isProtected()) {
             $property->setAccessible(true);
         }
         $value = $this->getAttributeValue($attribute, $definition, $data);
         $property->setValue($object, $value);
         $this->logger->debug(sprintf('Set attribute %s value ', $attribute), array('value' => $value));
     }
     return $object;
 }
Esempio n. 6
0
 /**
  * Return the view specified by the controller and view name, using data from the ViewBag
  * 
  * @param string $view_name
  * @param \MyArtJaub\Webtrees\Mvc\Controller\MvcControllerInterface $mvc_ctrl
  * @param \Fisharebest\Webtrees\Controller\BaseController $ctrl
  * @param \MyArtJaub\Webtrees\Mvc\View\ViewBag $data
  * @return \MyArtJaub\Webtrees\Mvc\View\AbstractView View
  * @throws \Exception
  */
 public function makeView($view_name, MvcController $mvc_ctrl, BaseController $ctrl, ViewBag $data)
 {
     if (!$mvc_ctrl) {
         throw new \Exception('Mvc Controller not defined');
     }
     if (!$ctrl) {
         throw new \Exception('Base Controller not defined');
     }
     if (!$view_name) {
         throw new \Exception('View not defined');
     }
     $mvc_ctrl_refl = new \ReflectionObject($mvc_ctrl);
     $view_class = $mvc_ctrl_refl->getNamespaceName() . '\\Views\\' . $view_name . 'View';
     if (!class_exists($view_class)) {
         throw new \Exception('View does not exist');
     }
     return new $view_class($ctrl, $data);
 }
Esempio n. 7
0
 /**
  *
  * @author leeboo
  *        
  * @param string $view_tpl
  *            模板的路径
  * @param string $format            
  * @return \yangzie\YZE_Simple_View
  *
  * @return
  *
  */
 protected function getResponse($view_tpl = null, $format = null)
 {
     $request = $this->request;
     $method = $request->the_method();
     if ($request->is_post()) {
         $method = substr($method, 5);
     }
     $view_data = $this->get_datas();
     $class_name = strtolower(get_class($this));
     $ref = new \ReflectionObject($this);
     if ($this->view) {
         $tpl = $this->view;
     } else {
         $tpl = substr(str_replace($ref->getNamespaceName() . "\\", "", $class_name), 0, -11) . "-" . $method;
     }
     $view = $view_tpl ? $view_tpl : $request->view_path() . "/" . $tpl;
     if (!$format) {
         $format = $request->get_output_format();
     }
     return new YZE_Simple_View($view, $view_data, $this, $format);
 }
Esempio n. 8
0
 /**
  * Autoloader for classes
  *
  * @param string $class
  */
 function autoload($class)
 {
     if (!preg_match('/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches)) {
         return;
     }
     static $reflection;
     if (empty($reflection)) {
         $reflection = new \ReflectionObject($this);
     }
     if ($reflection->getNamespaceName() !== $matches['namespace']) {
         return;
     }
     $autoload_name = $matches['autoload'];
     $autoload_dir = \trailingslashit($this->locations['class_dir']);
     $autoload_path = sprintf('%sclass-%s.php', $autoload_dir, strtolower(str_replace('_', '-', $autoload_name)));
     if (is_readable($autoload_path)) {
         require_once $autoload_path;
     }
 }
Esempio n. 9
0
 protected function detectAppNamespace()
 {
     $ref = new \ReflectionObject($this);
     return $ref->getNamespaceName();
 }
 /**
  * Returns the complete name for the IWorkflowSource class used to retrieve the definition of workflow $workflowId.
  * The class name is built by appending the workflow id to the `workflowSourceNamespace` parameter set for this factory component.
  *
  * @param string $workflowId a workflow id
  * @param Component|ActiveWorkflowBehavior $model the model that owns the workflow.
  *
  * @return string the full qualified class name implements IWorkflowSource used to provide definition for the workflow
  * @throws WorkflowException
  */
 public function getWorkflowSourceClassName($workflowId, $model)
 {
     if (isset($workflowId) && !$this->isValidWorkflowId($workflowId)) {
         throw new WorkflowException('Not a valid workflow Id : ' . $workflowId);
     }
     if (!isset($workflowId)) {
         $workflowId = $this->getDefaultWorkflowId($model);
     }
     $ns = $this->workflowSourceNamespace;
     if (!isset($ns)) {
         if (isset($model)) {
             $ro = new \ReflectionObject($model);
             $ns = $ro->getNamespaceName();
         }
         if (!isset($ns)) {
             $ns = self::DEFAULT_WORKFLOW_SOURCE_NAMESPACE;
         }
     }
     return $ns . '\\' . $workflowId . $this->workflowSourceSuffix;
 }
Esempio n. 11
0
 /**
  * @param $param
  * @param \ReflectionObject $reflection
  */
 private function buildFromObject($param, $reflection = null)
 {
     foreach ($param as $key => $value) {
         $this->object['Object default'][$key] = $value;
     }
     // Get info on the object
     $this->object['Reflection']['In namespace'] = $reflection->inNamespace() ? 'Yes' : 'No';
     if ($reflection->inNamespace()) {
         $this->object['Class namespace'] = $reflection->getNamespaceName();
     }
     $this->object['Reflection']['Class name'] = $reflection->getName();
     $this->object['Reflection']['Is internal'] = $reflection->isInternal() ? 'Yes' : 'No';
     $this->object['Reflection']['Is iterable'] = $reflection->isIterateable() ? 'Yes' : 'No';
     $this->object['Reflection']['Is abstract'] = $reflection->isAbstract() ? 'Yes' : 'No';
     $this->object['Reflection']['Is final'] = $reflection->isFinal() ? 'Yes' : 'No';
     $this->object['Reflection']['Is user defined'] = $reflection->isUserDefined() ? 'Yes' : 'No';
     $this->object['Reflection']['Is instantiable'] = $reflection->isInstantiable() ? 'Yes' : 'No';
     $this->object['Reflection']['Is clonable'] = $reflection->isCloneable() ? 'Yes' : 'No';
     $this->object['Reflection']['Is interface'] = $reflection->isInterface() ? 'Yes' : 'No';
     $this->object['Reflection']['Class constants'] = !empty($reflection->getConstants()) ? $reflection->getConstants() : 'Class has no constants';
     $this->object['Reflection']['Class static properties'] = !empty($reflection->getStaticProperties()) ? $reflection->getStaticProperties() : 'Class has no static properties';
     $this->object['Reflection']['Class default properties'] = !empty($reflection->getDefaultProperties()) ? $reflection->getDefaultProperties() : 'Class has no default properties';
     if (null === $reflection->getConstructor()) {
         $this->object['Reflection']['Class construct'] = 'Class has no construct.';
     } else {
         $this->object['Reflection']['Class construct'] = $reflection->getConstructor();
     }
     $this->object['Reflection']['Class interfaces'] = !empty($reflection->getInterfaces()) ? $reflection->getInterfaces() : 'Class implements no interfaces';
     $this->object['Reflection']['Class traits'] = !empty($reflection->getTraits()) ? $reflection->getTraits() : 'Class has no traits';
     $this->object['Reflection']['Class parent'] = $reflection->getParentClass() !== false ? $reflection->getParentClass() : 'Class has no parent';
     if (false === $reflection->getFileName()) {
         $this->object['Reflection']['Defined in'] = 'Class is internal, no definition to provide.';
     } else {
         $this->object['Reflection']['Defined in'] = $reflection->getFileName();
     }
     if (false === $reflection->getFileName()) {
         $this->object['Reflection']['Start line'] = 'Class is internal, no start line to provide.';
     } else {
         $this->object['Reflection']['Start line'] = $reflection->getFileName();
     }
     if (false === $reflection->getEndLine()) {
         $this->object['Reflection']['End line'] = 'Class is internal, no end line to provide.';
     } else {
         $this->object['Reflection']['End line'] = $reflection->getEndLine();
     }
     if (false === $reflection->getDocComment()) {
         $this->object['Reflection']['Doc comments'] = 'No documents to provide.';
     } else {
         $this->object['Reflection']['Doc comments'] = $reflection->getDocComment();
     }
     // End get info
     $this->html .= "<span class=\"js-parent-object\">";
     if (!empty($this->object['Object default'])) {
         $this->html .= "<div class=\"js-object-default-tab \"><button class=\"button-reflection button\">Show reflection</button></div>";
         $this->html .= "<div class=\"js-object-default \">";
         $this->buildFromObjectIterationInformationRecursive($this->object['Object default']);
         $this->html .= "</div>";
     }
     if ($param instanceof \Closure) {
         $this->html .= "<div class=\"js-object-default-tab \"><button class=\"button-reflection button\">Show reflection</button></div>";
         $this->html .= "<div class=\"js-object-default \">";
         $this->html .= "<span class=\"css-type-string\">Nothing here...</span>";
         $this->html .= "</div>";
     }
     $this->html .= "<div class=\"js-object-reflection-tab hide\"><button class=\"button-class-default button\">Show default</button></div>";
     $this->html .= "<div class=\"js-object-reflection hide\">";
     $this->buildFromObjectReflectionInformationRecursive($this->object['Reflection']);
     $this->html .= "</div>";
     $this->html .= "</span>";
     $this->object = [];
 }
Esempio n. 12
0
 /**
  * Initialize application settings base on reflection
  *
  * Set Path to folder where application is run
  * Set namespace of the appliacation class
  *
  * @return string
  */
 private function guessSettings()
 {
     $reflection = new \ReflectionObject($this);
     $this->appPath = str_replace('\\', '/', dirname($reflection->getFileName()));
     $this->namespace = $reflection->getNamespaceName();
 }
Esempio n. 13
0
 public function get_root_namespace()
 {
     $r = new \ReflectionObject($this);
     return $r->getNamespaceName();
 }
Esempio n. 14
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;
 }