Convert a string into a namespaced method name

@param string|array<string> $class
@param boolean $asArray Whether or not to return as an array
@return string|array<string>
195227
public static function toMethod($class, $asArray = false)
    {
        if (is_string($class)) {
            $class = self::split($class);
        }
        $method = array_pop($class);
        $classname = implode("\\", $class);
        return ($asArray) ? [$classname, $method] : "$classname::$method";
    }
485195
public static function parseRelationClass($class)
    {
        // detect many many through syntax
        if (is_array($class)
            && array_key_exists('through', $class)
            && array_key_exists('to', $class)
        ) {
            $toRelation = $class['to'];

            $hasOne = Config::inst()->get($class['through'], 'has_one');
            if (empty($hasOne) || !is_array($hasOne) || !array_key_exists($toRelation, $hasOne)) {
                return $class;
            }

            return $hasOne[$toRelation];
        }

        return $class;
    }
90779
public function toPhpString(
        $namespace,
        array $aliased_classes,
        $this_class,
        $php_major_version,
        $php_minor_version
    ) {
        if ($this->value === 'static') {
            return null;
        }

        return $this->toNamespacedString($namespace, $aliased_classes, $this_class, false);
    }
246374
public static function classes(array $list = null) {

            if ($list === null) {
                $list = Kohana::list_files('classes');
            }
            $namespaces = Kohana::$config->load('userguide.namespaces');
            Debug::stop($namespaces);
            $namespaces = \Arr::map(function ($namespace) {
                $namespace = trim($namespace, '/');
                $namespace = trim($namespace, '\\');
                return str_replace('/', '\\', $namespace);
            }, $namespaces);
            $namespaces = Arr::flatten($namespaces);
            //Debug::info($namespaces);
            $namespaces = array_unique($namespaces);
            $classes    = array();
            // This will be used a lot!
            $ext_length = strlen(EXT);
            foreach ($list as $name => $path) {
                if (is_array($path)) {
                    $classes += Kodoc::classes($path);
                }
                elseif (substr($name, -$ext_length) === EXT) {
                    // Remove "classes/" and the extension
                    $class = substr($name, 8, -$ext_length);
                    // Convert slashes to underscores
                    $class = str_replace(DIRECTORY_SEPARATOR, '_', $class);
                    $ret   = '';
                    //print '<hr />1) ' . $name . '<br />';
                    //print '2) ' . $class . '<hr />';
                    foreach ($namespaces as $namespace) {
                        $_namespace = str_replace('\\', '_', $namespace);
                        //print '4) ' . $_namespace . '<br />';
                        if (mb_strpos($class, $_namespace) === 0) {
                            $class = '\\'.$namespace.'\\'.str_replace($_namespace.'_', '', $class);
                            break;
                        }
                    }

                    $classes[$class] = $class;
                }
            }
            return $classes;
        }
285211
private function findClasspathAndClass($class)
    {
        if (false !== $pos = strrpos($class, '\\')) {
            // namespaced class name
            $classpath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR;
            $classname = substr($class, $pos + 1);

            return array($classpath, $classname);
        }

        // PEAR-like class name
        $classpath = null;
        $classname = $class;

        return array($classpath, $classname);
    }
253123
private function apply_namespace_filters( $namespace, $class, $dir )
    {
        foreach( $this->filters[$namespace] as $filter )
        {
            if( is_callable( $filter ) )
            {
                $file = call_user_func_array( $filter, array( $class, $namespace, $dir ) );
                if ( file_exists( $file ) ) 
                {
                    return $file;
                }
            }
        }
    }
7493
protected function parsedCodeHasNamespaces(array $parsed)
    {
        // Namespaces can only be on first level in the code,
        // so we make only check on it.
        $node = array_filter(
            $parsed,
            function ($value) {
                return $value instanceof NamespaceNode;
            }
        );

        return !empty($node);
    }
857990
public static function denamespace($class_name)
	{
		$class_name = trim($class_name, '\\');
		if ($last_separator = strrpos($class_name, '\\'))
		{
			$class_name = substr($class_name, $last_separator + 1);
		}
		return $class_name;
	}
1192672
public <T> T[] asArray(Class<T> clazz) {
      return Cast.as(convert(toConvert, Array.newInstance(clazz, 0).getClass()));
   }
820707
public static function decode($string, $asArray = false)
    {
        $decoded = self::safeDecode($string, $asArray);
        if (is_null($decoded) == false) {
            return $decoded;
        }
        $code = self::lastError();
        if ($code === JSON_ERROR_NONE) {
            return $decoded;
        }
        throw new JsonDecodeException(self::lastErrorMessage(), $code);
    }
506937
public function toArray($asArrayObject = false)
    {
        $data = [];
        foreach ($this->data as $k => $v) {
            $data[$k] = $this->isInstanceOf($v, $this) ? $v->toArray() : $v;
        }

        return $asArrayObject ? $this->arr($data) : $data;
    }
720570
public function getMimeType($asArray = false)
    {
        $asArray   = (bool) $asArray;
        $mimetype = (string) $this->_mimetype;
        if ($asArray) {
            $mimetype = explode(',', $mimetype);
        }

        return $mimetype;
    }
1180235
static function deserialize($class_name, $assoc_s)
    {
        $pairs = Auth_OpenID_KVForm::toArray($assoc_s, $strict = true);
        $keys = array();
        $values = array();
        foreach ($pairs as $key => $value) {
            if (is_array($value)) {
                list($key, $value) = $value;
            }
            $keys[] = $key;
            $values[] = $value;
        }

        $class_vars = get_class_vars($class_name);
        $class_assoc_keys = $class_vars['assoc_keys'];

        sort($keys);
        sort($class_assoc_keys);

        if ($keys != $class_assoc_keys) {
            trigger_error('Unexpected key values: ' . var_export($keys, true),
                          E_USER_WARNING);
            return null;
        }

        $version = $pairs['version'];
        $handle = $pairs['handle'];
        $secret = $pairs['secret'];
        $issued = $pairs['issued'];
        $lifetime = $pairs['lifetime'];
        $assoc_type = $pairs['assoc_type'];

        if ($version != '2') {
            trigger_error('Unknown version: ' . $version, E_USER_WARNING);
            return null;
        }

        $issued = intval($issued);
        $lifetime = intval($lifetime);
        $secret = base64_decode($secret);

        return new $class_name(
            $handle, $secret, $issued, $lifetime, $assoc_type);
    }
875005
private function _createInstance($namespace, $class, $params, $method_name, $data)
    {
        $ns_class = $namespace . $class;

        //create a reflection class so that we can pass parameters to the constructor

        $ref_class = new \ReflectionClass($ns_class);

        if (is_array($params) && sizeof($params) > 0) {

            $instance = $ref_class->newInstanceArgs($params);

        } else {

            $instance = new $ns_class();
        }
        
        $this->logger->info("$namespace object created for $class class");
   
        //call the method along with parameters, if they exist !
        if (method_exists($instance, $method_name))
        {
            if(is_callable(array($instance, $method_name)))
            {
                $last_hook = $this->loading[count($this->loading) - 1];
                $this->loaderHooks($instance,"pre_$last_hook",$class,$method_name,$data);
                call_user_func_array(array($instance, $method_name), $data);
                $this->loaderHooks($instance,"post_$last_hook",$class,$method_name,$data);
            }
        }elseif(is_object($instance)) 
        {
            $last_hook = $this->loading[count($this->loading) - 1];
            $this->loaderHooks($instance,"pre_$last_hook",$class,$method_name,$data);
        }
        else if(strpos($namespace,'controller') > 0)
        {
            header("HTTP/1.0 404 Not Found");
            Base::getInstance()->hook('404',array(
                'file' => $ref_class,
                'controller' => $class,
                'method' => $method_name,
                'message' => '404'
            ));
            die();
        }

        $this->clearCurrentLoader();

        return $instance;
    }
1130202
protected function prepareArguments(bool $asArray = true)
    {
        $arguments = array_merge(
            [$this->getBaseOptions()],
            $this->getOptions(),
            $this->getParameters()
        );

        if (false === $asArray) {
            $arguments = implode(' ', $arguments);
        }

        return $arguments;
    }
201815
protected function get_folder_name( $class ) {
		if ( $class ) {
			$class = str_replace( $this->namespace, '', $class );
			$file  = explode( '\\', $class );
			$file  = end( $file );
			$class = str_replace( $file, '', $class );
			$class = strtolower( str_replace( '\\', '/', $class ) );

			return array(
				$class,
				str_replace( '_', '-', $class ),
				strtolower( $file ),
				str_replace( '-', '_', $class ),
			);
		}
		return false;
	}
1176882
public function getNamespace($class_name)
	{
		$class_name = trim($class_name, '\\');
		if ($last_separator = strrpos($class_name, '\\'))
		{
			return substr($class_name, 0, $last_separator + 1);
		}
		return '';
	}