I'm not sure if I'm looking in the wrong places or what, but all I can find are ways to get the class name from a string using something like class_basename(). This is the opposite of what I want; I'm looking to get the namespace from it instead.
For example, if I had the string App\Http\Controllers\Controller, I want to get the App\Http\Controllers part from the string. Of course I could explode on the \ character and just remove the last element from the array, but I am hoping to find something with similar functionality to class_basename but for the namespace instead.
@Cronix - I don't think it's going to work (unless I'm doing it wrong). If I do it on a plain string I get a ReflectionException because the class doesn't exist.
Perhaps I should have specified my use case before. My use case is I'm generating a class with an artisan command, and I need to get the namespace part of the class to append to the default namespace. For example, one type of class I'm generating is a repository, which I have the directory set to Repositories.
Here is an example of the command usage:
php artisan make:repository Backend/ProductRepository
I need to be able to extract the Backend part of the string so my generated namespace will get set to Repositories\Backend in the stub file. Since the class doesn't exist, reflection isn't working for me, but a slight modification of the selected answer's code above does.