# phastpress/1.92/classes/CDN.php

PhastPress, version 1.92. 34 lines.

- Page: https://pluginprobe.com/plugins/phastpress/1.92/code/classes/CDN.php
- Raw: https://pluginprobe.com/plugins/phastpress/1.92/raw/classes/CDN.php
- Modified: 2020-08-20T08:45:36+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/phastpress/1.92/code/classes/CDN.php#L10-L20`.

```php
<?php
namespace Kibo\PhastPlugins\PhastPress;

use Kibo\Phast\ValueObjects\URL;

class CDN {
    public static function installHook() {
        add_filter('phastpress_cdn_url', [static::class, 'getCdnUrl']);
    }

    public static function getCdnUrl($url) {
        if (($options = self::getBunnyCdnOptions())
            && strlen(trim($options['cdn_domain_name']))
        ) {
            return URL::fromString($url)->rewrite(
                URL::fromString($options['site_url']),
                URL::fromString((is_ssl() ? 'https://' : 'http://') . $options['cdn_domain_name'])
            );
        }

        return $url;
    }

    public static function getBunnyCdnOptions() {
        try {
            $class = new \ReflectionClass('BunnyCDN');
            $method = $class->getMethod('getOptions');
            return $method->invoke(null);
        } catch (\Exception $e) {
        } catch (\Throwable $e) {
        }
    }
}

```
