Documentation

AnonymousAssetBuilder
in package

Use this to create your database tables and to create the instances of `DeliverAnonymousAsset`.

Table of Contents

Constants

COPY_EXTENSIONS  = ['js', 'css']
GENERATE_NEXT_HASH  = 60 * 60 * 24 * 7
MAX_SEO_REDIRECTS  = 4
OPTION_NAME_SERVE_HASH_SUFFIX  = '-serve-hash'
OPTION_NAME_SERVE_NEXT_HASH_SUFFIX  = '-serve-next-hash'
TABLE_NAME  = 'asset_seo_redirect'

Properties

$contentDir  : string|false
Cache of `Utils::contentDir`.
$folder  : mixed
$optionNamePrefix  : mixed
$pool  : array<string|int, DeliverAnonymousAsset>
The pool of collected built `DeliverAnonymousAsset` instances.
$table_name  : mixed

Methods

__construct()  : mixed
C'tor.
build()  : mixed
Create an anonymous asset. Do not forget to make it `->ready()` after you enqueued it! This must be done in `wp` hook as it is the first available hook.
dbDelta()  : mixed
Make sure the database table is created.
ensureAnonymousFolder()  : mixed
Create the anonymous folder in `wp-content`. It also uses the original folder path basename (e.g. `dist` or `dev`) as another subfolder, so it results in e.g. `/var/www/html/wp-content/7e9df1a92be399cb922305d5e7388ab1/dist/`.
forceRecreation()  : mixed
Force recreation of asset files.
generateFilename()  : mixed
Generate the filename for a given original filename.
generateFolderSrc()  : mixed
Get the URL to the anonymous folder.
getContentDir()  : mixed
Getter.
getFolder()  : mixed
Getter.
getHash()  : mixed
Get the currently used hash.
getOptionNamePrefix()  : mixed
Getter.
getTableName()  : mixed
Getter.
purgeHashes()  : mixed
Hashes got rotated and we can delete old folders from the filesystem.
ready()  : mixed
Make a handle ready. Do not forget to `->build()` it previously!
uninstall()  : mixed
Remove the files from filesystem. Use this function in your `uninstall.php`.
updateHash()  : mixed
Generate a new hash for the current served JS file.

Constants

OPTION_NAME_SERVE_NEXT_HASH_SUFFIX

public mixed OPTION_NAME_SERVE_NEXT_HASH_SUFFIX = '-serve-next-hash'

Properties

$contentDir

Cache of `Utils::contentDir`.

private string|false $contentDir

false when folder is not writable

Methods

__construct()

C'tor.

public __construct(string $table_name, string $optionNamePrefix, string $folder) : mixed
Parameters
$table_name : string

You can use it in conjunction with TABLE_NAME constant

$optionNamePrefix : string
$folder : string

The absolute path to your original files

build()

Create an anonymous asset. Do not forget to make it `->ready()` after you enqueued it! This must be done in `wp` hook as it is the first available hook.

public build(string $handle, string $file[, string $id = null ]) : mixed
Parameters
$handle : string
$file : string
$id : string = null

If you pass an ID, the instance will be hold in this class pool and you can use this::ready()

ensureAnonymousFolder()

Create the anonymous folder in `wp-content`. It also uses the original folder path basename (e.g. `dist` or `dev`) as another subfolder, so it results in e.g. `/var/www/html/wp-content/7e9df1a92be399cb922305d5e7388ab1/dist/`.

public ensureAnonymousFolder([bool|null $skipExistenceCheck = null ]) : mixed
Parameters
$skipExistenceCheck : bool|null = null

generateFilename()

Generate the filename for a given original filename.

public static generateFilename(string $hash, string $originalFilenameOrPath) : mixed
Parameters
$hash : string

The hash to use

$originalFilenameOrPath : string

purgeHashes()

Hashes got rotated and we can delete old folders from the filesystem.

public static purgeHashes(string $contentDir, array<string|int, string> $hashes) : mixed
Parameters
$contentDir : string
$hashes : array<string|int, string>

ready()

Make a handle ready. Do not forget to `->build()` it previously!

public ready(string $id[, bool $condition = true ]) : mixed
Parameters
$id : string
$condition : bool = true

uninstall()

Remove the files from filesystem. Use this function in your `uninstall.php`.

public static uninstall(string $table_name) : mixed
Parameters
$table_name : string

updateHash()

Generate a new hash for the current served JS file.

protected updateHash() : mixed

        
On this page

Search results