plugin install

This commit is contained in:
Tony Volpe
2024-06-18 17:29:05 -04:00
parent e1aaedd1ae
commit 41f50eacc4
5880 changed files with 1057631 additions and 39681 deletions

View File

@@ -0,0 +1,35 @@
<?php
/*
* Plugin Name: Advanced Custom Fields: Gravity Forms Add-on
* Plugin URI: https://github.com/sayhellogmbh/acf-gravityforms-add-on
* Description: Provides an Advanced Custom Field which allows a WordPress editorial user or administrator to select a Gravity Form as part of a field group configuration.
* Version: 1.3.8
* Requires at least: 4.6
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Author: Say Hello GmbH
* Author URI: http://www.sayhello.ch/
* Copyright: Say Hello GmbH
* Text Domain: acf-gravityforms-add-on
* Domain Path: /languages
*/
if (!defined('ABSPATH')) {
exit;
} // Exit if accessed directly
// Define multiple necessary constants
define('ACF_GF_FIELD_VERSION', '1.3.8');
define('ACF_GF_FIELD_LANGUAGES', dirname(plugin_basename(__FILE__)) . '/languages/');
// This remains defined just in case anyone is using it, but it is no longer used by this plugin.
define('ACF_GF_FIELD_TEXTDOMAIN', 'acf-gravityforms-add-on');
define('ACF_GF_FIELD_ASSETS', plugin_dir_url(__FILE__));
define('ACF_GF_FIELD_RESOURCES', __DIR__ . '/resources/');
// Use composer to autoload our classes
require_once __DIR__ . '/vendor/autoload.php';
// Initiate the field!
new ACFGravityformsField\Init();

View File

@@ -0,0 +1,57 @@
msgid ""
msgstr ""
"Project-Id-Version: acf-gravityforms-addon\n"
"POT-Creation-Date: 2017-05-31 17:08+0200\n"
"PO-Revision-Date: 2017-05-31 17:13+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.11\n"
"X-Poedit-Basepath: ..\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-KeywordsList: __;_x;_n:1,2\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: resources\n"
#: resources/Field.php:61 resources/FieldForV4.php:86
msgid "Form Object"
msgstr "Formulier Object"
#: resources/Field.php:62 resources/FieldForV4.php:87
msgid "Form ID"
msgstr "Formulier ID"
#: resources/Field.php:130
msgid "- Select a form -"
msgstr "- Selecteer een formulier"
#: resources/Notices.php:38
#, php-format
msgid ""
"Warning: You need to <a href=\"%s\">Activate Gravityforms</a> in order to "
"use the Advanced Custom Fields: Gravityforms Add-on."
msgstr ""
"Waarschuwing: Het is nodig <a href=\"%s\">Gravityforms te activeren</a> om "
"Advanced Custom Fields: Gravityforms Add-on te gebruiken."
#: resources/Notices.php:48
#, php-format
msgid ""
" Warning: There are no active forms. You need to <a href=\"%s\">Create a New "
"Form</a> in order to use the Advanced Custom Fields: Gravityforms Add-on."
msgstr ""
"Waarschuwing: Er zijn geen actieve formulieren. Het is nodig <a href=\"%s"
"\">een nieuw formulier te creëren</a> om Advanced Custom Fields: "
"Gravityforms Add-on te gebruiken."
#: resources/Notices.php:61
#, php-format
msgid ""
"Warning: You need to <a href=\"%s\">Activate Advanced Custom Fields</a> in "
"order to use the Advanced Custom Fields: Gravityforms Add-on."
msgstr ""
"Waarschuwing: Het is nodig <a href=\"%s\">Advanced Custom Fields te "
"activeren</a> om Advanced Custom Fields: Gravityforms Add-on te gebruiken."

View File

@@ -0,0 +1,51 @@
=== Advanced Custom Fields: Gravity Forms Add-on ===
Contributors: markhowellsmead, dannyvanholten
Tags: gravity forms, form, acf, advanced custom fields, sayhellogmbh
Requires at least: 4.6
Tested up to: 6.5.3
Stable tag: 1.3.8
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Provides an Advanced Custom Field which allows a WordPress user to select a Gravity Form as part of a field group configuration.
== Description ==
Provides an Advanced Custom Field which allows a WordPress editorial user or administrator to select a Gravity Form as part of a field group configuration.
**This plugin does not have any effect on the frontend of the website. It does not output the form, nor does it modify the output of existing forms. The plugin only adds a custom ACF field type for use in an ACF field group.**
Full documentation can be found in the [plugin's GitHub Repository](https://github.com/SayHelloGmbH/acf-gravityforms-add-on/).
== Installation ==
The plugin is available from the [WordPress plugin repository](http://www.wordpress.org/plugins/acf-gravityforms-add-on)
1. Upload the plugin files to the `/wp-content/plugins/acf-gravityforms-add-on` directory, or install the plugin through the WordPress plugins screen directly.
2. Activate the plugin through the 'Plugins' screen in WordPress.
3. Add a new field of type 'Forms' to the required ACF field group.
You can also install Advanced Custom Fields: Gravity Forms Add-on using Composer.
`composer require dannyvanholten/acf-gravityforms-add-on`
…or if you make use of WPackagist, …
`composer require wpackagist-plugin/acf-gravityforms-add-on`
== Screenshots ==
1. You can select 'Form' as a field type while adding an ACF Field.
2. The actual selection of the field.
3. You can select all your Gravity Forms.
4. If ACF or Gravity Forms is not added it will give a notice (Notices from [WP Growl Notifications](https://wordpress.org/plugins/wp-growl-notifications).
== Development ==
Version 1.3.2 added a plain HTML filter to the output of the field. This filter is not applied to fields in ACF version 4.
`apply_filters('acf-gravityforms-add-on/field_html', string $field_html, array $field, string $field_options, string $multiple)`
== Changelog ==
A detailed list of changes to the plugin can be found in the [changelog](https://github.com/SayHelloGmbH/acf-gravityforms-add-on/blob/master/CHANGELOG.md) at Github.

View File

@@ -0,0 +1,256 @@
<?php
namespace ACFGravityformsField;
use acf_field;
use GFAPI;
class Field extends acf_field
{
/**
* Make sure we can easily access our notices
*
* @var Notices
*/
public $notices;
/**
* Get our forms
*
* @var array
*/
public $forms;
public function __construct()
{
$this->name = 'forms';
$this->label = __('Gravity Form', 'gravityforms');
$this->category = __('Relational', 'acf');
$this->defaults = [
'return_format' => 'form_object',
'multiple' => 0,
'allow_null' => 0
];
// Get our notices up and running
$this->notices = new Notices();
// Execute the parent constructor as well
parent::__construct();
}
/**
* Create extra settings for our gravityforms field. These are visible when editing a field.
*
* @param $field
*/
public function render_field_settings($field)
{
// Render a field settings that will tell us if an empty field is allowed or not
acf_render_field_setting($field, [
'label' => __('Return Value', 'acf'),
'instructions' => __('Specify the returned value on front end', 'acf'),
'type' => 'radio',
'name' => 'return_format',
'layout' => 'horizontal',
'choices' => [
'post_object' => __('Form Object', 'acf-gravityforms-add-on'),
'id' => __('Form ID', 'acf-gravityforms-add-on')
],
]);
// Render a field setting that will tell us if an empty field is allowed or not.
acf_render_field_setting($field, [
'label' => __('Allow Null?', 'acf'),
'type' => 'radio',
'name' => 'allow_null',
'choices' => [
1 => __('Yes', 'acf'),
0 => __('No', 'acf'),
],
'layout' => 'horizontal'
]);
// Render a field setting that will tell us if multiple forms are allowed.
acf_render_field_setting($field, [
'label' => __('Select multiple values?', 'acf'),
'type' => 'radio',
'name' => 'multiple',
'choices' => [
1 => __('Yes', 'acf'),
0 => __('No', 'acf'),
],
'layout' => 'horizontal'
]);
}
/**
* Render our Gravity Form field with all the forms as options
*
* @param $field
* @return bool
*/
public function render_field($field)
{
if (class_exists('GFAPI')) {
$this->forms = GFAPI::get_forms(true, false, 'title');
}
// Set our defaults
$field = array_merge($this->defaults, $field);
$choices = [];
// Check if we have some valid forms
if (!$this->hasValidForms()) {
return false;
}
foreach ($this->forms as $form) {
$choices[$form['id']] = $form['title'];
}
// Override field settings and start rendering
$field['choices'] = $choices;
$field['type'] = 'select';
// Create a css id for our field
$fieldId = str_replace(['[', ']'], ['-', ''], $field['name']);
// Check if we're allowing multiple selections.
$hiddenField = '';
$multiple = '';
$field_options = '';
if ($field['multiple']) {
$hiddenField = '<input type="hidden" name="{$field[\'name\']}">';
$multiple = '[]" multiple="multiple" data-multiple="1';
}
// Check if we're allowing an empty form. If so, create a default option
if ($field['allow_null']) {
$field_options .= '<option value="">' . __('- Select a form -', 'acf-gravityforms-add-on') . '</option>';
}
// Loop trough all our choices
foreach ($field['choices'] as $formId => $formTitle) {
$selected = '';
if ((is_array($field['value']) && in_array($formId, $field['value'], false))
|| (int)$field['value'] === (int)$formId
) {
$selected = ' selected';
}
$field_options .= '<option value="' . $formId . '"' . $selected . '>' . $formTitle . '</option>';
}
// Start building the html for our field
$field_html = $hiddenField;
$field_html .= '<select id="' . $fieldId . '" name="' . $field['name'] . $multiple . '">';
$field_html .= $field_options;
$field_html .= '</select>';
echo apply_filters('acf-gravityforms-add-on/field_html', $field_html, $field, $field_options, $multiple);
}
/**
* Return a form object when not empty
*
* @param $value
* @param $postId
* @param $field
* @return array|bool
*/
public function format_value($value, $postId, $field)
{
return $this->processValue($value, $field);
}
/**
*
* This filter is applied to the $value before it is updated in the db
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
public function update_value($value)
{
// Strip empty array values
if (is_array($value)) {
$value = array_values(array_filter($value));
}
return $value;
}
/**
* Check what to return on basis of return format
*
* @param $value
* @param $field
* @return array|bool|int
*/
public function processValue($value, $field)
{
if (is_array($value)) {
$formObjects = [];
foreach ($value as $key => $formId) {
$form = $this->processValue($formId, $field);
//Add it if it's not an error object
if ($form) {
$formObjects[$key] = $form;
}
}
// Return the form object
if (!empty($formObjects)) {
return $formObjects;
}
// Else return false
return false;
}
// Make sure field is an array
$field = (array)$field;
if (!empty($field['return_format']) && $field['return_format'] === 'id') {
return (int)$value;
}
$form = GFAPI::get_form($value);
//Return the form object if it's not an error object. Otherwise return false.
if (!is_wp_error($form)) {
return $form;
}
return false;
}
/**
* Check if we actually have forms that we can use for our field
*
* @return bool
*/
public function hasValidForms()
{
// Stop if Gravityforms is not active
if (!class_exists('GFAPI')) {
$this->notices->isGravityformsActive(true, true);
return false;
}
// Check if there are forms and set our choices
if (!$this->forms) {
$this->notices->hasActiveGravityForms(true, true);
return false;
}
return true;
}
}

View File

@@ -0,0 +1,197 @@
<?php
namespace ACFGravityformsField;
use acf_field;
use GFFormsModel;
class FieldForV4 extends acf_field
{
/**
* will hold info such as dir / path
*
* @var $settings
*/
public $settings;
/**
* will hold default field options
*
* @var array
*/
public $defaults;
/**
* Make sure we can easily access our notices
*
* @var Notices
*/
public $notices;
/**
* Get our forms
*
* @var array
*/
public $forms;
public function __construct()
{
$this->name = 'forms';
$this->label = __('Gravity Form', 'gravityforms');
$this->category = __('Relational', 'acf'); // Basic, Content, Choice, etc
$this->defaults = [
'return_format' => 'form_object',
'multiple' => 0,
'allow_null' => 0
];
// Get our notices up and running
$this->notices = new Notices();
// Execute the parent constructor as well
parent::__construct();
}
/**
* Create extra settings for our gravityforms field. These are visible when editing a field.
*
* @param $field
*/
public function create_options($field)
{
// defaults?
$field = array_merge($this->defaults, $field);
// key is needed in the field names to correctly save the data
$key = $field['name'];
// Create Field Options HTML
?>
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php echo __('Return Value', 'acf'); ?></label>
</td>
<td>
<?php
do_action('acf/create_field', [
'type' => 'radio',
'name' => 'fields[' . $key . '][return_format]',
'value' => $field['return_format'],
'choices' => [
'post_object' => __('Form Object', 'acf-gravityforms-add-on'),
'id' => __('Form ID', 'acf-gravityforms-add-on')
],
'layout' => 'horizontal',
]); ?>
</td>
</tr>
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php echo __('Allow Null?', 'acf'); ?></label>
</td>
<td>
<?php
do_action('acf/create_field', [
'type' => 'radio',
'name' => 'fields[' . $key . '][allow_null]',
'value' => $field['allow_null'],
'choices' => [
1 => __('Yes', 'acf'),
0 => __('No', 'acf'),
],
'layout' => 'horizontal',
]); ?>
</td>
</tr>
<tr class="field_option field_option_<?php echo $this->name; ?>">
<td class="label">
<label><?php echo __('Select multiple values?', 'acf'); ?></label>
</td>
<td>
<?php
do_action('acf/create_field', [
'type' => 'radio',
'name' => 'fields[' . $key . '][multiple]',
'value' => $field['multiple'],
'choices' => [
1 => __('Yes', 'acf'),
0 => __('No', 'acf'),
],
'layout' => 'horizontal',
]); ?>
</td>
</tr>
<?php
}
/**
* Render our Gravity Form field with all the forms as options
*
* @param $field
* @return bool
*/
public function create_field($field)
{
if (class_exists('GFFormsModel')) {
$this->forms = GFFormsModel::get_forms(true, false, 'title');
}
// Set our defaults
$field = array_merge($this->defaults, $field);
$choices = [];
// Check if we have some valid forms
$fieldObject = new Field();
if (!$fieldObject->hasValidForms()) {
return false;
}
foreach ($this->forms as $form) {
$choices[$form->id] = $form->title;
}
// Override field settings and start rendering
$field['choices'] = $choices;
$field['type'] = 'select';
do_action('acf/create_field', $field);
}
/**
* This filter is applied to the $value before it is updated in the db
*
* @param $value - the value which will be saved in the database
* @param $post_id - the $post_id of which the value will be saved
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
public function update_value($value, $post_id, $field)
{
// Strip empty array values
if (is_array($value)) {
$value = array_values(array_filter($value));
}
return $value;
}
/**
* Return a form object when not empty
*
* @param $value
* @param $postId
* @param $field
* @return array|bool
*/
public function format_value_for_api($value, $postId, $field)
{
$fieldObject = new Field();
return $fieldObject->processValue($value, $field);
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace ACFGravityformsField;
class Init
{
public function __construct()
{
$this->addHooks();
}
/**
* Make sure all hooks are being executed.
*/
private function addHooks()
{
add_action('acf/include_field_types', [$this, 'addField']);
add_action('acf/register_fields', [$this, 'addFieldforV4']);
add_action('admin_init', [$this, 'loadTextDomain']);
add_action('admin_init', [$this, 'addNotices']);
}
/**
* Initialize the notices
*/
public function addNotices()
{
$notices = new Notices();
$notices->addHooks();
}
/**
* Add a new Field object for our newest version in Advanced Custom Fields
*/
public function addField()
{
$field = new Field();
// Added 31.3.2022 to avoid errors when using “show in REST”
// https://wordpress.org/support/topic/fatal-error-when-show-in-rest-is-active/
if (function_exists('acf_register_field_type')) {
acf_register_field_type($field);
}
}
/**
* Add a new Field object for other versions (V4 in this case) of Advanced Custom Fields
*
*/
public function addFieldforV4()
{
new FieldForV4();
}
/**
* Load the gettext plugin textdomain located in our language directory.
*/
public function loadTextDomain()
{
load_plugin_textdomain('acf-gravityforms-add-on', false, ACF_GF_FIELD_LANGUAGES);
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace ACFGravityformsField;
use GFFormsModel;
class Notices
{
/**
* Get our forms
*
* @var array
*/
public $forms;
/**
* Make sure all hooks are being executed.
*/
public function addHooks()
{
add_action('admin_notices', [$this, 'isGravityFormsActive']);
add_action('admin_notices', [$this, 'isAdvancedCustomFieldsActive']);
}
/**
* Check if gravityforms is active. If not, issue a notice
*/
public function isGravityFormsActive($inline = '', $alt = '')
{
if (!class_exists('GFAPI')) {
$notice = sprintf(__(
'Warning: You need to <a href="%s">Activate Gravityforms</a> in order to use the Advanced Custom Fields: Gravityforms Add-on.',
'acf-gravityforms-add-on'
), admin_url('plugins.php'));
$this->createNotice($notice, $inline, $alt);
}
}
/**
* Check if there are any active gravityforms forms. If not, issue a notice
*/
public function hasActiveGravityForms($inline = '', $alt = '')
{
if (class_exists('GFFormsModel')) {
$this->forms = GFFormsModel::get_forms(true, false, 'title');
}
if (!$this->forms) {
$notice = sprintf(__(
' Warning: There are no active forms. You need to <a href="%s">Create a New Form</a> in order to use the Advanced Custom Fields: Gravityforms Add-on.',
'acf-gravityforms-add-on'
), admin_url('admin.php?page=gf_new_form'));
$this->createNotice($notice, $inline, $alt);
}
}
/**
* Check if advanced custom fields is active. If not, issue a notice
*/
public function isAdvancedCustomFieldsActive($inline = '', $alt = '')
{
if (!function_exists('get_field')) {
$notice = sprintf(__(
'Warning: You need to <a href="%s">Activate Advanced Custom Fields</a> in order to use the Advanced Custom Fields: Gravityforms Add-on.',
'acf-gravityforms-add-on'
), admin_url('plugins.php'));
$this->createNotice($notice, $inline, $alt);
}
}
/**
* A wrapper for all the notices.
*/
public function createNotice($notice, $inline = '', $alt = '')
{
$inline = $inline ? ' inline' : '';
$alt = $alt ? ' notice-alt' : '';
echo '<div class="notice notice-warning ' . $inline . $alt . '"><p>' . $notice . '</p></div>';
}
}

View File

@@ -0,0 +1,7 @@
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitfd2368103e25b49dd164ce246da68541::getLoader();

View File

@@ -0,0 +1,572 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0, PSR-4 and classmap class loader.
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
* @see https://www.php-fig.org/psr/psr-0/
* @see https://www.php-fig.org/psr/psr-4/
*/
class ClassLoader
{
/** @var ?string */
private $vendorDir;
// PSR-4
/**
* @var array[]
* @psalm-var array<string, array<string, int>>
*/
private $prefixLengthsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, array<int, string>>
*/
private $prefixDirsPsr4 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr4 = array();
// PSR-0
/**
* @var array[]
* @psalm-var array<string, array<string, string[]>>
*/
private $prefixesPsr0 = array();
/**
* @var array[]
* @psalm-var array<string, string>
*/
private $fallbackDirsPsr0 = array();
/** @var bool */
private $useIncludePath = false;
/**
* @var string[]
* @psalm-var array<string, string>
*/
private $classMap = array();
/** @var bool */
private $classMapAuthoritative = false;
/**
* @var bool[]
* @psalm-var array<string, bool>
*/
private $missingClasses = array();
/** @var ?string */
private $apcuPrefix;
/**
* @var self[]
*/
private static $registeredLoaders = array();
/**
* @param ?string $vendorDir
*/
public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
}
/**
* @return string[]
*/
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
}
return array();
}
/**
* @return array[]
* @psalm-return array<string, array<int, string>>
*/
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
/**
* @return array[]
* @psalm-return array<string, string>
*/
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
/**
* @return string[] Array of classname => path
* @psalm-var array<string, string>
*/
public function getClassMap()
{
return $this->classMap;
}
/**
* @param string[] $classMap Class to filename map
* @psalm-param array<string, string> $classMap
*
* @return void
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*
* @return void
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param string[]|string $paths The PSR-0 base directories
*
* @return void
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param string[]|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*
* @return void
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*
* @return void
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* APCu prefix to use to cache found/not-found classes, if the extension is enabled.
*
* @param string|null $apcuPrefix
*
* @return void
*/
public function setApcuPrefix($apcuPrefix)
{
$this->apcuPrefix = function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? $apcuPrefix : null;
}
/**
* The APCu prefix in use, or null if APCu caching is not enabled.
*
* @return string|null
*/
public function getApcuPrefix()
{
return $this->apcuPrefix;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
if (null === $this->vendorDir) {
return;
}
if ($prepend) {
self::$registeredLoaders = array($this->vendorDir => $this) + self::$registeredLoaders;
} else {
unset(self::$registeredLoaders[$this->vendorDir]);
self::$registeredLoaders[$this->vendorDir] = $this;
}
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
if (null !== $this->vendorDir) {
unset(self::$registeredLoaders[$this->vendorDir]);
}
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return true|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
return null;
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
return false;
}
if (null !== $this->apcuPrefix) {
$file = apcu_fetch($this->apcuPrefix.$class, $hit);
if ($hit) {
return $file;
}
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if (false === $file && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if (null !== $this->apcuPrefix) {
apcu_add($this->apcuPrefix.$class, $file);
}
if (false === $file) {
// Remember that this class does not exist.
$this->missingClasses[$class] = true;
}
return $file;
}
/**
* Returns the currently registered loaders indexed by their corresponding vendor directories.
*
* @return self[]
*/
public static function getRegisteredLoaders()
{
return self::$registeredLoaders;
}
/**
* @param string $class
* @param string $ext
* @return string|false
*/
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
$subPath = $class;
while (false !== $lastPos = strrpos($subPath, '\\')) {
$subPath = substr($subPath, 0, $lastPos);
$search = $subPath . '\\';
if (isset($this->prefixDirsPsr4[$search])) {
$pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
foreach ($this->prefixDirsPsr4[$search] as $dir) {
if (file_exists($file = $dir . $pathEnd)) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
return false;
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*
* @param string $file
* @return void
* @private
*/
function includeFile($file)
{
include $file;
}

View File

@@ -0,0 +1,10 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
);

View File

@@ -0,0 +1,9 @@
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);

View File

@@ -0,0 +1,11 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Composer\\Installers\\' => array($vendorDir . '/composer/installers/src/Composer/Installers'),
'ACFGravityformsField\\' => array($baseDir . '/resources'),
);

View File

@@ -0,0 +1,55 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitfd2368103e25b49dd164ce246da68541
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
/**
* @return \Composer\Autoload\ClassLoader
*/
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitfd2368103e25b49dd164ce246da68541', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitfd2368103e25b49dd164ce246da68541', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitfd2368103e25b49dd164ce246da68541::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
}
$loader->register(true);
return $loader;
}
}

View File

@@ -0,0 +1,44 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInitfd2368103e25b49dd164ce246da68541
{
public static $prefixLengthsPsr4 = array (
'C' =>
array (
'Composer\\Installers\\' => 20,
),
'A' =>
array (
'ACFGravityformsField\\' => 21,
),
);
public static $prefixDirsPsr4 = array (
'Composer\\Installers\\' =>
array (
0 => __DIR__ . '/..' . '/composer/installers/src/Composer/Installers',
),
'ACFGravityformsField\\' =>
array (
0 => __DIR__ . '/../..' . '/resources',
),
);
public static $classMap = array (
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitfd2368103e25b49dd164ce246da68541::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitfd2368103e25b49dd164ce246da68541::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitfd2368103e25b49dd164ce246da68541::$classMap;
}, null, ClassLoader::class);
}
}