I'm making the leap from Drupal 7 to Drupal 8 and am still fuzzy on some core concepts, particularly relating to dependency injection (DI). I've read plenty of tutorials and have a grasp on DI with services, but am unclear on using DI with something like \Drupal::Url()
.
For instance, I am using the following code in a class:
use Drupal\Core\Url;
...
$url = Url::fromRoute('<current>', [], ['absolute' => 'true'])->toString();
From what I can tell, there is no Url service. So, what I am wondering is: Is it possible to access Url via DI? And if so, how?
Bonus points: I intend for the class I am writing to be used as a service. Does this have any impact on the answer?
Edit: Fixed erroneous code.
Edit 2: I should also point out that the purpose of this call is to retrieve the current absolute URL so that I can determine if it is HTTPS.