Example #1
0
 /**
  * @param string|mixed $class
  */
 public function registerPlugins($class)
 {
     switch (true) {
         case is_string($class):
             $class = is_string($class) ? new $class() : $class;
         case $class instanceof AbstractHelper:
             $reflector = new \ReflectionClass($class);
             $path = realpath(dirname($reflector->getFileName()));
             $class = array();
             foreach (scandir($path) as $file) {
                 if (strpos($file, '.php') !== FALSE && strpos($file, 'Abstract') === FALSE) {
                     $className = str_replace('.php', '', $file);
                     $class[lcfirst($className)] = $reflector->getNamespaceName() . '\\' . $className;
                     $p = strtolower(preg_replace("/([a-z])([A-Z])/", "\$1_\$2", $className));
                     $class[$p] = $reflector->getNamespaceName() . '\\' . $className;
                 }
             }
             break;
         case is_array($class):
             break;
         default:
             throw new \Exception('Invalid input for $class variable. Type must be string, Zend\\Form\\View\\Helper\\AbstractHelper or array.');
     }
     foreach ($class as $name => $invokableClass) {
         $this->registerPlugin($name, $invokableClass);
     }
     return $this;
 }
 protected static function qualifiedClass(\ReflectionClass $class, $type)
 {
     if (substr($type, 0, 1) == '\\') {
         return substr($type, 1);
     }
     $classNamespace = $class->getNamespaceName();
     if (!($uses = self::$namespaceUses[$classNamespace])) {
         $scriptContent = file_get_contents($class->getFileName());
         $scriptContent = substr($scriptContent, strpos($scriptContent, 'namespace ' . $class->getNamespaceName()));
         preg_match_all("/use\\s+([a-z]+(\\\\[a-z]+)*);/i", $scriptContent, $uses);
         if (isset($uses[1])) {
             $uses = $uses[1];
         } else {
             $uses = [];
         }
         $_temp = [];
         foreach ($uses as $use) {
             $parts = explode('\\', $use);
             $className = end($parts);
             $_temp[$className] = implode('\\', array_slice($parts, 0, -1));
         }
         $uses = $_temp;
         self::$namespaceUses[$classNamespace] = $uses;
     }
     if (isset($uses[$type])) {
         $classNamespace = $uses[$type];
     }
     return $classNamespace . '\\' . $type;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function toObjectValue($value, $type, \ReflectionProperty $property, $object)
 {
     $className = null;
     $context = new \ReflectionClass($property->class);
     //try to get the class from use statements in the class file
     if ($className === null) {
         $classContent = file_get_contents($context->getFileName());
         $regExps = ["/use\\s+([\\w\\\\]+{$type});/", "/use\\s+([\\w\\\\]+)\\s+as\\s+{$type}/"];
         foreach ($regExps as $regExp) {
             if ($matchClass = $this->extractClass($regExp, $classContent)) {
                 $className = $matchClass;
                 break;
             }
         }
     }
     //use the same namespace as class container
     if ($className === null && class_exists($context->getNamespaceName() . '\\' . $type)) {
         $className = $context->getNamespaceName() . '\\' . $type;
     }
     //use the type as class
     if (class_exists($type)) {
         $className = $type;
     }
     if (is_array($value) && $className !== null && class_exists($className) && $this->array2Object) {
         $property->setAccessible(true);
         $currentValue = $property->getValue($object);
         if (is_object($currentValue)) {
             $this->array2Object->populate($currentValue, $value);
             return $currentValue;
         } else {
             return $this->array2Object->createObject($className, $value);
         }
     }
     return $value;
 }
 /**
  * Generate Remote API from a list of controllers
  */
 public function generateRemotingApi()
 {
     $list = array();
     foreach ($this->remotingBundles as $bundle) {
         $bundleRef = new \ReflectionClass($bundle);
         $controllerDir = new Finder();
         $controllerDir->files()->in(dirname($bundleRef->getFileName()) . '/Controller/')->name('/.*Controller\\.php$/');
         foreach ($controllerDir as $controllerFile) {
             /** @var SplFileInfo $controllerFile */
             $controller = $bundleRef->getNamespaceName() . "\\Controller\\" . substr($controllerFile->getFilename(), 0, -4);
             $controllerRef = new \ReflectionClass($controller);
             foreach ($controllerRef->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                 /** @var $methodDirectAnnotation Direct */
                 $methodDirectAnnotation = $this->annoReader->getMethodAnnotation($method, 'Tpg\\ExtjsBundle\\Annotation\\Direct');
                 if ($methodDirectAnnotation !== null) {
                     $nameSpace = str_replace("\\", ".", $bundleRef->getNamespaceName());
                     $className = str_replace("Controller", "", $controllerRef->getShortName());
                     $methodName = str_replace("Action", "", $method->getName());
                     $list[$nameSpace][$className][] = array('name' => $methodName, 'len' => count($method->getParameters()));
                 }
             }
         }
     }
     return $list;
 }
Example #5
0
 /**
  * @return string $classNamespace
  */
 protected function getNamespace() : string
 {
     if (is_null($this->namespace)) {
         $this->namespace = $this->reflection->getNamespaceName();
     }
     return $this->namespace;
 }
Example #6
0
 /**
  * @param Controller $controller
  * @param null $entityClassName
  * @return $this
  */
 public function initialize(Controller $controller, $entityClassName = null)
 {
     $entityClassName = explode('\\', $entityClassName);
     $this->entityClassName = $entityClassName[count($entityClassName) - 1];
     $this->reflector = new \ReflectionClass($controller);
     $this->namespace = explode('\\', $this->reflector->getNamespaceName());
     $key = array_search('__CG__', $this->namespace);
     //if the controller come from jms aop bundle
     if ($key) {
         for ($i = $key; $i >= 0; $i--) {
             unset($this->namespace[$i]);
         }
     }
     $this->namespace = array_values($this->namespace);
     $key = array_search('Controller', $this->namespace);
     $lastValue = $this->namespace[count($this->namespace) - 1];
     //May be you have nested controller
     if ('Controller' !== $lastValue) {
         $this->exclude = $lastValue;
     }
     for ($i = $key; $i <= count($this->namespace); $i++) {
         array_pop($this->namespace);
     }
     return $this;
 }
Example #7
0
 /**
  * Recursively brings value to type
  * @param $parent
  * @param $type
  * @param $value
  * @param bool $isNullable
  * @param array $restrictions
  * @throws Exception
  * @return mixed
  */
 public static function bringValueToType($parent, $type, $value, $isNullable = false, $restrictions = [])
 {
     if ($isNullable && null === $value || empty($type)) {
         return $value;
     }
     $typeParts = explode("[]", $type);
     $singleType = current($typeParts);
     if (count($typeParts) > 2) {
         throw new Exception(sprintf("In %s type '{$type}' is invalid", get_class($parent)), Exception::INTERNAL_ERROR);
     }
     //for array type
     if (count($typeParts) === 2) {
         if (!is_array($value)) {
             if ($parent instanceof \JsonRpc2\Dto) {
                 throw new Exception(sprintf("In %s value has type %s, but array expected", get_class($parent), gettype($value)), Exception::INTERNAL_ERROR);
             } else {
                 throw new Exception("Value has type %s, but array expected", gettype($value), Exception::INTERNAL_ERROR);
             }
         }
         foreach ($value as $key => $childValue) {
             $value[$key] = self::bringValueToType($parent, $singleType, $childValue, $isNullable);
         }
         return $value;
     }
     $class = new \ReflectionClass($parent);
     if (0 !== strpos($type, "\\") && class_exists($class->getNamespaceName() . "\\" . $type)) {
         $type = $class->getNamespaceName() . "\\" . $type;
     }
     if (class_exists($type)) {
         if (!is_subclass_of($type, '\\JsonRpc2\\Dto')) {
             throw new Exception(sprintf("In %s class '%s' MUST be instance of '\\JsonRpc2\\Dto'", get_class($parent), $type), Exception::INTERNAL_ERROR);
         }
         return new $type($value);
     } else {
         switch ($type) {
             case "string":
                 $value = (string) $value;
                 self::restrictValue($parent, $type, $value, $restrictions);
                 return $value;
                 break;
             case "int":
                 $value = (int) $value;
                 self::restrictValue($parent, $type, $value, $restrictions);
                 return $value;
                 break;
             case "float":
                 $value = (double) $value;
                 self::restrictValue($parent, $type, $value, $restrictions);
                 return $value;
                 break;
             case "array":
                 throw new Exception("Parameter type 'array' is deprecated. Use square brackets with simply types or DTO based classes instead.", Exception::INTERNAL_ERROR);
             case "bool":
                 return (bool) $value;
                 break;
         }
     }
     return $value;
 }
 /**
  *
  */
 public function getXmlNamespace()
 {
     $namespace = $this->_parseAnnotation($this->reflection->getDocComment(), 'xmlNamespace');
     if (!$namespace && $this->configuration) {
         $namespace = $this->configuration->getXmlNamespace($this->reflection->getNamespaceName());
     }
     return $namespace;
 }
Example #9
0
 /**
  * Initializes a new ClassMetadata instance that will hold the object-relational mapping
  * metadata of the class with the given name.
  *
  * @param string $entityName The name of the entity class the new instance is used for.
  */
 public function __construct($entityName)
 {
     $this->name = $entityName;
     $this->reflClass = new \ReflectionClass($entityName);
     $this->namespace = $this->reflClass->getNamespaceName();
     $this->primaryTable['name'] = $this->reflClass->getShortName();
     $this->rootEntityName = $entityName;
 }
 public function __construct(\ReflectionClass $intf)
 {
     $this->intf = $intf;
     $classParser = new PhpParser();
     $uses = array_merge($classParser->parseClass($this->intf), [$this->intf->getNamespaceName()]);
     $this->reader = new AnnotationReader($this->intf);
     $this->converter = new AnnotationConverter($uses);
 }
Example #11
0
 public function initialize()
 {
     $ref = new \ReflectionClass($this);
     $namespace = str_replace(basename($ref->getNamespaceName()), '', $ref->getNamespaceName());
     $this->moduleInstance = $this->getDI()->get($namespace . 'Module');
     $this->modelName = strtolower(basename($ref->name));
     $this->setSource(TH_DB_PREFIX . $this->modelName);
     $this->onInitialize();
 }
Example #12
0
 static function widget_name()
 {
     $function_name = 'widget_';
     $r = new \ReflectionClass(get_called_class());
     $function_name .= Str::snake(str_replace('Widget', '', $r->getShortName()));
     if ('Larakit\\Widget' != $r->getNamespaceName()) {
         $function_name .= '__' . Str::snake(str_replace(['\\', 'Widget'], '', $r->getNamespaceName()));
     }
     return $function_name;
 }
Example #13
0
 private function generateClassName()
 {
     $shortName = $this->reflection->getShortName();
     $fullName = $this->reflection->getNamespaceName() . "\\{$shortName}Mock";
     $counter = 1;
     while (class_exists($fullName . $counter)) {
         $counter++;
     }
     return ["{$shortName}Mock{$counter}", $fullName . $counter];
 }
Example #14
0
 /**
  * Creates the factory for this concrete product.
  * If the class does not exists yet, it is generated on the fly.
  * 
  * The factory implements an interface named after the short name of the
  * product class name with the suffix "Factory". The namespace is the
  * same namespace as the product classname.
  * 
  * The concrete factory is not of your concern, that's the trick of
  * factory method. That's why I put a random number after the classname
  * of the concrete factory : do not use that name !
  * 
  * @param string $fqcnProduct
  * 
  * @return object the the new factory
  */
 public function getFactory($fqcnProduct)
 {
     $refl = new \ReflectionClass($fqcnProduct);
     $fmName = 'Concrete' . $refl->getShortName() . 'Factory' . crc32($fqcnProduct);
     $fqcnFM = $refl->getNamespaceName() . '\\' . $fmName;
     if (!class_exists($fqcnFM)) {
         eval($this->generate($refl->getNamespaceName(), $refl->getShortName() . 'Factory', $fmName, $refl->getName()));
     }
     return new $fqcnFM();
 }
Example #15
0
 public function initialize()
 {
     $ref = new \ReflectionClass($this);
     $namespace = str_replace(basename($ref->getNamespaceName()), '', $ref->getNamespaceName());
     $this->moduleInstance = $this->getDI()->get($namespace . 'Module');
     $this->tag->setTitleSeparator(' - ');
     $this->tag->setTitle('thunderhawk');
     $this->onInitialize();
     $this->onPrepareAssets();
     $this->onPrepareThemeAssets();
 }
Example #16
0
 /**
  * Parses a class.
  *
  * @param \ReflectionClass $class A <code>ReflectionClass</code> object.
  * @return array A list with use statements in the form (Alias => FQN).
  */
 public function parseClass(\ReflectionClass $class)
 {
     if (false === ($filename = $class->getFilename())) {
         return array();
     }
     $content = $this->getFileContent($filename, $class->getStartLine());
     $namespace = str_replace('\\', '\\\\', $class->getNamespaceName());
     $content = preg_replace('/^.*?(\\bnamespace\\s+' . $namespace . '\\s*[;{].*)$/s', '\\1', $content);
     $this->tokens = token_get_all('<?php ' . $content);
     $this->numTokens = count($this->tokens);
     $this->pointer = 0;
     $statements = $this->parseUseStatements($class->getNamespaceName());
     return $statements;
 }
Example #17
0
 /**
  * @return array A list with use statements in the form (Alias => FQN).
  */
 public function parseUseStatements(\ReflectionClass $class)
 {
     if (false === ($filename = $class->getFilename())) {
         return array();
     }
     $content = $this->getFileContent($filename, $class->getStartLine());
     if (null === $content) {
         return array();
     }
     $namespace = preg_quote($class->getNamespaceName());
     $content = preg_replace('/^.*?(\\bnamespace\\s+' . $namespace . '\\s*[;{].*)$/s', '\\1', $content);
     $tokenizer = new TokenParser('<?php ' . $content);
     $statements = $tokenizer->parseUseStatements($class->getNamespaceName());
     return $statements;
 }
Example #18
0
 /**
  * @param  \ReflectionClass|string
  * @return self
  */
 public static function from($from)
 {
     $from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from);
     if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) {
         $class = new static('anonymous');
     } else {
         $class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
     }
     $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class');
     $class->final = $from->isFinal() && $class->type === 'class';
     $class->abstract = $from->isAbstract() && $class->type === 'class';
     $class->implements = $from->getInterfaceNames();
     $class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
     if ($from->getParentClass()) {
         $class->extends = $from->getParentClass()->getName();
         $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames());
     }
     foreach ($from->getProperties() as $prop) {
         if ($prop->getDeclaringClass()->getName() === $from->getName()) {
             $class->properties[$prop->getName()] = Property::from($prop);
         }
     }
     foreach ($from->getMethods() as $method) {
         if ($method->getDeclaringClass()->getName() === $from->getName()) {
             $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace);
         }
     }
     return $class;
 }
 protected function registerMetadataDirectories(ContainerBuilder $container, array $config)
 {
     $bundles = $container->getParameter('kernel.bundles');
     // directories
     $directories = array();
     if ($config['metadata']['auto_detection']) {
         foreach ($bundles as $class) {
             $ref = new \ReflectionClass($class);
             $directory = dirname($ref->getFileName()) . '/Resources/config/vich_uploader';
             if (!is_dir($directory)) {
                 continue;
             }
             $directories[$ref->getNamespaceName()] = $directory;
         }
     }
     foreach ($config['metadata']['directories'] as $directory) {
         $directory['path'] = rtrim(str_replace('\\', '/', $directory['path']), '/');
         if ('@' === $directory['path'][0]) {
             $bundleName = substr($directory['path'], 1, strpos($directory['path'], '/') - 1);
             if (!isset($bundles[$bundleName])) {
                 throw new \RuntimeException(sprintf('The bundle "%s" has not been registered with AppKernel. Available bundles: %s', $bundleName, implode(', ', array_keys($bundles))));
             }
             $ref = new \ReflectionClass($bundles[$bundleName]);
             $directory['path'] = dirname($ref->getFileName()) . substr($directory['path'], strlen('@' . $bundleName));
         }
         $directories[rtrim($directory['namespace_prefix'], '\\')] = rtrim($directory['path'], '\\/');
     }
     $container->getDefinition('vich_uploader.metadata.file_locator')->replaceArgument(0, $directories);
 }
 /**
  * @return INamespaceReflection
  */
 public function getNamespaceReflection()
 {
     if ($this->namespaceReflection === null) {
         $this->namespaceReflection = $this->getSourceReflection()->getNamespaceReflection($this->reflectionClass->getNamespaceName());
     }
     return $this->namespaceReflection;
 }
Example #21
0
 /**
  * Check for added admin menu's
  */
 public function __construct()
 {
     // Get loaded providers
     $providers = array_keys(\App::getLoadedProviders());
     // Get Tdt matches, but not core
     $packages = preg_grep('/^Tdt[\\\\](?!Core)/i', $providers);
     $menu = $this->core_menu;
     // Check for UI controller
     foreach ($packages as $package) {
         // Get package namespace
         $reflector = new \ReflectionClass($package);
         $namespace = $reflector->getNamespaceName();
         // Check for a UI controller
         $controller = $namespace . "\\Ui\\UiController";
         if (class_exists($controller)) {
             // Create controller instance
             $controller = \App::make($controller);
             $package_menu = @$controller->menu();
             // Check for added menu items
             if (!empty($package_menu)) {
                 $menu = array_merge($menu, $package_menu);
             }
             // Push for future use
             array_push($this->package_controllers, $controller);
         }
     }
     // Sort menu's
     usort($menu, function ($a, $b) {
         return $a['priority'] - $b['priority'];
     });
     // Share menu with views
     \View::share('menu', $menu);
 }
Example #22
0
 /**
  * @return Router
  */
 protected function createBoxRouter()
 {
     $class = new \ReflectionClass($this);
     $namespace = $class->getNamespaceName();
     $directory = dirname($class->getFileName());
     return new WebRouter($this->factory, $directory, $namespace);
 }
 /**
  * Attempts to read the uploadable annotation.
  *
  * @param  \ReflectionClass $class The reflection class.
  * @return null|\Iphp\FileStoreBundle\Annotation\Uploadable The annotation.
  */
 public function readUploadable(\ReflectionClass $class)
 {
     $baseClassName = $className = $class->getNamespaceName() . '\\' . $class->getName();
     do {
         if (isset($this->uploadedClass[$className])) {
             if ($baseClassName != $className) {
                 $this->uploadedClass[$baseClassName] = $this->uploadedClass[$className];
             }
             return $this->uploadedClass[$baseClassName];
         }
         $annotation = $this->reader->getClassAnnotation($class, 'Iphp\\FileStoreBundle\\Mapping\\Annotation\\Uploadable');
         if ($annotation) {
             $this->uploadedClass[$baseClassName] = $annotation;
             if ($baseClassName != $className) {
                 $this->uploadedClass[$className] = $annotation;
             }
             return $annotation;
         }
         $class = $class->getParentClass();
         if ($class) {
             $className = $class->getNamespaceName() . '\\' . $class->getName();
         }
     } while ($class);
     return $annotation;
 }
Example #24
0
 /**
  *	Init
  *	This method must return self
  *	@return self
  */
 public function init()
 {
     parent::init();
     $reflector = new \ReflectionClass($this);
     $this->_applicationNamespace = $reflector->getNamespaceName();
     //Define BASE Asset paths
     $assetConfig = $this->config()->get("assets");
     $assetPath = $assetConfig->get("assets", "assets");
     if (!defined("BASE_ASSETS")) {
         define("BASE_ASSETS", Router::buildPath(SITE_URL, $assetPath));
     }
     if (!defined("BASE_IMAGES")) {
         define("BASE_IMAGES", Router::buildPath(SITE_URL, $assetPath, $assetConfig->get("images", "images")));
     }
     if (!defined("BASE_STYLES")) {
         define("BASE_STYLES", Router::buildPath(SITE_URL, $assetPath, $assetConfig->get("css", "css")));
     }
     if (!defined("BASE_SCRIPTS")) {
         define("BASE_SCRIPTS", Router::buildPath(SITE_URL, $assetPath, $assetConfig->get("js", "js")));
     }
     if (!defined("BASE_TEMPLATES")) {
         define("BASE_TEMPLATES", Filesystem::buildPath(PROJECT_PATH, $assetConfig->get("templates", "Templates")));
     }
     return $this;
 }
 private function getExpectedTableClasses()
 {
     $tablesReflection = new \ReflectionClass(Tables::class);
     $rootDir = dirname($tablesReflection->getFileName());
     $rootNamespace = $tablesReflection->getNamespaceName();
     return $this->scanForTables($rootDir, $rootNamespace);
 }
 /**
  * @param ContainerBuilder $container
  */
 public function process(ContainerBuilder $container)
 {
     $bundles = $container->getParameter('kernel.bundles');
     $reader = $container->get('annotation_reader');
     $registry = $container->getDefinition('lemon_rest.object_registry');
     foreach ($bundles as $name => $bundle) {
         $reflection = new \ReflectionClass($bundle);
         $baseNamespace = $reflection->getNamespaceName() . '\\Entity\\';
         $dir = dirname($reflection->getFileName()) . '/Entity';
         if (is_dir($dir)) {
             $finder = new Finder();
             $iterator = $finder->files()->name('*.php')->in($dir);
             /** @var SplFileInfo $file */
             foreach ($iterator as $file) {
                 // Translate the directory path from our starting namespace forward
                 $expandedNamespace = substr($file->getPath(), strlen($dir) + 1);
                 // If we are in a sub namespace add a trailing separation
                 $expandedNamespace = $expandedNamespace === false ? '' : $expandedNamespace . '\\';
                 $className = $baseNamespace . $expandedNamespace . $file->getBasename('.php');
                 if (class_exists($className)) {
                     $reflectionClass = new \ReflectionClass($className);
                     foreach ($reader->getClassAnnotations($reflectionClass) as $annotation) {
                         if ($annotation instanceof Resource) {
                             $name = $annotation->name ?: Inflector::pluralize(lcfirst($reflectionClass->getShortName()));
                             $definition = new Definition('Lemon\\RestBundle\\Object\\Definition', array($name, $className, $annotation->search, $annotation->create, $annotation->update, $annotation->delete, $annotation->partialUpdate));
                             $container->setDefinition('lemon_rest.object_resources.' . $name, $definition);
                             $registry->addMethodCall('add', array($definition));
                         }
                     }
                 }
             }
         }
     }
 }
 public function parse($symfonyControllerName)
 {
     if (isset($this->cache[$symfonyControllerName])) {
         return $this->cache[$symfonyControllerName];
     }
     // skip controllers as services
     if (strpos($symfonyControllerName, ".") !== false) {
         return array();
     }
     if (substr_count($symfonyControllerName, "::") == 1) {
         $details = array();
         list($controllerName, $actionName) = explode("::", $symfonyControllerName);
         $details['action'] = str_replace("Action", "", $actionName);
         $controllerRefl = new \ReflectionClass($controllerName);
         $details['controller'] = str_replace("Controller", "", $controllerRefl->getShortName());
         $controllerNamespace = $controllerRefl->getNamespaceName();
         foreach ($this->kernel->getBundles() as $bundle) {
             if (strpos($controllerNamespace, $bundle->getNamespace()) === 0) {
                 $details['module'] = str_replace("Bundle", "", $bundle->getName());
                 break;
             }
         }
     } else {
         list($module, $controller, $action) = explode(":", $symfonyControllerName);
         $details['action'] = $action;
         $details['controller'] = $controller;
         $details['module'] = str_replace("Bundle", "", $module);
     }
     return $this->cache[$symfonyControllerName] = $details;
 }
 protected static function mockImpl($type_, array $args_ = [])
 {
     $type = new \ReflectionClass($type_);
     if ($type->isFinal()) {
         throw new Exception_IllegalArgument('mock/factory', 'Can not mock final class.');
     }
     $mtime = @filemtime($type->getFileName());
     $classMock = 'Mock_' . str_replace('\\', '_', $type->getNamespaceName()) . '_' . $type->getShortName() . "_{$mtime}";
     if (false === @class_exists($classMock)) {
         if (null === self::$m_tmpPath) {
             self::$m_tmpPath = (string) Test_Runner::get()->getTempPath();
         }
         $fileName = self::$m_tmpPath . "/{$classMock}.php";
         if (false === @file_exists($fileName)) {
             $source = self::weaveMock($classMock, new \ReflectionClass('Components\\Mock'), $type);
             if (false === @file_put_contents($fileName, $source, 0644)) {
                 throw new Exception_IllegalState('mock/factory', sprintf('Unable to create mock [type: %1$s, path: %2$s].', $type_, $fileName));
             }
         }
         require_once $fileName;
     }
     $classMock = "Components\\{$classMock}";
     if (0 < count($args_)) {
         $refl = new \ReflectionClass($classMock);
         $mock = $refl->newInstanceArgs($args_);
     } else {
         $mock = new $classMock();
     }
     $mock->mockType = $type;
     return $mock;
 }
 protected function detectModuleName()
 {
     $refl = new \ReflectionClass($this);
     $namespace = $refl->getNamespaceName();
     $namespace = ltrim($namespace, '\\');
     return false === strpos($namespace, 'Settings\\') ? substr($namespace, 0, strpos($namespace, '\\')) : null;
 }
Example #30
0
 private function _getParsedRoutes($target)
 {
     $route_name = null;
     $uses = [];
     if (is_string($target)) {
         $uses = explode('@', $target);
     } elseif (is_array($target)) {
         $route_name = @$target['as'] ?: null;
         if (isset($target['uses'])) {
             $uses = explode('@', $target['uses']);
         }
     }
     # - get the default namespace from the dispatcher
     $default_namespace = $this->getDI()->get('dispatcher')->getDefaultNamespace() . '\\';
     # - if the uses is not empty, we should get the class properties
     # such as namespace, class short name
     if (!empty($uses)) {
         $reflection = new \ReflectionClass($default_namespace . $uses[0]);
         # - let's get the reflected class namespace
         $namespace = $reflection->getNamespaceName();
         # - this strips out all the word 'Controller'
         # and then getting the reflected class short name
         $controller = str_replace('Controller', '', $reflection->getShortName());
         # - get the action based on the index[1]
         $action = $uses[1];
         $target = ['controller' => $controller, 'action' => $action];
         if ($namespace) {
             $target['namespace'] = $namespace;
         }
     }
     return ['target' => $target, 'name' => $route_name];
 }