class TinyPng in TinyPNG 8
Class TinyPng.
@package Drupal\tinypng
Hierarchy
- class \Drupal\tinypng\TinyPng implements ContainerInjectionInterface, TinyPngInterface
Expanded class hierarchy of TinyPng
1 string reference to 'TinyPng'
1 service uses TinyPng
File
- src/
TinyPng.php, line 19
Namespace
Drupal\tinypngView source
class TinyPng implements TinyPngInterface, ContainerInjectionInterface {
/**
* Config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Config.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* File system.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* TinyPNG API key.
*
* @var string
*/
protected $apiKey;
/**
* Tinify Source.
*
* @var \Tinify\Source
*/
protected $tinyfySource;
/**
* TinyPng service constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Config factory.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* File system.
*/
public function __construct(ConfigFactoryInterface $config_factory, FileSystemInterface $file_system) {
$this->configFactory = $config_factory;
$this->config = $this->configFactory
->get('tinypng.settings');
$this->fileSystem = $file_system;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('file_system'));
}
/**
* {@inheritdoc}
*/
public function setApiKey($key = NULL, $reset = FALSE) {
if (empty($this->apiKey) || $reset) {
if (empty($key)) {
$key = $this->config
->get('api_key');
}
$this->apiKey = $key;
TinifySetKey($key);
TinifySetAppIdentifier('Drupal/' . \Drupal::VERSION);
}
return $this;
}
/**
* {@inheritdoc}
*/
public function setFromUrl($url) {
$this
->setApiKey();
$origin = file_create_url($url);
$this->tinyfySource = TinifyFromUrl($origin);
return $this;
}
/**
* {@inheritdoc}
*/
public function setFromFile($uri) {
$this
->setApiKey();
$path = $this->fileSystem
->realpath($uri);
$this->tinyfySource = TinifyFromFile($path);
return $this;
}
/**
* {@inheritdoc}
*/
public function saveTo($uri) {
$path = $this->fileSystem
->realpath($uri);
return $this->tinyfySource
->toFile($path);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TinyPng:: |
protected | property | TinyPNG API key. | |
TinyPng:: |
protected | property | Config. | |
TinyPng:: |
protected | property | Config factory. | |
TinyPng:: |
protected | property | File system. | |
TinyPng:: |
protected | property | Tinify Source. | |
TinyPng:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
TinyPng:: |
public | function |
Save result to file. Overrides TinyPngInterface:: |
|
TinyPng:: |
public | function |
Set TinyPNG API key. Overrides TinyPngInterface:: |
|
TinyPng:: |
public | function |
Compress with \Tinify\fromFile. Overrides TinyPngInterface:: |
|
TinyPng:: |
public | function |
Compress with \Tinify\fromUrl. Overrides TinyPngInterface:: |
|
TinyPng:: |
public | function | TinyPng service constructor. |