Actualización

This commit is contained in:
Xes
2025-04-10 12:36:07 +02:00
parent 1da7c3f3b9
commit 4aff98e77b
3147 changed files with 320647 additions and 0 deletions

25
plugin/onlyoffice/vendor/autoload.php vendored Normal file
View File

@@ -0,0 +1,25 @@
<?php
// autoload.php @generated by Composer
if (PHP_VERSION_ID < 50600) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, $err);
} elseif (!headers_sent()) {
echo $err;
}
}
trigger_error(
$err,
E_USER_ERROR
);
}
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInite2447622f5a8ba1f88ff1d49032f1f2d::getLoader();

View File

@@ -0,0 +1,579 @@
<?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 \Closure(string):void */
private static $includeFile;
/** @var string|null */
private $vendorDir;
// PSR-4
/**
* @var array<string, array<string, int>>
*/
private $prefixLengthsPsr4 = array();
/**
* @var array<string, list<string>>
*/
private $prefixDirsPsr4 = array();
/**
* @var list<string>
*/
private $fallbackDirsPsr4 = array();
// PSR-0
/**
* List of PSR-0 prefixes
*
* Structured as array('F (first letter)' => array('Foo\Bar (full prefix)' => array('path', 'path2')))
*
* @var array<string, array<string, list<string>>>
*/
private $prefixesPsr0 = array();
/**
* @var list<string>
*/
private $fallbackDirsPsr0 = array();
/** @var bool */
private $useIncludePath = false;
/**
* @var array<string, string>
*/
private $classMap = array();
/** @var bool */
private $classMapAuthoritative = false;
/**
* @var array<string, bool>
*/
private $missingClasses = array();
/** @var string|null */
private $apcuPrefix;
/**
* @var array<string, self>
*/
private static $registeredLoaders = array();
/**
* @param string|null $vendorDir
*/
public function __construct($vendorDir = null)
{
$this->vendorDir = $vendorDir;
self::initializeIncludeClosure();
}
/**
* @return array<string, list<string>>
*/
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', array_values($this->prefixesPsr0));
}
return array();
}
/**
* @return array<string, list<string>>
*/
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
/**
* @return list<string>
*/
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
/**
* @return list<string>
*/
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
/**
* @return array<string, string> Array of classname => path
*/
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array<string, string> $classMap Class to filename map
*
* @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 list<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)
{
$paths = (array) $paths;
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
$paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
$paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
$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 list<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)
{
$paths = (array) $paths;
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
$paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
$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] = $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
$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 list<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 list<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 = self::$includeFile;
$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 keyed by their corresponding vendor directories.
*
* @return array<string, 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;
}
/**
* @return void
*/
private static function initializeIncludeClosure()
{
if (self::$includeFile !== null) {
return;
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*
* @param string $file
* @return void
*/
self::$includeFile = \Closure::bind(static function($file) {
include $file;
}, null, null);
}
}

View File

@@ -0,0 +1,359 @@
<?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;
use Composer\Autoload\ClassLoader;
use Composer\Semver\VersionParser;
/**
* This class is copied in every Composer installed project and available to all
*
* See also https://getcomposer.org/doc/07-runtime.md#installed-versions
*
* To require its presence, you can require `composer-runtime-api ^2.0`
*
* @final
*/
class InstalledVersions
{
/**
* @var mixed[]|null
* @psalm-var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}|array{}|null
*/
private static $installed;
/**
* @var bool|null
*/
private static $canGetVendors;
/**
* @var array[]
* @psalm-var array<string, array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
private static $installedByVendor = array();
/**
* Returns a list of all package names which are present, either by being installed, replaced or provided
*
* @return string[]
* @psalm-return list<string>
*/
public static function getInstalledPackages()
{
$packages = array();
foreach (self::getInstalled() as $installed) {
$packages[] = array_keys($installed['versions']);
}
if (1 === \count($packages)) {
return $packages[0];
}
return array_keys(array_flip(\call_user_func_array('array_merge', $packages)));
}
/**
* Returns a list of all package names with a specific type e.g. 'library'
*
* @param string $type
* @return string[]
* @psalm-return list<string>
*/
public static function getInstalledPackagesByType($type)
{
$packagesByType = array();
foreach (self::getInstalled() as $installed) {
foreach ($installed['versions'] as $name => $package) {
if (isset($package['type']) && $package['type'] === $type) {
$packagesByType[] = $name;
}
}
}
return $packagesByType;
}
/**
* Checks whether the given package is installed
*
* This also returns true if the package name is provided or replaced by another package
*
* @param string $packageName
* @param bool $includeDevRequirements
* @return bool
*/
public static function isInstalled($packageName, $includeDevRequirements = true)
{
foreach (self::getInstalled() as $installed) {
if (isset($installed['versions'][$packageName])) {
return $includeDevRequirements || !isset($installed['versions'][$packageName]['dev_requirement']) || $installed['versions'][$packageName]['dev_requirement'] === false;
}
}
return false;
}
/**
* Checks whether the given package satisfies a version constraint
*
* e.g. If you want to know whether version 2.3+ of package foo/bar is installed, you would call:
*
* Composer\InstalledVersions::satisfies(new VersionParser, 'foo/bar', '^2.3')
*
* @param VersionParser $parser Install composer/semver to have access to this class and functionality
* @param string $packageName
* @param string|null $constraint A version constraint to check for, if you pass one you have to make sure composer/semver is required by your package
* @return bool
*/
public static function satisfies(VersionParser $parser, $packageName, $constraint)
{
$constraint = $parser->parseConstraints((string) $constraint);
$provided = $parser->parseConstraints(self::getVersionRanges($packageName));
return $provided->matches($constraint);
}
/**
* Returns a version constraint representing all the range(s) which are installed for a given package
*
* It is easier to use this via isInstalled() with the $constraint argument if you need to check
* whether a given version of a package is installed, and not just whether it exists
*
* @param string $packageName
* @return string Version constraint usable with composer/semver
*/
public static function getVersionRanges($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
$ranges = array();
if (isset($installed['versions'][$packageName]['pretty_version'])) {
$ranges[] = $installed['versions'][$packageName]['pretty_version'];
}
if (array_key_exists('aliases', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['aliases']);
}
if (array_key_exists('replaced', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['replaced']);
}
if (array_key_exists('provided', $installed['versions'][$packageName])) {
$ranges = array_merge($ranges, $installed['versions'][$packageName]['provided']);
}
return implode(' || ', $ranges);
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
*/
public static function getVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['version'])) {
return null;
}
return $installed['versions'][$packageName]['version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as version, use satisfies or getVersionRanges if you need to know if a given version is present
*/
public static function getPrettyVersion($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['pretty_version'])) {
return null;
}
return $installed['versions'][$packageName]['pretty_version'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as reference
*/
public static function getReference($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
if (!isset($installed['versions'][$packageName]['reference'])) {
return null;
}
return $installed['versions'][$packageName]['reference'];
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @param string $packageName
* @return string|null If the package is being replaced or provided but is not really installed, null will be returned as install path. Packages of type metapackages also have a null install path.
*/
public static function getInstallPath($packageName)
{
foreach (self::getInstalled() as $installed) {
if (!isset($installed['versions'][$packageName])) {
continue;
}
return isset($installed['versions'][$packageName]['install_path']) ? $installed['versions'][$packageName]['install_path'] : null;
}
throw new \OutOfBoundsException('Package "' . $packageName . '" is not installed');
}
/**
* @return array
* @psalm-return array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}
*/
public static function getRootPackage()
{
$installed = self::getInstalled();
return $installed[0]['root'];
}
/**
* Returns the raw installed.php data for custom implementations
*
* @deprecated Use getAllRawData() instead which returns all datasets for all autoloaders present in the process. getRawData only returns the first dataset loaded, which may not be what you expect.
* @return array[]
* @psalm-return array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}
*/
public static function getRawData()
{
@trigger_error('getRawData only returns the first dataset loaded, which may not be what you expect. Use getAllRawData() instead which returns all datasets for all autoloaders present in the process.', E_USER_DEPRECATED);
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
self::$installed = include __DIR__ . '/installed.php';
} else {
self::$installed = array();
}
}
return self::$installed;
}
/**
* Returns the raw data of all installed.php which are currently loaded for custom implementations
*
* @return array[]
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
public static function getAllRawData()
{
return self::getInstalled();
}
/**
* Lets you reload the static array from another file
*
* This is only useful for complex integrations in which a project needs to use
* this class but then also needs to execute another project's autoloader in process,
* and wants to ensure both projects have access to their version of installed.php.
*
* A typical case would be PHPUnit, where it would need to make sure it reads all
* the data it needs from this class, then call reload() with
* `require $CWD/vendor/composer/installed.php` (or similar) as input to make sure
* the project in which it runs can then also use this class safely, without
* interference between PHPUnit's dependencies and the project's dependencies.
*
* @param array[] $data A vendor/composer/installed.php data set
* @return void
*
* @psalm-param array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $data
*/
public static function reload($data)
{
self::$installed = $data;
self::$installedByVendor = array();
}
/**
* @return array[]
* @psalm-return list<array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>}>
*/
private static function getInstalled()
{
if (null === self::$canGetVendors) {
self::$canGetVendors = method_exists('Composer\Autoload\ClassLoader', 'getRegisteredLoaders');
}
$installed = array();
if (self::$canGetVendors) {
foreach (ClassLoader::getRegisteredLoaders() as $vendorDir => $loader) {
if (isset(self::$installedByVendor[$vendorDir])) {
$installed[] = self::$installedByVendor[$vendorDir];
} elseif (is_file($vendorDir.'/composer/installed.php')) {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require $vendorDir.'/composer/installed.php';
$installed[] = self::$installedByVendor[$vendorDir] = $required;
if (null === self::$installed && strtr($vendorDir.'/composer', '\\', '/') === strtr(__DIR__, '\\', '/')) {
self::$installed = $installed[count($installed) - 1];
}
}
}
}
if (null === self::$installed) {
// only require the installed.php file if this file is loaded from its dumped location,
// and not from its source location in the composer/composer package, see https://github.com/composer/composer/issues/9937
if (substr(__DIR__, -8, 1) !== 'C') {
/** @var array{root: array{name: string, pretty_version: string, version: string, reference: string|null, type: string, install_path: string, aliases: string[], dev: bool}, versions: array<string, array{pretty_version?: string, version?: string, reference?: string|null, type?: string, install_path?: string, aliases?: string[], dev_requirement: bool, replaced?: string[], provided?: string[]}>} $required */
$required = require __DIR__ . '/installed.php';
self::$installed = $required;
} else {
self::$installed = array();
}
}
if (self::$installed !== array()) {
$installed[] = self::$installed;
}
return $installed;
}
}

View File

@@ -0,0 +1,15 @@
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Attribute' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php',
'PhpToken' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
'Stringable' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
'UnhandledMatchError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
'ValueError' => $vendorDir . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',
);

View File

@@ -0,0 +1,12 @@
<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
);

View File

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

View File

@@ -0,0 +1,24 @@
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Polyfill\\Ctype\\' => array($vendorDir . '/symfony/polyfill-ctype'),
'PhpOption\\' => array($vendorDir . '/phpoption/phpoption/src/PhpOption'),
'Onlyoffice\\DocsIntegrationSdk\\Util\\' => array($vendorDir . '/onlyoffice/docs-integration-sdk/src/util'),
'Onlyoffice\\DocsIntegrationSdk\\Service\\Request\\' => array($vendorDir . '/onlyoffice/docs-integration-sdk/src/service/request'),
'Onlyoffice\\DocsIntegrationSdk\\Service\\DocEditorConfig\\' => array($vendorDir . '/onlyoffice/docs-integration-sdk/src/service/doceditorconfig'),
'Onlyoffice\\DocsIntegrationSdk\\Models\\' => array($vendorDir . '/onlyoffice/docs-integration-sdk/src/models'),
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Settings\\' => array($vendorDir . '/onlyoffice/docs-integration-sdk/src/manager/settings'),
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Security\\' => array($vendorDir . '/onlyoffice/docs-integration-sdk/src/manager/security'),
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Formats\\' => array($vendorDir . '/onlyoffice/docs-integration-sdk/src/manager/formats'),
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Document\\' => array($vendorDir . '/onlyoffice/docs-integration-sdk/src/manager/document'),
'Onlyoffice\\DocsIntegrationSdk\\' => array($vendorDir . '/onlyoffice/docs-integration-sdk/src'),
'GrahamCampbell\\ResultType\\' => array($vendorDir . '/graham-campbell/result-type/src'),
'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
);

View File

@@ -0,0 +1,50 @@
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInite2447622f5a8ba1f88ff1d49032f1f2d
{
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;
}
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInite2447622f5a8ba1f88ff1d49032f1f2d', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInite2447622f5a8ba1f88ff1d49032f1f2d', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInite2447622f5a8ba1f88ff1d49032f1f2d::getInitializer($loader));
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInite2447622f5a8ba1f88ff1d49032f1f2d::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
require $file;
}
}, null, null);
foreach ($filesToLoad as $fileIdentifier => $file) {
$requireFile($fileIdentifier, $file);
}
return $loader;
}
}

View File

@@ -0,0 +1,129 @@
<?php
// autoload_static.php @generated by Composer
namespace Composer\Autoload;
class ComposerStaticInite2447622f5a8ba1f88ff1d49032f1f2d
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
);
public static $prefixLengthsPsr4 = array (
'S' =>
array (
'Symfony\\Polyfill\\Php80\\' => 23,
'Symfony\\Polyfill\\Mbstring\\' => 26,
'Symfony\\Polyfill\\Ctype\\' => 23,
),
'P' =>
array (
'PhpOption\\' => 10,
),
'O' =>
array (
'Onlyoffice\\DocsIntegrationSdk\\Util\\' => 35,
'Onlyoffice\\DocsIntegrationSdk\\Service\\Request\\' => 46,
'Onlyoffice\\DocsIntegrationSdk\\Service\\DocEditorConfig\\' => 54,
'Onlyoffice\\DocsIntegrationSdk\\Models\\' => 37,
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Settings\\' => 47,
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Security\\' => 47,
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Formats\\' => 46,
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Document\\' => 47,
'Onlyoffice\\DocsIntegrationSdk\\' => 30,
),
'G' =>
array (
'GrahamCampbell\\ResultType\\' => 26,
),
'D' =>
array (
'Dotenv\\' => 7,
),
);
public static $prefixDirsPsr4 = array (
'Symfony\\Polyfill\\Php80\\' =>
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-php80',
),
'Symfony\\Polyfill\\Mbstring\\' =>
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring',
),
'Symfony\\Polyfill\\Ctype\\' =>
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-ctype',
),
'PhpOption\\' =>
array (
0 => __DIR__ . '/..' . '/phpoption/phpoption/src/PhpOption',
),
'Onlyoffice\\DocsIntegrationSdk\\Util\\' =>
array (
0 => __DIR__ . '/..' . '/onlyoffice/docs-integration-sdk/src/util',
),
'Onlyoffice\\DocsIntegrationSdk\\Service\\Request\\' =>
array (
0 => __DIR__ . '/..' . '/onlyoffice/docs-integration-sdk/src/service/request',
),
'Onlyoffice\\DocsIntegrationSdk\\Service\\DocEditorConfig\\' =>
array (
0 => __DIR__ . '/..' . '/onlyoffice/docs-integration-sdk/src/service/doceditorconfig',
),
'Onlyoffice\\DocsIntegrationSdk\\Models\\' =>
array (
0 => __DIR__ . '/..' . '/onlyoffice/docs-integration-sdk/src/models',
),
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Settings\\' =>
array (
0 => __DIR__ . '/..' . '/onlyoffice/docs-integration-sdk/src/manager/settings',
),
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Security\\' =>
array (
0 => __DIR__ . '/..' . '/onlyoffice/docs-integration-sdk/src/manager/security',
),
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Formats\\' =>
array (
0 => __DIR__ . '/..' . '/onlyoffice/docs-integration-sdk/src/manager/formats',
),
'Onlyoffice\\DocsIntegrationSdk\\Manager\\Document\\' =>
array (
0 => __DIR__ . '/..' . '/onlyoffice/docs-integration-sdk/src/manager/document',
),
'Onlyoffice\\DocsIntegrationSdk\\' =>
array (
0 => __DIR__ . '/..' . '/onlyoffice/docs-integration-sdk/src',
),
'GrahamCampbell\\ResultType\\' =>
array (
0 => __DIR__ . '/..' . '/graham-campbell/result-type/src',
),
'Dotenv\\' =>
array (
0 => __DIR__ . '/..' . '/vlucas/phpdotenv/src',
),
);
public static $classMap = array (
'Attribute' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Attribute.php',
'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php',
'PhpToken' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/PhpToken.php',
'Stringable' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/Stringable.php',
'UnhandledMatchError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/UnhandledMatchError.php',
'ValueError' => __DIR__ . '/..' . '/symfony/polyfill-php80/Resources/stubs/ValueError.php',
);
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInite2447622f5a8ba1f88ff1d49032f1f2d::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite2447622f5a8ba1f88ff1d49032f1f2d::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite2447622f5a8ba1f88ff1d49032f1f2d::$classMap;
}, null, ClassLoader::class);
}
}

View File

@@ -0,0 +1,86 @@
<?php return array(
'root' => array(
'name' => '__root__',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'e2dac8179b6ce15fe4dfb1df7703546297a02790',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev' => true,
),
'versions' => array(
'__root__' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => 'e2dac8179b6ce15fe4dfb1df7703546297a02790',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'dev_requirement' => false,
),
'graham-campbell/result-type' => array(
'pretty_version' => 'v1.1.3',
'version' => '1.1.3.0',
'reference' => '3ba905c11371512af9d9bdd27d99b782216b6945',
'type' => 'library',
'install_path' => __DIR__ . '/../graham-campbell/result-type',
'aliases' => array(),
'dev_requirement' => false,
),
'onlyoffice/docs-integration-sdk' => array(
'pretty_version' => 'v1.0.1',
'version' => '1.0.1.0',
'reference' => '6f63b25db1108c469ad0d94f786f0870f403c795',
'type' => 'library',
'install_path' => __DIR__ . '/../onlyoffice/docs-integration-sdk',
'aliases' => array(),
'dev_requirement' => false,
),
'phpoption/phpoption' => array(
'pretty_version' => '1.9.3',
'version' => '1.9.3.0',
'reference' => 'e3fac8b24f56113f7cb96af14958c0dd16330f54',
'type' => 'library',
'install_path' => __DIR__ . '/../phpoption/phpoption',
'aliases' => array(),
'dev_requirement' => false,
),
'symfony/polyfill-ctype' => array(
'pretty_version' => 'v1.31.0',
'version' => '1.31.0.0',
'reference' => 'a3cc8b044a6ea513310cbd48ef7333b384945638',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-ctype',
'aliases' => array(),
'dev_requirement' => false,
),
'symfony/polyfill-mbstring' => array(
'pretty_version' => 'v1.31.0',
'version' => '1.31.0.0',
'reference' => '85181ba99b2345b0ef10ce42ecac37612d9fd341',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-mbstring',
'aliases' => array(),
'dev_requirement' => false,
),
'symfony/polyfill-php80' => array(
'pretty_version' => 'v1.31.0',
'version' => '1.31.0.0',
'reference' => '60328e362d4c2c802a54fcbf04f9d3fb892b4cf8',
'type' => 'library',
'install_path' => __DIR__ . '/../symfony/polyfill-php80',
'aliases' => array(),
'dev_requirement' => false,
),
'vlucas/phpdotenv' => array(
'pretty_version' => 'v5.6.1',
'version' => '5.6.1.0',
'reference' => 'a59a13791077fe3d44f90e7133eb68e7d22eaff2',
'type' => 'library',
'install_path' => __DIR__ . '/../vlucas/phpdotenv',
'aliases' => array(),
'dev_requirement' => false,
),
),
);

View File

@@ -0,0 +1,26 @@
<?php
// platform_check.php @generated by Composer
$issues = array();
if (!(PHP_VERSION_ID >= 70205)) {
$issues[] = 'Your Composer dependencies require a PHP version ">= 7.2.5". You are running ' . PHP_VERSION . '.';
}
if ($issues) {
if (!headers_sent()) {
header('HTTP/1.1 500 Internal Server Error');
}
if (!ini_get('display_errors')) {
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
fwrite(STDERR, 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . implode(PHP_EOL, $issues) . PHP_EOL.PHP_EOL);
} elseif (!headers_sent()) {
echo 'Composer detected issues in your platform:' . PHP_EOL.PHP_EOL . str_replace('You are running '.PHP_VERSION.'.', '', implode(PHP_EOL, $issues)) . PHP_EOL.PHP_EOL;
}
}
trigger_error(
'Composer detected issues in your platform: ' . implode(' ', $issues),
E_USER_ERROR
);
}

View File

@@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
/*
* This file is part of Result Type.
*
* (c) Graham Campbell <hello@gjcampbell.co.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace GrahamCampbell\ResultType;
use PhpOption\None;
use PhpOption\Some;
/**
* @template T
* @template E
*
* @extends \GrahamCampbell\ResultType\Result<T,E>
*/
final class Error extends Result
{
/**
* @var E
*/
private $value;
/**
* Internal constructor for an error value.
*
* @param E $value
*
* @return void
*/
private function __construct($value)
{
$this->value = $value;
}
/**
* Create a new error value.
*
* @template F
*
* @param F $value
*
* @return \GrahamCampbell\ResultType\Result<T,F>
*/
public static function create($value)
{
return new self($value);
}
/**
* Get the success option value.
*
* @return \PhpOption\Option<T>
*/
public function success()
{
return None::create();
}
/**
* Map over the success value.
*
* @template S
*
* @param callable(T):S $f
*
* @return \GrahamCampbell\ResultType\Result<S,E>
*/
public function map(callable $f)
{
return self::create($this->value);
}
/**
* Flat map over the success value.
*
* @template S
* @template F
*
* @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
*
* @return \GrahamCampbell\ResultType\Result<S,F>
*/
public function flatMap(callable $f)
{
/** @var \GrahamCampbell\ResultType\Result<S,F> */
return self::create($this->value);
}
/**
* Get the error option value.
*
* @return \PhpOption\Option<E>
*/
public function error()
{
return Some::create($this->value);
}
/**
* Map over the error value.
*
* @template F
*
* @param callable(E):F $f
*
* @return \GrahamCampbell\ResultType\Result<T,F>
*/
public function mapError(callable $f)
{
return self::create($f($this->value));
}
}

View File

@@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
/*
* This file is part of Result Type.
*
* (c) Graham Campbell <hello@gjcampbell.co.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace GrahamCampbell\ResultType;
/**
* @template T
* @template E
*/
abstract class Result
{
/**
* Get the success option value.
*
* @return \PhpOption\Option<T>
*/
abstract public function success();
/**
* Map over the success value.
*
* @template S
*
* @param callable(T):S $f
*
* @return \GrahamCampbell\ResultType\Result<S,E>
*/
abstract public function map(callable $f);
/**
* Flat map over the success value.
*
* @template S
* @template F
*
* @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
*
* @return \GrahamCampbell\ResultType\Result<S,F>
*/
abstract public function flatMap(callable $f);
/**
* Get the error option value.
*
* @return \PhpOption\Option<E>
*/
abstract public function error();
/**
* Map over the error value.
*
* @template F
*
* @param callable(E):F $f
*
* @return \GrahamCampbell\ResultType\Result<T,F>
*/
abstract public function mapError(callable $f);
}

View File

@@ -0,0 +1,120 @@
<?php
declare(strict_types=1);
/*
* This file is part of Result Type.
*
* (c) Graham Campbell <hello@gjcampbell.co.uk>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace GrahamCampbell\ResultType;
use PhpOption\None;
use PhpOption\Some;
/**
* @template T
* @template E
*
* @extends \GrahamCampbell\ResultType\Result<T,E>
*/
final class Success extends Result
{
/**
* @var T
*/
private $value;
/**
* Internal constructor for a success value.
*
* @param T $value
*
* @return void
*/
private function __construct($value)
{
$this->value = $value;
}
/**
* Create a new error value.
*
* @template S
*
* @param S $value
*
* @return \GrahamCampbell\ResultType\Result<S,E>
*/
public static function create($value)
{
return new self($value);
}
/**
* Get the success option value.
*
* @return \PhpOption\Option<T>
*/
public function success()
{
return Some::create($this->value);
}
/**
* Map over the success value.
*
* @template S
*
* @param callable(T):S $f
*
* @return \GrahamCampbell\ResultType\Result<S,E>
*/
public function map(callable $f)
{
return self::create($f($this->value));
}
/**
* Flat map over the success value.
*
* @template S
* @template F
*
* @param callable(T):\GrahamCampbell\ResultType\Result<S,F> $f
*
* @return \GrahamCampbell\ResultType\Result<S,F>
*/
public function flatMap(callable $f)
{
return $f($this->value);
}
/**
* Get the error option value.
*
* @return \PhpOption\Option<E>
*/
public function error()
{
return None::create();
}
/**
* Map over the error value.
*
* @template F
*
* @param callable(E):F $f
*
* @return \GrahamCampbell\ResultType\Result<T,F>
*/
public function mapError(callable $f)
{
return self::create($this->value);
}
}

View File

@@ -0,0 +1,35 @@
# ENV
DOCS_INTEGRATION_SDK_PRODUCT_NAME=ONLYOFFICE
# Document server
DOCS_INTEGRATION_SDK_DOCUMENT_SERVER_URL=
DOCS_INTEGRATION_SDK_DOCUMENT_SERVER_API_URL=/web-apps/apps/api/documents/api.js
DOCS_INTEGRATION_SDK_DOCUMENT_SERVER_API_PRELOADER_URL=/web-apps/apps/api/documents/cache-scripts.html
DOCS_INTEGRATION_SDK_DOCUMENT_SERVER_HEALTHCHECK_URL=/healthcheck
# JWT
DOCS_INTEGRATION_SDK_JWT_HEADER=Authorization
DOCS_INTEGRATION_SDK_JWT_PREFIX="Bearer "
DOCS_INTEGRATION_SDK_JWT_KEY=
DOCS_INTEGRATION_SDK_JWT_LEEWAY=3
# Editing service
DOCS_INTEGRATION_SDK_EDITING_SERVICE_INSERT_IMAGE=bmp|gif|jpeg|jpg|png|tif|tiff
DOCS_INTEGRATION_SDK_EDITING_SERVICE_MAX_FILE_SIZE=104857600
DOCS_INTEGRATION_SDK_EDITING_SERVICE_MOBILE_USER_AGENT="android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino"
# Convert service
DOCS_INTEGRATION_SDK_CONVERT_SERVICE_URL=/ConvertService.ashx
DOCS_INTEGRATION_SDK_CONVERT_SERVICE_SYNC_SOCKET_TIMEOUT=60
DOCS_INTEGRATION_SDK_CONVERT_SERVICE_MAX_FILE_SIZE=104857600
# Command service
DOCS_INTEGRATION_SDK_COMMAND_SERVICE_URL=/coauthoring/CommandService.ashx
# Docbuilder service
DOCS_INTEGRATION_SDK_DOCBUILDER_SERVICE_URL=/docbuilder
# HTTP
DOCS_INTEGRATION_SDK_HTTP_CONNECTION_TIMEOUT=10
DOCS_INTEGRATION_SDK_HTTP_REQUEST_TIMEOUT=10
DOCS_INTEGRATION_SDK_HTTP_IGNORE_SSL=false

View File

@@ -0,0 +1,4 @@
# Authors
* Ascensio System SIA: <integration@onlyoffice.com>

View File

@@ -0,0 +1,26 @@
# Change Log
## 1.0.1
- minor fixes
- fix settings check
## 1.0.0
- common interfaces
- list supported formats
- empty file templates
- demo server settings
## 0.0.5
- default empty templates
## 0.0.4
- minor fixes
## 0.0.3
- support pdf form
## 0.0.2
- remove git submodules
## 0.0.1
- Initial release

View File

@@ -0,0 +1,162 @@
# ONLYOFFICE Docs Integration PHP SDK
ONLYOFFICE Docs Integration PHP SDK provides common interfaces and default implementations for integrating ONLYOFFICE Document Server into your own website or application on PHP.
## Prerequisites
* **PHP**: version 7.4.0 and higher
### Managers
| Manager | Description | Default implementation |
| ----------------------------- | ----------------------------------------------------------------------- | -------------------------------- |
| DocumentManagerInterface | This manager is used for working with files, and string data associated with documents. | DocumentManager (abstract) |
| FormatsManagerInterface | This manager is used for working with document formats. | FormatsManager |
| JwtManagerInterface | This manager is used for generating and verifying authorization tokens. | JwtManager (abstract) |
| SettingsManagerInterface | This manager is used to manage integration application settings. | SettingsManager (abstract) |
### Services
| Service | Description | Default implementation |
| ----------------------------- | ----------------------------------------------------------------------- | -------------------------------- |
| CallbackServiceInterface | This service is used for processing the response of the Document Server. | CallbackService (abstract) |
| DocEditorConfigServiceInterface | This configuration generation service is used for opening the document editor. | DocEditorConfigService |
| RequestServiceInterface | This service is used to make requests to the ONLYOFFICE Document Server. | RequestService (abstract) |
## Usage
1. Implement the methods of the abstract **DocumentManager** class:
```php
public function getDocumentKey(string $fileId, bool $embedded = false)
{
return self::generateRevisionId($fileId);
}
public function getDocumentName(string $fileId)
{
return "sample.docx";
}
public static function getLangMapping()
{
return null;
}
public static function getFileUrl(string $fileId)
{
return "https://example-server.example/fileId/download/";
}
public static function getCallbackUrl(string $fileId)
{
return "https://example-server.example/callback";
}
public static function getGobackUrl(string $fileId)
{
return "https://example-server.example/filelist";
}
public static function getCreateUrl(string $fileId)
{
return "https://example-server.example/fileId";
}
```
2. Implement the methods of the abstract **JwtManager** class (use third-party libraries for JWT encoding and decoding, whichever is convenient for you):
```php
public function encode($token, $key, $algorithm = "HS256")
{
return "SOME.JWT.STRING";
}
public function decode($token, $key, $algorithm = "HS256")
{
return json_encode([]);
}
```
3. Implement the methods of the abstract **SettingsManager** class:
```php
public function getServerUrl()
{
return "https://example-server.example/";
}
public function getSetting($settingName)
{
return null;
}
public function setSetting($settingName, $value, $createSetting = false)
{
// if ($createSetting === true) {
// $this->yourMethodForCreateNewSetting($settingName, $value);
// return;
// }
// $this->yourMethodForSetNewValueForSetting($settingName, $value);
}
```
4. Implement the methods of the abstract **SettingsManager** class:
```php
public function processTrackerStatusEditing()
{
// $someTrackResult["error"] = 0;
// return json_encode($someTrackResult);
}
public function processTrackerStatusMustsave()
{
// $someTrackResult["error"] = 0;
// return json_encode($someTrackResult);
}
public function processTrackerStatusCorrupted()
{
// $someTrackResult["error"] = 0;
// return json_encode($someTrackResult);
}
public function processTrackerStatusClosed()
{
// $someTrackResult["error"] = 0;
// return json_encode($someTrackResult);
}
public function processTrackerStatusForcesave()
{
// $someTrackResult["error"] = 0;
// return json_encode($someTrackResult);
}
```
5. Create a class that implements the **HttpClientInterface** interface (use PHP Client URL Library or any other third-party library to make requests):
```php
class YourHttpClient implements HttpClientInterface
{
public function __construct()
{
$this->responseStatusCode = null;
$this->responseBody = null;
}
public function getStatusCode()
{
return $this->responseStatusCode;
}
public function getBody()
{
return $this->responseBody;
}
public function request($url, $method = 'GET', $opts = [])
{
$this->responseStatusCode = 200;
$this->responseBody = "{\"status\": \"OK\"}";
}
}
```
6. Implement the method of the abstract **RequestService** class:
```php
public function getFileUrlForConvert()
{
return "https://example-server.example/file-url-for-check-convert";
}
```
7. Use DocEditorConfigService to create a config model for the editors in your own controllers.

View File

@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<ruleset name="Custom Standard">
<description>A custom coding standard</description>
<rule ref="PSR2"/>
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName"/>
<rule ref="Squiz.NamingConventions.ValidVariableName.PublicHasUnderscore">
<severity>0</severity>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore">
<severity>0</severity>
</rule>
</ruleset>

View File

@@ -0,0 +1,4 @@
# Authors
* Ascensio System SIA: <integration@onlyoffice.com>

View File

@@ -0,0 +1,15 @@
# Change Log
## 2.0.0
- pdf documentType for djvu, docxf, oform, oxps, pdf, xps
- fb2 additional mime
## 1.1.0
- filling pdf
- conversion formats for txt, csv
- formats for auto conversion
## 1.0.0
- formats for viewing, editing and lossy editing
- formats for conversions
- mime-types of formats

View File

@@ -0,0 +1,52 @@
## Overview
This repository contains the list of file formats (electronic documents, forms, spreadsheets, presentations) supported by ONLYOFFICE editors and describes the properties of each file format type.
The repository is used in:
* [Document Server integration example](https://github.com/ONLYOFFICE/document-server-integration)
* [ONLYOFFICE Docs Integration Java SDK](https://github.com/ONLYOFFICE/docs-integration-sdk-java)
* [ONLYOFFICE Docs Integration PHP SDK](https://github.com/ONLYOFFICE/docs-integration-sdk-php)
* [Nextcloud ONLYOFFICE integration app](https://github.com/ONLYOFFICE/onlyoffice-nextcloud)
* [Nuxeo ONLYOFFICE integration plugin](https://github.com/ONLYOFFICE/onlyoffice-nuxeo)
* [ONLYOFFICE integration app for Confluence Cloud](https://github.com/ONLYOFFICE/onlyoffice-confluence-cloud)
* [ownCloud ONLYOFFICE integration app](https://github.com/ONLYOFFICE/onlyoffice-owncloud)
* [Redmine ONLYOFFICE Integration Plugin](https://github.com/ONLYOFFICE/onlyoffice-redmine)
* [WordPress ONLYOFFICE integration plugin](https://github.com/ONLYOFFICE/onlyoffice-wordpress)
## Project info
ONLYOFFICE Docs (Document Server): [github.com/ONLYOFFICE/DocumentServer](https://github.com/ONLYOFFICE/DocumentServer)
Official website: [www.onlyoffice.com](https://www.onlyoffice.com/)
## Supported formats
**For viewing:**
* **WORD**: DOC, DOCM, DOCX, DOT, DOTM, DOTX, EPUB, FB2, FODT, HTM, HTML, MHT, MHTML, ODT, OTT, RTF, STW, SXW, TXT, WPS, WPT, XML
* **CELL**: CSV, ET, ETT, FODS, ODS, OTS, SXC, XLS, XLSB, XLSM, XLSX, XLT, XLTM, XLTX
* **SLIDE**: DPS, DPT, FODP, ODP, OTP, POT, POTM, POTX, PPS, PPSM, PPSX, PPT, PPTM, PPTX, SXI
* **PDF**: DJVU, DOCXF, OFORM, OXPS, PDF, XPS
**For editing:**
* **WORD**: DOCM, DOCX, DOTM, DOTX
* **CELL**: XLSM, XLSX, XLTM, XLTX
* **SLIDE**: POTM, POTX, PPSM, PPSX, PPTM, PPTX
* **PDF**: PDF
**For editing with possible loss of information:**
* **WORD**: EPUB, FB2, HTML, ODT, OTT, RTF, TXT
* **CELL**: CSV, ODS, OTS
* **SLIDE**: ODP, OTP
**For filling:**
* **PDF**: PDF
**For converting to Office Open XML formats:**
* **WORD:** DOC, DOCM, DOT, DOTM, DOTX, EPUB, FB2, FODT, HTM, HTML, MHT, MHTML, ODT, OTT, RTF, STW, SXW, WPS, WPT, XML
* **CELL:** ET, ETT, FODS, ODS, OTS, SXC, XLS, XLSB, XLSM, XLT, XLTM, XLTX
* **SLIDE:** DPS, DPT, FODP, ODP, OTP, POT, POTM, POTX, PPS, PPSM, PPSX, PPT, PPTM, SXI
* **PDF**: DOCXF, OXPS, PDF, XPS

View File

@@ -0,0 +1,288 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Manager\Document;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Manager\Settings\SettingsManager;
use Onlyoffice\DocsIntegrationSdk\Manager\Document\DocumentManagerInterface;
use Onlyoffice\DocsIntegrationSdk\Models\Format;
use Onlyoffice\DocsIntegrationSdk\Manager\Formats\FormatsManager;
use Onlyoffice\DocsIntegrationSdk\Util\CommonError;
abstract class DocumentManager implements DocumentManagerInterface
{
private const PATHINFO_DIRNAME = "dirname";
private const PATHINFO_BASENAME = "basename";
private const PATHINFO_EXTENSION = "extension";
private const PATHINFO_FILENAME = "filename";
private const FORMATINFO_TYPE = "type";
private const FORMATINFO_ACTIONS = "actions";
private const FORMATINFO_CONVERT = "convert";
private const FORMATINFO_MIMES = "mimes";
private const FORMATINFO_MIME = "mime";
/**
* Formats list
*/
public $formats;
public $locale;
public $lang;
public $settingsManager;
public const APP_NAME = "onlyoffice";
abstract public function getDocumentKey(string $fileId, bool $embedded);
abstract public function getDocumentName(string $fileId);
abstract public static function getLangMapping();
abstract public function getFileUrl(string $fileId);
abstract public function getCallbackUrl(string $fileId);
abstract public function getGobackUrl(string $fileId);
abstract public function getCreateUrl(string $fileId);
public function __construct(
SettingsManager $settingsManager,
FormatsManager $formats = null,
$systemLangCode = "en"
) {
$this->lang = $systemLangCode;
$this->lang = $systemLangCode;
if (empty($formats)) {
$formats = new FormatsManager(true);
}
if (isset(static::getLangMapping()[$systemLangCode]) && !empty(static::getLangMapping()[$systemLangCode])) {
$locale = static::getLangMapping()[$systemLangCode];
} else {
$locale = "default";
}
$this->formats = $formats;
$this->settingsManager = $settingsManager;
}
public function getEmptyTemplate($fileExt)
{
$filePath = dirname(dirname(dirname(__DIR__)))
.DIRECTORY_SEPARATOR.
"resources".
DIRECTORY_SEPARATOR.
"assets".
DIRECTORY_SEPARATOR.
"document-templates".
DIRECTORY_SEPARATOR.
$this->locale.
DIRECTORY_SEPARATOR.
"new.".
$fileExt;
if (!file_exists($filePath)) {
throw new \Exception(CommonError::message(CommonError::FILE_TEMPLATE_IS_NOT_EXISTS));
}
return $filePath;
}
/**
* Get temporary file
*
* @return array
*/
public function getTempFile()
{
$fileUrl = null;
$templatePath = $this->getEmptyTemplate("docx");
$fileUrl = $this->getFileUrl("new.docx");
return [
"fileUrl" => $fileUrl,
"filePath" => $templatePath
];
}
public function getFormatInfo(string $extension, string $option = null)
{
$search = null;
$formats = $this->formats->getFormatsList();
if (!array_key_exists($extension, $formats)) {
foreach ($formats as $format) {
if ($format->getName() === $extension) {
$search = $format;
break;
}
}
if ($search === null) {
return null;
}
} else {
$search = $formats[$extension];
}
switch ($option) {
case self::FORMATINFO_TYPE:
return $search->getType();
case self::FORMATINFO_ACTIONS:
return $search->getActions();
case self::FORMATINFO_CONVERT:
return $search->getConvert();
case self::FORMATINFO_MIMES:
return $search->getMimes();
case self::FORMATINFO_MIME:
return $search->getMimes()[0];
default:
return $search;
}
}
/**
* Return file type by extension
*/
public function getDocType(string $extension)
{
return $this->getFormatInfo($extension, self::FORMATINFO_TYPE);
}
/**
* Return actions for file by extension
*/
public function getDocActions(string $extension)
{
return $this->getFormatInfo($extension, self::FORMATINFO_ACTIONS);
}
/**
* Return convert extensions for file by current extension
*/
public function getDocConvert(string $extension)
{
return $this->getFormatInfo($extension, self::FORMATINFO_CONVERT);
}
/**
* Return array of all mime types for file by extension
*/
public function getDocMimes(string $extension)
{
return $this->getFormatInfo($extension, self::FORMATINFO_MIMES);
}
/**
* Return mime type of the file by extension
*/
public function getDocMimeType(string $extension)
{
return $this->getFormatInfo($extension, self::FORMATINFO_MIME);
}
/**
* Return file path info
*/
public function getPathInfo(string $filePath, string $option = null)
{
$result = ["dirname" => "", "basename" => "", "extension" => "", "filename" => ""];
$pathInfo = [];
if (preg_match("#^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^.\\\\/]+?)|))[\\\\/.]*$#m", $filePath, $pathInfo)) {
if (array_key_exists(1, $pathInfo)) {
$result["dirname"] = $pathInfo[1];
}
if (array_key_exists(2, $pathInfo)) {
$result["basename"] = $pathInfo[2];
}
if (array_key_exists(5, $pathInfo)) {
$result["extension"] = mb_strtolower($pathInfo[5]);
}
if (array_key_exists(3, $pathInfo)) {
$result["filename"] = $pathInfo[3];
}
}
switch ($option) {
case self::PATHINFO_DIRNAME:
return $result["dirname"];
case self::PATHINFO_BASENAME:
return $result["basename"];
case self::PATHINFO_EXTENSION:
return $result["extension"];
case self::PATHINFO_FILENAME:
return $result["filename"];
default:
return $result;
}
}
public function getDirName(string $filePath)
{
return $this->getPathInfo($filePath, self::PATHINFO_DIRNAME);
}
public function getBaseName(string $filePath)
{
return $this->getPathInfo($filePath, self::PATHINFO_BASENAME);
}
public function getExt(string $filePath)
{
return $this->getPathInfo($filePath, self::PATHINFO_EXTENSION);
}
public function getFileName(string $filePath)
{
return $this->getPathInfo($filePath, self::PATHINFO_FILENAME);
}
public function isDocumentViewable(string $filePath)
{
return $this->getFormatInfo($this->getExt($filePath))->isViewable();
}
public function isDocumentEditable(string $filePath)
{
return $this->getFormatInfo($this->getExt($filePath))->isEditable();
}
public function isDocumentConvertable(string $filePath)
{
return $this->getFormatInfo($this->getExt($filePath))->isAutoConvertable();
}
public function isDocumentFillable(string $filePath)
{
return $this->getFormatInfo($this->getExt($filePath))->isFillable();
}
public function isDocumentReadOnly(string $filePath = "")
{
return false;
}
public function getDocumentAccessRights(string $filePath = "")
{
return true;
}
/**
* Translation key to a supported form
*/
public static function generateRevisionId(string $expectedKey)
{
if (strlen($expectedKey) > 20) {
$expectedKey = crc32($expectedKey);
}
$key = preg_replace("[^0-9-.a-zA-Z_=]", "_", $expectedKey);
$key = substr($key, 0, min(array(strlen($key), 20)));
return $key;
}
}

View File

@@ -0,0 +1,214 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Manager\Document;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
interface DocumentManagerInterface
{
/**
* Generates a unique document identifier used by the service to recognize the document.
*
* @param string $fileId The file ID.
* @param bool $embedded Specifies if the editor is opened in the embedded mode (true) or not (false).
* @throws Exception If the processing fails unexpectedly.
* @return string The unique document identifier.
*/
public function getDocumentKey(string $fileId, bool $embedded);
/**
* Returns the document name by file ID.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return string Document name
*/
public function getDocumentName(string $fileId);
/**
* Returns the locale by lang code
*
* @throws Exception If the processing fails unexpectedly.
* @return string Locale
*/
public static function getLangMapping();
/**
* Returns the URL to download a file with the ID specified in the request.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return string The URL to download a file.
*/
public function getFileUrl(string $fileId);
/**
* Returns the URL to the callback handler.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return string The URL to the callback handler.
*/
public function getCallbackUrl(string $fileId);
/**
* Returns the URL to the location folder of a file with the ID specified in the request.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return string The URL to the file location folder.
*/
public function getGobackUrl(string $fileId);
/**
* Returns the URL to create a new file with the ID specified in the request.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return string The URL to create a new file.
*/
public function getCreateUrl(string $fileId);
/**
* Returns the path of empty file from assets/document-templates by extension.
*
* @param string $fileExt Extension of the file.
* @throws Exception If the processing fails unexpectedly.
* @return string The URL to create a new file.
*/
public function getEmptyTemplate(string $fileExt);
/**
* Returns temporary file info (path and url as array)
*
* @throws Exception If the processing fails unexpectedly.
* @return array Temporary file info.
*/
public function getTempFile();
/**
* Return file type by extension
*
* @param string $extension Extension of the file.
* @throws Exception If the processing fails unexpectedly.
* @return string File type
*/
public function getDocType(string $extension);
/**
* Return actions for file by extension
*
* @param string $extension Extension of the file.
* @throws Exception If the processing fails unexpectedly.
* @return array Actions for file by extension
*/
public function getDocActions(string $extension);
/**
* Return convert extensions for file by current extension
*
* @param string $extension Extension of the file.
* @throws Exception If the processing fails unexpectedly.
* @return array Convert extensions for file by current extension
*/
public function getDocConvert(string $extension);
/**
* Return array of all mime types for file by extension
*
* @param string $extension Extension of the file.
* @throws Exception If the processing fails unexpectedly.
* @return array All mime types for file by extension
*/
public function getDocMimes(string $extension);
/**
* Return one mime type of the file by extension
*
* @param string $extension Extension of the file.
* @throws Exception If the processing fails unexpectedly.
* @return string Mime type of the file by extension
*/
public function getDocMimeType(string $extension);
/**
* Returns the file base name without the full path and extension.
*
* @param string $filePath The file path.
* @return string The file name without the extension or null if the file name is empty.
*/
public function getBaseName(string $filePath);
/**
* Returns the file extension.
*
* @param string $filePath The file path.
* @return string The file extension.
*/
public function getExt(string $filePath);
/**
* Returns the file name.
*
* @param string $filePath The file path.
* @return string The file name.
*/
public function getFileName(string $filePath);
/**
* Determines whether a document with a name specified in the request is viewable.
*
* @param string $filePath The file path.
* @return bool True if the document is viewable.
*/
public function isDocumentViewable(string $filePath);
/**
* Determines whether a document with a name specified in the request is editable.
*
* @param string $filePath The file path.
* @return bool True if the document is editable.
*/
public function isDocumentEditable(string $filePath);
/**
* Determines whether a document with a name specified in the request is convertable.
*
* @param string $filePath The file path.
* @return bool True if the document is convertable.
*/
public function isDocumentConvertable(string $filePath);
/**
* Determines whether a document with a name specified in the request is fillable.
*
* @param string $filePath The file path.
* @return bool True if the document is fillable.
*/
public function isDocumentFillable(string $filePath);
/**
* Translation key to a supported form
*
* @param string $expectedKey The expected key for document.
* @return string Generated key
*/
public static function generateRevisionId(string $expectedKey);
}

View File

@@ -0,0 +1,151 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Manager\Formats;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\CommonError;
use Onlyoffice\DocsIntegrationSdk\Models\Format;
/**
* Document formats manager.
*
* @package Onlyoffice\DocsIntegrationSdk\Manager\Formats
*/
class FormatsManager implements FormatsManagerInterface
{
/**
* List of formats
*
* @var array
*/
protected $formatsList;
public function __construct($nameAssoc = false)
{
$formats = self::getFormats();
if ($nameAssoc === false) {
$this->formatsList = self::buildDefaultFormatsArray($formats);
} else {
$this->formatsList = self::buildNamedFormatsArray($formats);
}
}
protected static function buildDefaultFormatsArray(array $formats)
{
$formatsList = [];
foreach ($formats as $format) {
array_push($formatsList, new Format(
$format->name,
$format->type,
$format->actions,
$format->convert,
$format->mime
));
}
return $formatsList;
}
protected static function buildNamedFormatsArray(array $formats)
{
$formatsList = [];
foreach ($formats as $format) {
$currentFormat = new Format(
$format->name,
$format->type,
$format->actions,
$format->convert,
$format->mime
);
$formatsList[$currentFormat->getName()] = $currentFormat;
}
return $formatsList;
}
private static function getFormats()
{
$formats = file_get_contents(dirname(dirname(dirname(__DIR__))).
DIRECTORY_SEPARATOR.
"resources".
DIRECTORY_SEPARATOR.
"assets".
DIRECTORY_SEPARATOR.
"document-formats".
DIRECTORY_SEPARATOR.
"onlyoffice-docs-formats.json");
if (!empty($formats)) {
$formats = json_decode($formats);
if (!empty($formats)) {
return $formats;
}
throw new \Exception(CommonError::message(CommonError::EMPTY_FORMATS_ASSET));
}
throw new \Exception(CommonError::message(CommonError::EMPTY_FORMATS_ASSET));
}
public function getFormatsList()
{
return $this->formatsList;
}
public function getViewableList()
{
$viewableList = [];
foreach ($this->formatsList as $format) {
if ($format->isViewable()) {
array_push($viewableList, $format);
}
}
return $viewableList;
}
public function getEditableList()
{
$editableList = [];
foreach ($this->formatsList as $format) {
if ($format->isEditable()) {
array_push($editableList, $format);
}
}
return $editableList;
}
public function getConvertableList()
{
$convertableList = [];
foreach ($this->formatsList as $format) {
if ($format->isAutoConvertable()) {
array_push($convertableList, $format);
}
}
return $convertableList;
}
public function getFillableList()
{
$fillableList = [];
foreach ($this->formatsList as $format) {
if ($format->isFillable()) {
array_push($fillableList, $format);
}
}
return $fillableList;
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Manager\Formats;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Interface Formats.
*
* @package Onlyoffice\DocsIntegrationSdk\Manager\Formats
*/
interface FormatsManagerInterface
{
/**
* Returns the list of all formats.
*
* @return array List of all formats
*/
public function getFormatsList();
/**
* Returns the list of viewable formats.
*
* @return array List of viewable formats
*/
public function getViewableList();
/**
* Returns the list of editable formats.
*
* @return array List of editable formats
*/
public function getEditableList();
/**
* Returns the list of convertable formats.
*
* @return array List of convertable formats
*/
public function getConvertableList();
/**
* Returns the list of fillable formats.
*
* @return array List of fillable formats
*/
public function getFillableList();
}

View File

@@ -0,0 +1,109 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Manager\Security;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Manager\Settings\SettingsManager;
use Onlyoffice\DocsIntegrationSdk\Manager\Security\JwtManagerInterface;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
/**
* Default JWT Manager.
*
* @package Onlyoffice\DocsIntegrationSdk\Manager\Security
*/
abstract class JwtManager implements JwtManagerInterface
{
private SettingsManager $settingsManager;
public function __construct(SettingsManager $settingsManager)
{
$this->settingsManager = $settingsManager;
}
abstract public function encode($payload, $key, $algorithm = "HS256");
abstract public function decode($token, $key, $algorithm = "HS256");
/**
* Check if a secret key to generate token exists or not.
*
* @return bool
*/
public function isJwtEnabled()
{
return !empty($this->settingsManager->getJwtKey());
}
/**
* Encode a payload object into a token using a secret key
*
* @param array $payload
*
* @return string
*/
public function jwtEncode($payload, $key = null)
{
if (empty($key)) {
$key = $this->settingsManager->getJwtKey();
}
return $this->encode($payload, $key);
}
/**
* Decode a token into a payload object using a secret key
*
* @param string $token
*
* @return string
*/
public function jwtDecode($token)
{
try {
$payload = $this->decode($token, $this->settingsManager->getJwtKey());
} catch (\UnexpectedValueException $e) {
$payload = "";
}
return $payload;
}
/**
* Create an object from the token
*
* @param string $token - token
*
* @return array
*/
public function readHash($token, $securityKey)
{
$result = null;
$error = null;
if ($token === null) {
return [$result, "Token is empty"];
}
try {
$result = $this->decode($token, $securityKey);
} catch (\UnexpectedValueException $e) {
$error = $e->getMessage();
}
return [$result, $error];
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Manager\Security;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Interface JwtManager.
*
* @package Onlyoffice\DocsIntegrationSdk\Manager\Security
*/
interface JwtManagerInterface
{
/**
* Checks is JWT enabled or not.
*
* @throws Exception If the processing fails unexpectedly.
* @return bool True if JWT is enabled.
*/
public function isJwtEnabled();
/**
* Encode a payload object into a token using a secret key
*
* @param array $payload
* @param string $key
*
* @return string
*/
public function jwtEncode($payload, $key);
/**
* Create an object from the token
*
* @param string $token
* @param string $securityKey
*
* @return array
*/
public function readHash($token, $securityKey);
}

View File

@@ -0,0 +1,435 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Manager\Settings;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Manager\Settings\SettingsManagerInterface;
use Onlyoffice\DocsIntegrationSdk\Util\EnvUtil;
use Dotenv\Dotenv;
/**
* Default Settings Manager.
*
* @package Onlyoffice\DocsIntegrationSdk\Manager\Settings
*/
abstract class SettingsManager implements SettingsManagerInterface
{
abstract public function getServerUrl();
abstract public function getSetting($settingName);
abstract public function setSetting($settingName, $value, $createSetting = false);
/**
* The settings key for the demo server
*
* @var string
*/
protected $useDemoName = "demo";
/**
* The settings key for the document server address
*
* @var string
*/
protected $documentServerUrl = "documentServerUrl";
/**
* The config key for the document server address available from storage
*
* @var string
*/
protected $documentServerInternalUrl = "documentServerInternalUrl";
/**
* The config key for the storage url
*
* @var string
*/
protected $storageUrl = "storageUrl";
/**
* The config key for JWT header
*
* @var string
*/
protected $jwtHeader = "jwtHeader";
/**
* The config key for JWT secret key
*
* @var string
*/
protected $jwtKey = "jwtKey";
/**
* The config key for JWT prefix
*
* @var string
*/
protected $jwtPrefix = "jwtPrefix";
/**
* The config key for JWT leeway
*
* @var string
*/
protected $jwtLeeway = "jwtLeeway";
/**
* The config key for HTTP ignore SSL setting
*
* @var string
*/
protected $httpIgnoreSSL = "ignoreSSL";
/** The demo url. */
protected const DEMO_URL = "https://onlinedocs.docs.onlyoffice.com/";
/** The demo security header. */
protected const DEMO_JWT_HEADER = "AuthorizationJWT";
/** The demo security key. */
protected const DEMO_JWT_KEY = "sn2puSUF7muF5Jas";
/** The demo security prefix. */
protected const DEMO_JWT_PREFIX = "Bearer ";
/** The number of days that the demo server can be used. */
protected const DEMO_TRIAL_PERIOD = 30;
protected const ENV_SETTINGS_PREFIX = "DOCS_INTEGRATION_SDK";
public function __construct()
{
EnvUtil::loadEnvSettings();
}
/**
* Get status of demo server
*
* @return bool
*/
public function useDemo()
{
return $this->getDemoData()["enabled"] === true;
}
/**
* Get demo data
*
* @return array
*/
public function getDemoData()
{
$data = $this->getSetting($this->useDemoName);
if (empty($data)) {
$data = [
"available" => true,
"enabled" => false
];
$this->setSetting($this->useDemoName, json_encode($data), true);
return $data;
}
$data = json_decode($data, true);
if (isset($data['start'])) {
$overdue = $data["start"];
$overdue += 24 * 60 * 60 *$this->getDemoParams()["TRIAL"];
if ($overdue > time()) {
$data["available"] = true;
$data["enabled"] = $data["enabled"] === true;
} else {
$data["available"] = false;
$data["enabled"] = false;
$this->setSetting($this->useDemoName, json_encode($data));
}
}
return $data;
}
/**
* Switch on demo server
*
* @param bool $value - select demo
*
* @return bool
*/
public function selectDemo($value)
{
$data = $this->getDemoData();
if ($value === true && !$data["available"]) {
return false;
}
$data["enabled"] = $value === true;
if (!isset($data["start"])) {
$data["start"] = time();
}
$this->setSetting($this->useDemoName, json_encode($data));
return true;
}
private function getBaseSettingValue(string $settingKey, string $envKey, string $demoKey = "")
{
if ($this->useDemo() && !empty($demoKey)) {
return $demoKey;
}
$settingValue = $this->getSetting($settingKey);
if (empty($settingValue) && !empty($_ENV[$envKey])) {
$settingValue = $_ENV[$envKey];
}
return $settingValue;
}
/**
* Get the document service address from the application configuration
*
* @return string
*/
public function getDocumentServerUrl()
{
$url = $this->getBaseSettingValue(
$this->documentServerUrl,
EnvUtil::envKey("DOCUMENT_SERVER_URL"),
self::DEMO_URL
);
$url = !empty($url) ? $this->normalizeUrl($url) : "";
return (string)$url;
}
public function getDocumentServerInternalUrl()
{
if ($this->useDemo()) {
return $this->getDocumentServerUrl();
}
$url = $this->getSetting($this->documentServerInternalUrl);
if (empty($url)) {
return $this->getDocumentServerUrl();
}
return (string)$url;
}
public function getStorageUrl()
{
$url = $this->getSetting($this->storageUrl);
return !empty($url) ? $url : "";
}
/**
* Replace domain in document server url with internal address from configuration
*
* @param string $url - document server url
*
* @return string
*/
public function replaceDocumentServerUrlToInternal($url)
{
$documentServerUrl = $this->getDocumentServerInternalUrl();
if (!empty($documentServerUrl)) {
$from = $this->getDocumentServerUrl();
if (!preg_match("/^https?:\/\//i", $from)) {
$parsedUrl = parse_url($url);
$from = $parsedUrl["scheme"].
"://".
$parsedUrl["host"].
(array_key_exists("port", $parsedUrl) ? (":" . $parsedUrl["port"]) : "") . $from;
}
$url = $from !== $documentServerUrl ?? str_replace($from, $documentServerUrl, $url);
}
return $url;
}
private function getDocumentServerCustomUrl($settingKey, $useInternalUrl = false)
{
if (!$useInternalUrl) {
$serverUrl = $this->getDocumentServerUrl();
} else {
$serverUrl = $this->getDocumentServerInternalUrl();
}
$customUrl = "";
if (!empty($serverUrl) && !empty($_ENV[EnvUtil::envKey($settingKey)])) {
$customUrl = $_ENV[EnvUtil::envKey($settingKey)];
$customUrl = $this->normalizeUrl($serverUrl .= $customUrl);
}
return (string)$customUrl;
}
/**
* Get the document server API URL
*
* @return string
*/
public function getDocumentServerApiUrl($useInternalUrl = false)
{
return $this->getDocumentServerCustomUrl("DOCUMENT_SERVER_API_URL", $useInternalUrl) ?:
$this->normalizeUrl($this->getDocumentServerUrl()."/web-apps/apps/api/documents/api.js");
}
/**
* Get the document server preloader url
*
* @return string
*/
public function getDocumentServerPreloaderUrl($useInternalUrl = false)
{
return $this->getDocumentServerCustomUrl("DOCUMENT_SERVER_API_PRELOADER_URL", $useInternalUrl) ?:
$this->normalizeUrl($this->getDocumentServerUrl()."/web-apps/apps/api/documents/cache-scripts.html");
}
/**
* Get the document server healthcheck url
*
* @return string
*/
public function getDocumentServerHealthcheckUrl($useInternalUrl = false)
{
return $this->getDocumentServerCustomUrl("DOCUMENT_SERVER_HEALTHCHECK_URL", $useInternalUrl) ?:
$this->normalizeUrl($this->getDocumentServerUrl()."/healthcheck");
}
/**
* Get the convert service url
*
* @return string
*/
public function getConvertServiceUrl($useInternalUrl = false)
{
return $this->getDocumentServerCustomUrl("CONVERT_SERVICE_URL", $useInternalUrl) ?:
$this->normalizeUrl($this->getDocumentServerUrl()."/ConvertService.ashx");
}
/**
* Get the command service url
*
* @return string
*/
public function getCommandServiceUrl($useInternalUrl = false)
{
return $this->getDocumentServerCustomUrl("COMMAND_SERVICE_URL", $useInternalUrl) ?:
$this->normalizeUrl($this->getDocumentServerUrl()."/coauthoring/CommandService.ashx");
}
/**
* Get the JWT Header
*
* @return string
*/
public function getJwtHeader()
{
$jwtHeader = $this->getBaseSettingValue($this->jwtHeader, EnvUtil::envKey("JWT_HEADER"), self::DEMO_JWT_HEADER);
return (string)$jwtHeader;
}
/**
* Get the JWT secret
*
* @return string
*/
public function getJwtKey()
{
$jwtKey = $this->getBaseSettingValue($this->jwtKey, EnvUtil::envKey("JWT_KEY"), self::DEMO_JWT_KEY);
return (string)$jwtKey;
}
/**
* Get the JWT prefix
*
* @return string
*/
public function getJwtPrefix()
{
$jwtPrefix = $this->getBaseSettingValue($this->jwtPrefix, EnvUtil::envKey("JWT_PREFIX"), self::DEMO_JWT_PREFIX);
return (string)$jwtPrefix;
}
/**
* Get the JWT leeway
*
* @return string
*/
public function getJwtLeeway()
{
$jwtLeeway = $this->getBaseSettingValue($this->jwtLeeway, EnvUtil::envKey("JWT_LEEWAY"));
return (string)$jwtLeeway;
}
/**
* Get the ignore SSL value
*
* @return bool
*/
public function isIgnoreSSL()
{
if (!$this->useDemo()) {
return boolval($this->getBaseSettingValue($this->httpIgnoreSSL, EnvUtil::envKey("HTTP_IGNORE_SSL")))
=== true;
}
return false;
}
/**
* Get demo params
*
* @return array
*/
public function getDemoParams()
{
return [
"ADDR" => self::DEMO_URL,
"HEADER" => self::DEMO_JWT_HEADER,
"SECRET" => self::DEMO_JWT_KEY,
"PREFIX" => self::DEMO_JWT_PREFIX,
"TRIAL" => self::DEMO_TRIAL_PERIOD
];
}
/**
* Add backslash to url if it's needed
*
* @return string
*/
public function processUrl($url)
{
if ($url !== null && $url !== "/") {
$url = rtrim($url, "/");
if (strlen($url) > 0) {
$url = $url . "/";
}
}
return $url;
}
public function normalizeUrl($url)
{
$url = preg_replace('/([^:])(\/{2,})/', '$1/', $url);
$url = filter_var($url, FILTER_SANITIZE_URL);
return $url;
}
}

View File

@@ -0,0 +1,150 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Manager\Settings;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Interface Settings Manager.
*
* @package Onlyoffice\DocsIntegrationSdk\Manager\Settings
*/
interface SettingsManagerInterface
{
/**
* Get the setting value by setting name.
*
* @param string $settingName Name of setting.
* @throws Exception If the processing fails unexpectedly.
*/
public function getSetting($settingName);
/**
* Set the setting value.
*
* @param string $settingName Name of setting.
* @param $value Value of setting.
* @param bool $createSetting If True, then create a new setting with the value.
* @throws Exception If the processing fails unexpectedly.
*/
public function setSetting($settingName, $value, $createSetting);
/**
* Get status of demo server
*
* @return bool
*/
public function useDemo();
/**
* Get the data for demo connection
*
* @return array
*/
public function getDemoData();
/**
* Switch on demo server
*
* @param bool $value - select demo
*
* @return bool
*/
public function selectDemo($value);
/**
* Get the document service address from the application configuration
*
* @return string
*/
public function getDocumentServerUrl();
/**
* Get the document server API URL from the application configuration
*
* @return string
*/
public function getDocumentServerApiUrl();
/**
* Get the preloader URL from the application configuration
*
* @return string
*/
public function getDocumentServerPreloaderUrl();
/**
* Get the healthcheck URL from the application configuration
*
* @return string
*/
public function getDocumentServerHealthcheckUrl();
/**
* Get the convert service URL from the application configuration
*
* @return string
*/
public function getConvertServiceUrl();
/**
* Get the command service URL from the application configuration
*
* @return string
*/
public function getCommandServiceUrl();
/**
* Get the JWT Header
*
* @return string
*/
public function getJwtHeader();
/**
* Get the JWT Key
*
* @return string
*/
public function getJwtKey();
/**
* Get the JWT prefix
*
* @return string
*/
public function getJwtPrefix();
/**
* Get the JWT Leeway
*
* @return string
*/
public function getJwtLeeway();
/**
* Checks whether the setting to ignore SSL certificate is enabled.
*
* @return bool True if the setting to ignore SSL certificate is enabled.
*/
public function isIgnoreSSL();
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class Anonymous extends JsonSerializable
{
protected $request;
protected $label;
public function __construct(bool $request = true, string $label = "Guest")
{
$this->request = $request;
$this->label = $label;
}
/**
* Get the value of request
*/
public function getRequest()
{
return $this->request;
}
/**
* Set the value of request
*/
public function setRequest($request)
{
$this->request = $request;
}
/**
* Get the value of label
*/
public function getLabel()
{
return $this->label;
}
/**
* Set the value of label
*/
public function setLabel($label)
{
$this->label = $label;
}
}

View File

@@ -0,0 +1,223 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\CallbackAction;
use Onlyoffice\DocsIntegrationSdk\Models\CallbackForceSaveType;
use Onlyoffice\DocsIntegrationSdk\Models\CallbackDocStatus;
use Onlyoffice\DocsIntegrationSdk\Models\History;
class Callback extends JsonSerializable
{
protected $actions; //array of CallbackAction
protected $changesurl;
protected $fileType;
protected $forceSaveType;
protected $history;
protected $key;
protected $status;
protected $url;
protected $users;
protected $token;
public function __construct(
array $actions = [],
string $changesurl = "",
string $fileType = "",
CallbackForceSaveType $forceSaveType = null,
History $history = null,
string $key = "",
CallbackDocStatus $status = null,
string $url = "",
array $users = [],
string $token = ""
) {
$this->actions = $actions;
$this->changesurl = $changesurl;
$this->fileType = $fileType;
$this->forceSaveType = $forceSaveType !== null ? $forceSaveType : new CallbackForceSaveType;
$this->history = $history !== null ? $history : new History;
$this->key = $key;
$this->status = $status !== null ? $status : new CallbackDocStatus;
$this->url = $url;
$this->users = $users;
$this->token = $token;
}
/**
* Get the value of actions
*/
public function getActions()
{
return $this->actions;
}
/**
* Set the value of actions
*/
public function setActions($actions)
{
$this->actions = $actions;
}
/**
* Get the value of changesurl
*/
public function getChangesurl()
{
return $this->changesurl;
}
/**
* Set the value of changesurl
*/
public function setChangesurl($changesurl)
{
$this->changesurl = $changesurl;
}
/**
* Get the value of fileType
*/
public function getFileType()
{
return $this->fileType;
}
/**
* Set the value of fileType
*/
public function setFileType($fileType)
{
$this->fileType = $fileType;
}
/**
* Get the value of forceSaveType
*/
public function getForceSaveType()
{
return $this->forceSaveType;
}
/**
* Set the value of forceSaveType
*/
public function setForceSaveType($forceSaveType)
{
$this->forceSaveType = $forceSaveType;
}
/**
* Get the value of history
*/
public function getHistory()
{
return $this->history;
}
/**
* Set the value of history
*/
public function setHistory($history)
{
$this->history = $history;
}
/**
* Get the value of key
*/
public function getKey()
{
return $this->key;
}
/**
* Set the value of key
*/
public function setKey($key)
{
$this->key = $key;
}
/**
* Get the value of status
*/
public function getStatus()
{
return $this->status;
}
/**
* Set the value of status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* Get the value of url
*/
public function getUrl()
{
return $this->url;
}
/**
* Set the value of url
*/
public function setUrl($url)
{
$this->url = $url;
}
/**
* Get the value of users
*/
public function getUsers()
{
return $this->users;
}
/**
* Set the value of users
*/
public function setUsers($users)
{
$this->users = $users;
}
/**
* Get the value of token
*/
public function getToken()
{
return $this->token;
}
/**
* Set the value of token
*/
public function setToken($token)
{
$this->token = $token;
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\CallbackActionType;
class CallbackAction extends JsonSerializable
{
protected $type;
protected $userId;
public function __construct(CallbackActionType $type = null, string $userId = "")
{
$this->type = $type !== null ? $type : new CallbackActionType;
$this->userId = $userId;
}
/**
* Get the value of type
*/
public function getType()
{
return $this->type;
}
/**
* Set the value of type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* Get the value of userId
*/
public function getUserId()
{
return $this->userId;
}
/**
* Set the value of userId
*/
public function setUserId($userId)
{
$this->userId = $userId;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class CallbackActionType extends BasicEnum
{
const DISCONNECTED = 0;
const CONNECTED = 1;
const CLICK_FORCESAVE = 2;
public function __construct($type = null)
{
if (!self::isValidValue($type) && $type !== null) {
throw new \Exception("Unknown callback action type");
} else {
$this->value = $type;
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class CallbackDocStatus extends BasicEnum
{
const EDITING = 1;
const SAVE = 2;
const SAVE_CORRUPTED = 3;
const CLOSED = 4;
const FORCESAVE = 6;
const FORCESAVE_CORRUPTED = 7;
public function __construct($status = null)
{
if (!self::isValidValue($status) && $status !== null) {
throw new \Exception("Unknown callback document status");
} else {
$this->value= $status;
}
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class CallbackForceSaveType extends BasicEnum
{
const COMMAND_SERVICE = 0;
const SAVE_BUTTON = 1;
const TIMER = 2;
public function __construct($type = null)
{
if (!self::isValidValue($type) && $type !== null) {
throw new \Exception("Unknown callback forcesave type");
} else {
$this->value = $type;
}
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\User;
class Changes extends JsonSerializable
{
protected $created;
protected $user;
public function __construct(string $created = "", User $user = null)
{
$this->created = $created;
$this->user = $histuserory !== null ? $user : new User;
}
/**
* Get the value of created
*/
public function getCreated()
{
return $this->created;
}
/**
* Set the value of created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* Get the value of user
*/
public function getUser()
{
return $this->user;
}
/**
* Set the value of user
*/
public function setUser($user)
{
$this->user = $user;
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\CoEditingMode;
class CoEditing extends JsonSerializable
{
protected $mode;
protected $change;
public function __construct(CoEditingMode $mode = null, bool $change = true)
{
$this->mode = $mode !== null ? $mode : new CoEditingMode;
$this->change = $change;
}
/**
* Get the value of mode
*/
public function getMode()
{
return $this->mode;
}
/**
* Set the value of mode
*/
public function setMode($mode)
{
$this->mode = $mode;
}
/**
* Get the value of change
*/
public function getChange()
{
return $this->change;
}
/**
* Set the value of change
*/
public function setChange($change)
{
$this->change = $change;
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class CoEditingMode extends BasicEnum
{
const FAST = "fast";
const STRICT = "strict";
public function __construct($mode = null)
{
if (!self::isValidValue($mode) && $mode !== null) {
throw new \Exception("Unknown co-editing mode");
} else {
$this->value = $mode !== null ? $mode : self::FAST;
}
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class CommentGroups extends JsonSerializable
{
protected $edit;
protected $remove;
protected $view;
public function __construct(array $edit = [], array $remove = [], array $view = [])
{
$this->edit = $edit;
$this->remove = $remove;
$this->view = $view;
}
/**
* Get the value of edit
*/
public function getEdit()
{
return $this->edit;
}
/**
* Set the value of edit
*/
public function setEdit($edit)
{
$this->edit = $edit;
}
/**
* Get the value of remove
*/
public function getRemove()
{
return $this->remove;
}
/**
* Set the value of remove
*/
public function setRemove($remove)
{
$this->remove = $remove;
}
/**
* Get the value of view
*/
public function getView()
{
return $this->view;
}
/**
* Set the value of view
*/
public function setView($view)
{
$this->view = $view;
}
}

View File

@@ -0,0 +1,168 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\DocumentType;
use Onlyoffice\DocsIntegrationSdk\Models\DocEditorConfig;
use Onlyoffice\DocsIntegrationSdk\Models\Document;
use Onlyoffice\DocsIntegrationSdk\Models\Type;
class Config extends JsonSerializable
{
protected $documentType;
protected $height;
protected $width;
protected $token;
protected $type;
protected $editorConfig;
protected $document;
public function __construct(
DocumentType $documentType,
string $height,
string $width,
string $token,
Type $type,
DocEditorConfig $editorConfig,
Document $document
) {
$this->documentType = $documentType;
$this->height = $height;
$this->width = $width;
$this->token = $token;
$this->type = $type;
$this->editorConfig = $editorConfig;
$this->document = $document;
}
/**
* Get the value of documentType
*/
public function getDocumentType()
{
return $this->documentType;
}
/**
* Set the value of documentType
*/
public function setDocumentType($documentType)
{
$this->documentType = $documentType;
}
/**
* Get the value of height
*/
public function getHeight()
{
return $this->height;
}
/**
* Set the value of height
*/
public function setHeight($height)
{
$this->height = $height;
}
/**
* Get the value of width
*/
public function getWidth()
{
return $this->width;
}
/**
* Set the value of width
*/
public function setWidth($width)
{
$this->width = $width;
}
/**
* Get the value of token
*/
public function getToken()
{
return $this->token;
}
/**
* Set the value of token
*/
public function setToken($token)
{
$this->token = $token;
}
/**
* Get the value of type
*/
public function getType()
{
return $this->type;
}
/**
* Set the value of type
*/
public function setType($type)
{
$this->type = $type;
}
/**
* Get the value of editorConfig
*/
public function getEditorConfig()
{
return $this->editorConfig;
}
/**
* Set the value of editorConfig
*/
public function setEditorConfig($editorConfig)
{
$this->editorConfig = $editorConfig;
}
/**
* Get the value of document
*/
public function getDocument()
{
return $this->document;
}
/**
* Set the value of document
*/
public function setDocument($document)
{
$this->document = $document;
}
}

View File

@@ -0,0 +1,258 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\ConvertRequestThumbnail;
class ConvertRequest extends JsonSerializable
{
protected $async;
protected $codePage;
protected $delimiter;
protected $filetype;
protected $key;
protected $outputtype;
protected $password;
protected $region;
protected $thumbnail;
protected $title;
protected $token;
protected $url;
public function __construct(
bool $async = false,
int $codepage = 65001,
int $delimiter = 0,
string $filetype = "",
string $key = "",
string $outputtype = "",
string $password = "",
string $region = "",
?ConvertRequestThumbnail $thumbnail = null,
string $title = "",
string $token = "",
string $url = ""
) {
$this->async = $async;
$this->codePage = $codePage;
$this->delimiter = $delimiter;
$this->filetype = $filetype;
$this->key = $key;
$this->outputtype = $outputtype;
$this->password = $password;
$this->region = $region;
$this->thumbnail = $thumbnail !== null ? $thumbnail : new ConvertRequestThumbnail;
$this->title = $title;
$this->token = $token;
$this->url = $url;
}
/**
* Get the value of async
*/
public function getAsync()
{
return $this->async;
}
/**
* Set the value of async
*/
public function setAsync($async)
{
$this->async = $async;
}
/**
* Get the value of codePage
*/
public function getCodePage()
{
return $this->codePage;
}
/**
* Set the value of codePage
*/
public function setCodePage($codePage)
{
$this->codePage = $codePage;
}
/**
* Get the value of delimiter
*/
public function getDelimiter()
{
return $this->delimiter;
}
/**
* Set the value of delimiter
*/
public function setDelimiter($delimiter)
{
$this->delimiter = $delimiter;
}
/**
* Get the value of filetype
*/
public function getFiletype()
{
return $this->filetype;
}
/**
* Set the value of filetype
*/
public function setFiletype($filetype)
{
$this->filetype = $filetype;
}
/**
* Get the value of key
*/
public function getKey()
{
return $this->key;
}
/**
* Set the value of key
*/
public function setKey($key)
{
$this->key = $key;
}
/**
* Get the value of outputtype
*/
public function getOutputtype()
{
return $this->outputtype;
}
/**
* Set the value of outputtype
*/
public function setOutputtype($outputtype)
{
$this->outputtype = $outputtype;
}
/**
* Get the value of password
*/
public function getPassword()
{
return $this->password;
}
/**
* Set the value of password
*/
public function setPassword($password)
{
$this->password = $password;
}
/**
* Get the value of region
*/
public function getRegion()
{
return $this->region;
}
/**
* Set the value of region
*/
public function setRegion($region)
{
$this->region = $region;
}
/**
* Get the value of thumbnail
*/
public function getThumbnail()
{
return $this->thumbnail;
}
/**
* Set the value of thumbnail
*/
public function setThumbnail($thumbnail)
{
$this->thumbnail = $thumbnail;
}
/**
* Get the value of title
*/
public function getTitle()
{
return $this->title;
}
/**
* Set the value of title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get the value of token
*/
public function getToken()
{
return $this->token;
}
/**
* Set the value of token
*/
public function setToken($token)
{
$this->token = $token;
}
/**
* Get the value of url
*/
public function getUrl()
{
return $this->url;
}
/**
* Set the value of url
*/
public function setUrl($url)
{
$this->url = $url;
}
}

View File

@@ -0,0 +1,103 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class ConvertRequestThumbnail extends JsonSerializable
{
protected $aspect;
protected $first;
protected $height;
protected $width;
public function __construct(int $aspect = 2, bool $first = true, int $height = 100, int $width = 100)
{
$this->aspect = $aspect;
$this->first = $first;
$this->height = $height;
$this->width = $width;
}
/**
* Get the value of aspect
*/
public function getAspect()
{
return $this->aspect;
}
/**
* Set the value of aspect
*/
public function setAspect($aspect)
{
$this->aspect = $aspect;
}
/**
* Get the value of first
*/
public function getFirst()
{
return $this->first;
}
/**
* Set the value of first
*/
public function setFirst($first)
{
$this->first = $first;
}
/**
* Get the value of height
*/
public function getHeight()
{
return $this->height;
}
/**
* Set the value of height
*/
public function setHeight($height)
{
$this->height = $height;
}
/**
* Get the value of width
*/
public function getWidth()
{
return $this->width;
}
/**
* Set the value of width
*/
public function setWidth($width)
{
$this->width = $width;
}
}

View File

@@ -0,0 +1,181 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class Customer extends JsonSerializable
{
protected $address;
protected $info;
protected $logo;
protected $logoDark;
protected $mail;
protected $name;
protected $phone;
protected $www;
public function __construct(
string $address = "",
string $info = "",
string $logo = "",
string $logoDark = "",
string $mail = "",
string $name = "",
string $phone = "",
string $www = ""
) {
$this->address = $address;
$this->info = $info;
$this->logo = $logo;
$this->logoDark = $logoDark;
$this->mail = $mail;
$this->name = $name;
$this->phone = $phone;
$this->www = $www;
}
/**
* Get the value of address
*/
public function getAddress()
{
return $this->address;
}
/**
* Set the value of address
*/
public function setAddress($address)
{
$this->address = $address;
}
/**
* Get the value of info
*/
public function getInfo()
{
return $this->info;
}
/**
* Set the value of info
*/
public function setInfo($info)
{
$this->info = $info;
}
/**
* Get the value of logo
*/
public function getLogo()
{
return $this->logo;
}
/**
* Set the value of logo
*/
public function setLogo($logo)
{
$this->logo = $logo;
}
/**
* Get the value of logoDark
*/
public function getLogoDark()
{
return $this->logoDark;
}
/**
* Set the value of logoDark
*/
public function setLogoDark($logoDark)
{
$this->logoDark = $logoDark;
}
/**
* Get the value of mail
*/
public function getMail()
{
return $this->mail;
}
/**
* Set the value of mail
*/
public function setMail($mail)
{
$this->mail = $mail;
}
/**
* Get the value of name
*/
public function getName()
{
return $this->name;
}
/**
* Set the value of name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get the value of phone
*/
public function getPhone()
{
return $this->phone;
}
/**
* Set the value of phone
*/
public function setPhone($phone)
{
$this->phone = $phone;
}
/**
* Get the value of www
*/
public function getWww()
{
return $this->www;
}
/**
* Set the value of www
*/
public function setWww($www)
{
$this->www = $www;
}
}

View File

@@ -0,0 +1,586 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\Anonymous;
use Onlyoffice\DocsIntegrationSdk\Models\Customer;
use Onlyoffice\DocsIntegrationSdk\Models\Features;
use Onlyoffice\DocsIntegrationSdk\Models\Logo;
use Onlyoffice\DocsIntegrationSdk\Models\Review;
use Onlyoffice\DocsIntegrationSdk\Models\Unit;
class Customization extends JsonSerializable
{
protected $anonymous;
protected $autosave;
protected $comments;
protected $compactHeader;
protected $compactToolbar;
protected $compatibleFeatures;
protected $customer;
protected $features;
protected $feedback;
protected $forcesave;
protected $goback;
protected $help;
protected $hideNotes;
protected $hideRightMenu;
protected $hideRulers;
protected $integrationMode;
protected $logo;
protected $macros;
protected $macrosMode;
protected $mentionShare;
protected $mobileForceView;
protected $plugins;
protected $review;
protected $submitForm;
protected $toolbarHideFileName;
protected $toolbarNoTabs;
protected $uiTheme;
protected $unit;
protected $zoom;
public function __construct(
?Anonymous $anonymous = null,
?bool $autosave = null,
?bool $comments = null,
?bool $compactHeader = null,
?bool $compactToolbar = null,
?bool $compatibleFeatures = null,
?Customer $customer = null,
?Features $features = null,
?bool $feedback = null,
?bool $forcesave = null,
?GoBack $goback = null,
?bool $help = true,
?bool $hideNotes = null,
?bool $hideRightMenu = null,
?bool $hideRulers = null,
?string $integrationMode = "embed",
?Logo $logo = null,
?bool $macros = null,
?MacrosMode $macrosMode = null,
?bool $mentionShare = null,
?bool $mobileForceView = null,
?bool $plugins = null,
?Review $review = null,
?bool $submitForm = null,
?bool $toolbarHideFileName = null,
?bool $toolbarNoTabs = null,
?string $uiTheme = "",
?Unit $unit = null,
?int $zoom = 100
) {
$this->anonymous = $anonymous;
$this->autosave = $autosave;
$this->comments = $comments;
$this->compactHeader = $compactHeader;
$this->compactToolbar = $compactToolbar;
$this->compatibleFeatures = $compatibleFeatures;
$this->customer = $customer;
$this->features = $features;
$this->feedback = $feedback;
$this->forcesave = $forcesave;
$this->goback = $goback;
$this->help = $help;
$this->hideNotes = $hideNotes;
$this->hideRightMenu = $hideRightMenu;
$this->hideRulers = $hideRulers;
$this->integrationMode = $integrationMode;
$this->logo = $logo;
$this->macros = $macros;
$this->macrosMode = $macrosMode;
$this->mentionShare = $mentionShare;
$this->mobileForceView = $mobileForceView;
$this->plugins = $plugins;
$this->review = $review;
$this->submitForm = $submitForm;
$this->toolbarHideFileName = $toolbarHideFileName;
$this->toolbarNoTabs = $toolbarNoTabs;
$this->uiTheme = $uiTheme;
$this->unit = $unit;
$this->zoom = $zoom;
}
/**
* Get the value of anonymous
*/
public function getAnonymous()
{
return $this->anonymous;
}
/**
* Set the value of anonymous
*/
public function setAnonymous($anonymous)
{
$this->anonymous = $anonymous;
}
/**
* Get the value of autosave
*/
public function getAutosave()
{
return $this->autosave;
}
/**
* Set the value of autosave
*/
public function setAutosave($autosave)
{
$this->autosave = $autosave;
}
/**
* Get the value of comments
*/
public function getComments()
{
return $this->comments;
}
/**
* Set the value of comments
*/
public function setComments($comments)
{
$this->comments = $comments;
}
/**
* Get the value of compactHeader
*/
public function getCompactHeader()
{
return $this->compactHeader;
}
/**
* Set the value of compactHeader
*/
public function setCompactHeader($compactHeader)
{
$this->compactHeader = $compactHeader;
}
/**
* Get the value of compactToolbar
*/
public function getCompactToolbar()
{
return $this->compactToolbar;
}
/**
* Set the value of compactToolbar
*/
public function setCompactToolbar($compactToolbar)
{
$this->compactToolbar = $compactToolbar;
}
/**
* Get the value of compatibleFeatures
*/
public function getCompatibleFeatures()
{
return $this->compatibleFeatures;
}
/**
* Set the value of compatibleFeatures
*/
public function setCompatibleFeatures($compatibleFeatures)
{
$this->compatibleFeatures = $compatibleFeatures;
}
/**
* Get the value of customer
*/
public function getCustomer()
{
return $this->customer;
}
/**
* Set the value of customer
*/
public function setCustomer($customer)
{
$this->customer = $customer;
}
/**
* Get the value of features
*/
public function getFeatures()
{
return $this->features;
}
/**
* Set the value of features
*/
public function setFeatures($features)
{
$this->features = $features;
}
/**
* Get the value of feedback
*/
public function getFeedback()
{
return $this->feedback;
}
/**
* Set the value of feedback
*/
public function setFeedback($feedback)
{
$this->feedback = $feedback;
}
/**
* Get the value of forcesave
*/
public function getForcesave()
{
return $this->forcesave;
}
/**
* Set the value of forcesave
*/
public function setForcesave($forcesave)
{
$this->forcesave = $forcesave;
}
/**
* Get the value of goback
*/
public function getGoback()
{
return $this->goback;
}
/**
* Set the value of goback
*/
public function setGoback($goback)
{
$this->goback = $goback;
}
/**
* Get the value of help
*/
public function getHelp()
{
return $this->help;
}
/**
* Set the value of help
*/
public function setHelp($help)
{
$this->help = $help;
}
/**
* Get the value of hideNotes
*/
public function getHideNotes()
{
return $this->hideNotes;
}
/**
* Set the value of hideNotes
*/
public function setHideNotes($hideNotes)
{
$this->hideNotes = $hideNotes;
}
/**
* Get the value of hideRightMenu
*/
public function getHideRightMenu()
{
return $this->hideRightMenu;
}
/**
* Set the value of hideRightMenu
*/
public function setHideRightMenu($hideRightMenu)
{
$this->hideRightMenu = $hideRightMenu;
}
/**
* Get the value of hideRulers
*/
public function getHideRulers()
{
return $this->hideRulers;
}
/**
* Set the value of hideRulers
*/
public function setHideRulers($hideRulers)
{
$this->hideRulers = $hideRulers;
}
/**
* Get the value of integrationMode
*/
public function getIntegrationMode()
{
return $this->integrationMode;
}
/**
* Set the value of integrationMode
*/
public function setIntegrationMode($integrationMode)
{
$this->integrationMode = $integrationMode;
}
/**
* Get the value of logo
*/
public function getLogo()
{
return $this->logo;
}
/**
* Set the value of logo
*/
public function setLogo($logo)
{
$this->logo = $logo;
}
/**
* Get the value of macros
*/
public function getMacros()
{
return $this->macros;
}
/**
* Set the value of macros
*/
public function setMacros($macros)
{
$this->macros = $macros;
}
/**
* Get the value of macrosMode
*/
public function getMacrosMode()
{
return $this->macrosMode;
}
/**
* Set the value of macrosMode
*/
public function setMacrosMode($macrosMode)
{
$this->macrosMode = $macrosMode;
}
/**
* Get the value of mentionShare
*/
public function getMentionShare()
{
return $this->mentionShare;
}
/**
* Set the value of mentionShare
*/
public function setMentionShare($mentionShare)
{
$this->mentionShare = $mentionShare;
}
/**
* Get the value of mobileForceView
*/
public function getMobileForceView()
{
return $this->mobileForceView;
}
/**
* Set the value of mobileForceView
*/
public function setMobileForceView($mobileForceView)
{
$this->mobileForceView = $mobileForceView;
}
/**
* Get the value of plugins
*/
public function getPlugins()
{
return $this->plugins;
}
/**
* Set the value of plugins
*/
public function setPlugins($plugins)
{
$this->plugins = $plugins;
}
/**
* Get the value of review
*/
public function getReview()
{
return $this->review;
}
/**
* Set the value of review
*/
public function setReview($review)
{
$this->review = $review;
}
/**
* Get the value of submitForm
*/
public function getSubmitForm()
{
return $this->submitForm;
}
/**
* Set the value of submitForm
*/
public function setSubmitForm($submitForm)
{
$this->submitForm = $submitForm;
}
/**
* Get the value of toolbarHideFileName
*/
public function getToolbarHideFileName()
{
return $this->toolbarHideFileName;
}
/**
* Set the value of toolbarHideFileName
*/
public function setToolbarHideFileName($toolbarHideFileName)
{
$this->toolbarHideFileName = $toolbarHideFileName;
}
/**
* Get the value of toolbarNoTabs
*/
public function getToolbarNoTabs()
{
return $this->toolbarNoTabs;
}
/**
* Set the value of toolbarNoTabs
*/
public function setToolbarNoTabs($toolbarNoTabs)
{
$this->toolbarNoTabs = $toolbarNoTabs;
}
/**
* Get the value of uiTheme
*/
public function getUiTheme()
{
return $this->uiTheme;
}
/**
* Set the value of uiTheme
*/
public function setUiTheme($uiTheme)
{
$this->uiTheme = $uiTheme;
}
/**
* Get the value of unit
*/
public function getUnit()
{
return $this->unit;
}
/**
* Set the value of unit
*/
public function setUnit($unit)
{
$this->unit = $unit;
}
/**
* Get the value of zoom
*/
public function getZoom()
{
return $this->zoom;
}
/**
* Set the value of zoom
*/
public function setZoom($zoom)
{
$this->zoom = $zoom;
}
}

View File

@@ -0,0 +1,276 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\CoEditing;
use Onlyoffice\DocsIntegrationSdk\Models\EditorsMode;
use Onlyoffice\DocsIntegrationSdk\Models\Recent;
use Onlyoffice\DocsIntegrationSdk\Models\Template;
use Onlyoffice\DocsIntegrationSdk\Models\User;
use Onlyoffice\DocsIntegrationSdk\Models\Customization;
use Onlyoffice\DocsIntegrationSdk\Models\Embedded;
class DocEditorConfig extends JsonSerializable
{
protected $callbackUrl;
protected $coEditing;
protected $createUrl;
protected $lang;
protected $location;
protected $mode;
protected $recent; // array of Recent
protected $region;
protected $templates; // aray of Template
protected $user;
protected $customization;
protected $embedded;
public function __construct(
?string $callbackUrl = "",
?CoEditing $coEditing = null,
?string $createUrl = "",
?string $lang = "en",
?string $location = "",
?EditorsMode $mode = null,
?array $recent = null,
?string $region = "en-US",
?array $templates = null,
?User $user = null,
?Customization $customization = null,
?Embedded $embedded = null
) {
$this->callbackUrl = $callbackUrl;
$this->coEditing = $coEditing;
$this->createUrl = $createUrl;
$this->lang = $lang;
$this->location = $location;
$this->mode = $mode;
$this->recent = $recent;
$this->region = $region;
$this->templates = $templates;
$this->user = $user;
$this->customization = $customization;
$this->embedded = $embedded;
}
/**
* Get the value of callbackUrl
*/
public function getCallbackUrl()
{
return $this->callbackUrl;
}
/**
* Set the value of callbackUrl
*
*/
public function setCallbackUrl($callbackUrl)
{
$this->callbackUrl = $callbackUrl;
}
/**
* Get the value of coEditing
*/
public function getCoEditing()
{
return $this->coEditing;
}
/**
* Set the value of coEditing
*
*/
public function setCoEditing($coEditing)
{
$this->coEditing = $coEditing;
}
/**
* Get the value of createUrl
*/
public function getCreateUrl()
{
return $this->createUrl;
}
/**
* Set the value of createUrl
*
*/
public function setCreateUrl($createUrl)
{
$this->createUrl = $createUrl;
}
/**
* Get the value of lang
*/
public function getLang()
{
return $this->lang;
}
/**
* Set the value of lang
*
*/
public function setLang($lang)
{
$this->lang = $lang;
}
/**
* Get the value of location
*/
public function getLocation()
{
return $this->location;
}
/**
* Set the value of location
*
*/
public function setLocation($location)
{
$this->location = $location;
}
/**
* Get the value of mode
*/
public function getMode()
{
return $this->mode;
}
/**
* Set the value of mode
*
*/
public function setMode($mode)
{
$this->mode = $mode;
}
/**
* Get the value of recent
*/
public function getRecent()
{
return $this->recent;
}
/**
* Set the value of recent
*
*/
public function setRecent($recent)
{
$this->recent = $recent;
}
/**
* Get the value of region
*/
public function getRegion()
{
return $this->region;
}
/**
* Set the value of region
*
*/
public function setRegion($region)
{
$this->region = $region;
}
/**
* Get the value of templates
*/
public function getTemplates()
{
return $this->templates;
}
/**
* Set the value of templates
*
*/
public function setTemplates($templates)
{
$this->templates = $templates;
}
/**
* Get the value of user
*/
public function getUser()
{
return $this->user;
}
/**
* Set the value of user
*
*/
public function setUser($user)
{
$this->user = $user;
}
/**
* Get the value of customization
*/
public function getCustomization()
{
return $this->customization;
}
/**
* Set the value of customization
*
*/
public function setCustomization($customization)
{
$this->customization = $customization;
}
/**
* Get the value of embedded
*/
public function getEmbedded()
{
return $this->embedded;
}
/**
* Set the value of embedded
*
*/
public function setEmbedded($embedded)
{
$this->embedded = $embedded;
}
}

View File

@@ -0,0 +1,169 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\DocumentType;
use Onlyoffice\DocsIntegrationSdk\Models\ReferenceData;
use Onlyoffice\DocsIntegrationSdk\Models\Info;
use Onlyoffice\DocsIntegrationSdk\Models\Permissions;
class Document extends JsonSerializable
{
protected $fileType;
protected $key;
protected $referenceData;
protected $title;
protected $url;
protected $info;
protected $permissions;
public function __construct(
?string $fileType,
?string $key,
?ReferenceData $referenceData,
?string $title,
?string $url,
?Info $info,
?Permissions $permissions
) {
$this->fileType = $fileType;
$this->key = $key;
$this->referenceData = $referenceData;
$this->title = $title;
$this->url = $url;
$this->info = $info;
$this->permissions = $permissions;
}
/**
* Get the value of fileType
*/
public function getFileType()
{
return $this->fileType;
}
/**
* Set the value of fileType
*/
public function setFileType($fileType)
{
$this->fileType = $fileType;
}
/**
* Get the value of key
*/
public function getKey()
{
return $this->key;
}
/**
* Set the value of key
*/
public function setKey($key)
{
$this->key = $key;
}
/**
* Get the value of referenceData
*/
public function getReferenceData()
{
return $this->referenceData;
}
/**
* Set the value of referenceData
*/
public function setReferenceData($referenceData)
{
$this->referenceData = $referenceData;
}
/**
* Get the value of title
*/
public function getTitle()
{
return $this->title;
}
/**
* Set the value of title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get the value of url
*/
public function getUrl()
{
return $this->url;
}
/**
* Set the value of url
*/
public function setUrl($url)
{
$this->url = $url;
}
/**
* Get the value of info
*/
public function getInfo()
{
return $this->info;
}
/**
* Set the value of info
*/
public function setInfo($info)
{
$this->info = $info;
}
/**
* Get the value of permissions
*/
public function getPermissions()
{
return $this->permissions;
}
/**
* Set the value of permissions
*/
public function setPermissions($permissions)
{
$this->permissions = $permissions;
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class DocumentType extends BasicEnum
{
const WORD = "word";
const CELL = "cell";
const SLIDE = "slide";
const PDF = "pdf";
public function __construct($type = null)
{
if (!self::isValidValue($type) && $type !== null) {
throw new \Exception("Unknown document type");
} else {
$this->value = $type;
}
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class EditorsMode extends BasicEnum
{
const VIEW = "view";
const EDIT = "edit";
public function __construct($editorsMode = null)
{
if (!self::isValidValue($editorsMode) && $editorsMode !== null) {
throw new \Exception("Unknown editors mode");
} else {
$this->value = $editorsMode !== null ? $editorsMode : self::EDIT;
}
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\Toolbar;
class Embedded extends JsonSerializable
{
protected $embedUrl;
protected $fullscreenUrl;
protected $saveUrl;
protected $shareUrl;
protected $toolbarDocked;
public function __construct(
string $embedUrl = "",
string $fullscreenUrl = "",
string $saveUrl = "",
string $shareUrl = "",
Toolbar $toolbarDocked = null
) {
$this->embedUrl = $embedUrl;
$this->fullscreenUrl = $fullscreenUrl;
$this->saveUrl = $saveUrl;
$this->shareUrl = $shareUrl;
$this->toolbarDocked = $toolbarDocked !== null ? $toolbarDocked : new Toolbar;
}
/**
* Get the value of embedUrl
*/
public function getEmbedUrl()
{
return $this->embedUrl;
}
/**
* Set the value of embedUrl
*/
public function setEmbedUrl($embedUrl)
{
$this->embedUrl = $embedUrl;
}
/**
* Get the value of fullscreenUrl
*/
public function getFullscreenUrl()
{
return $this->fullscreenUrl;
}
/**
* Set the value of fullscreenUrl
*/
public function setFullscreenUrl($fullscreenUrl)
{
$this->fullscreenUrl = $fullscreenUrl;
}
/**
* Get the value of saveUrl
*/
public function getSaveUrl()
{
return $this->saveUrl;
}
/**
* Set the value of saveUrl
*/
public function setSaveUrl($saveUrl)
{
$this->saveUrl = $saveUrl;
}
/**
* Get the value of toolbarDocked
*/
public function getToolbarDocked()
{
return $this->toolbarDocked;
}
/**
* Set the value of toolbarDocked
*/
public function setToolbarDocked($toolbarDocked)
{
$this->toolbarDocked = $toolbarDocked;
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class Features extends JsonSerializable
{
protected $spellcheck;
public function __construct(bool $spellcheck = true)
{
$this->spellcheck = $spellcheck;
}
/**
* Get the value of spellcheck
*/
public function getSpellcheck()
{
return $this->spellcheck;
}
/**
* Set the value of spellcheck
*/
public function setSpellcheck($spellcheck)
{
$this->spellcheck = $spellcheck;
}
}

View File

@@ -0,0 +1,129 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class Format extends JsonSerializable
{
protected $name;
protected $type;
protected $actions;
protected $convert;
protected $mime;
public function __construct(
string $name,
string $type = "",
array $actions = [],
array $convert = [],
array $mime = []
) {
$this->name = $name;
$this->type = $type;
$this->actions = $actions;
$this->convert = $convert;
$this->mime = $mime;
}
public function getName()
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
}
public function getType()
{
return $this->type;
}
public function setType(string $type)
{
$this->type = $type;
}
public function getActions()
{
return $this->actions;
}
public function setActions(array $actions)
{
$this->actions = $actions;
}
public function getConvert()
{
return $this->convert;
}
public function setConvert(array $convert)
{
$this->convert = $convert;
}
public function getMimes()
{
return $this->mime;
}
public function setMimes(array $mime)
{
$this->mime = $mime;
}
protected function hasAction(string $search)
{
return in_array($search, $this->actions);
}
public function isViewable()
{
return $this->hasAction("view");
}
public function isStrictlyEditable()
{
return $this->hasAction("edit");
}
public function isLossyEditable()
{
return $this->hasAction("lossy-edit");
}
public function isEditable()
{
return $this->hasAction("edit") || $this->hasAction("lossy-edit");
}
public function isAutoConvertable()
{
$this->hasAction("auto-convert");
}
public function isFillable()
{
return $this->hasAction("fill");
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class GoBack extends JsonSerializable
{
protected $blank;
protected $requestClose;
protected $text;
protected $url;
public function __construct(bool $blank = true, bool $requestClose = false, string $text = "", string $url = "")
{
$this->blank = $blank;
$this->requestClose = $requestClose;
$this->text = $text;
$this->url = $url;
}
/**
* Get the value of blank
*/
public function getBlank()
{
return $this->blank;
}
/**
* Set the value of blank
*/
public function setBlank($blank)
{
$this->blank = $blank;
}
/**
* Get the value of requestClose
*/
public function getRequestClose()
{
return $this->requestClose;
}
/**
* Set the value of requestClose
*/
public function setRequestClose($requestClose)
{
$this->requestClose = $requestClose;
}
/**
* Get the value of text
*/
public function getText()
{
return $this->text;
}
/**
* Set the value of text
*/
public function setText($text)
{
$this->text = $text;
}
/**
* Get the value of url
*/
public function getUrl()
{
return $this->url;
}
/**
* Set the value of url
*/
public function setUrl($url)
{
$this->url = $url;
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\Changes;
class History extends JsonSerializable
{
protected $serverVersion;
protected $changes; // array of Changes
public function __construct(string $serverVersion = "", array $changes = [])
{
$this->serverVersion = $serverVersion;
$this->changes = $changes;
}
/**
* Get the value of serverVersion
*/
public function getServerVersion()
{
return $this->serverVersion;
}
/**
* Set the value of serverVersion
*/
public function setServerVersion($serverVersion)
{
$this->serverVersion = $serverVersion;
}
/**
* Set the value of changes
*/
public function setChanges($changes)
{
$this->changes = $changes;
}
}

View File

@@ -0,0 +1,125 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\SharingSettings;
class Info extends JsonSerializable
{
protected $favorite;
protected $folder;
protected $owner;
protected $sharingSettings; // array of SharingSettings
protected $uploaded;
public function __construct(
bool $favorite = false,
string $folder = "",
string $owner = "",
array $sharingSettings = [],
string $uploaded = ""
) {
$this->favorite = $favorite;
$this->folder = $folder;
$this->owner = $owner;
$this->sharingSettings = $sharingSettings;
$this->uploaded = $uploaded;
}
/**
* Get the value of favorite
*/
public function getFavorite()
{
return $this->favorite;
}
/**
* Set the value of favorite
*/
public function setFavorite($favorite)
{
$this->favorite = $favorite;
}
/**
* Get the value of folder
*/
public function getFolder()
{
return $this->folder;
}
/**
* Set the value of folder
*/
public function setFolder($folder)
{
$this->folder = $folder;
}
/**
* Get the value of owner
*/
public function getOwner()
{
return $this->owner;
}
/**
* Set the value of owner
*/
public function setOwner($owner)
{
$this->owner = $owner;
}
/**
* Get the value of sharingSettings
*/
public function getSharingSettings()
{
return $this->sharingSettings;
}
/**
* Set the value of sharingSettings
*/
public function setSharingSettings($sharingSettings)
{
$this->sharingSettings = $sharingSettings;
}
/**
* Get the value of uploaded
*/
public function getUploaded()
{
return $this->uploaded;
}
/**
* Set the value of uploaded
*/
public function setUploaded($uploaded)
{
$this->uploaded = $uploaded;
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
abstract class JsonSerializable implements \JsonSerializable
{
public function jsonSerialize()
{
$vars = get_object_vars($this);
foreach ($vars as $key => $var) {
if (empty($var) && !is_bool($var)) {
unset($vars[$key]);
} else {
if (is_object($var)) {
if (property_exists($var, "value")) {
if (empty($var->value)) {
unset($vars[$key]);
} else {
$vars[$key] = $var->value;
}
}
}
}
}
return $vars;
}
public function mapFromArray(array $values)
{
foreach ($values as $key => $value) {
try {
$mapperFunction = "set" . lcfirst($key);
$this->{$mapperFunction}($value);
} catch (\Exception $e) {
continue;
}
}
}
}

View File

@@ -0,0 +1,101 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class Logo extends JsonSerializable
{
protected $image;
protected $imageDark;
protected $url;
protected $visible;
public function __construct(string $image = "", string $imageDark = "", string $url = "", bool $visible = true)
{
$this->image = $image;
$this->imageDark = $imageDark;
$this->url = $url;
$this->visible = $visible;
}
/**
* Get the value of image
*/
public function getImage()
{
return $this->image;
}
/**
* Set the value of image
*/
public function setImage($image)
{
$this->image = $image;
}
/**
* Get the value of imageDark
*/
public function getImageDark()
{
return $this->imageDark;
}
/**
* Set the value of imageDark
*/
public function setImageDark($imageDark)
{
$this->imageDark = $imageDark;
}
/**
* Get the value of imageEmbedded
*/
public function getImageEmbedded()
{
return $this->imageEmbedded;
}
/**
* Set the value of imageEmbedded
*/
public function setImageEmbedded($imageEmbedded)
{
$this->imageEmbedded = $imageEmbedded;
}
/**
* Get the value of url
*/
public function getUrl()
{
return $this->url;
}
/**
* Set the value of url
*/
public function setUrl($url)
{
$this->url = $url;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class MacrosMode extends BasicEnum
{
const DISABLE = "disable";
const ENABLE = "enable";
const WARN = "warn";
public function __construct($macrosMode = null)
{
if (!self::isValidValue($macrosMode) && $macrosMode !== null) {
throw new \Exception("Unknown macros mode");
} else {
$this->value = $macrosMode !== null ? $macrosMode : self::WARN;
}
}
}

View File

@@ -0,0 +1,353 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\CommentGroups;
class Permissions extends JsonSerializable
{
protected $chat;
protected $comment;
protected $commentGroups;
protected $copy;
protected $deleteCommentAuthorOnly;
protected $download;
protected $edit;
protected $editCommentAuthorOnly;
protected $fillForms;
protected $modifyContentControl;
protected $modifyFilter;
protected $print;
protected $protect;
protected $rename;
protected $review;
protected $reviewGroups; //string array
protected $userInfoGroups; //string array
public function __construct(
?bool $chat = true,
?bool $comment = true,
?CommentGroups $commentGroups = null,
?bool $copy = true,
?bool $deleteCommentAuthorOnly = false,
?bool $download = true,
?bool $edit = true,
?bool $editCommentAuthorOnly = false,
?bool $fillForms = true,
?bool $modifyContentControl = true,
?bool $modifyFilter = true,
?bool $print = true,
?bool $protect = true,
?bool $rename = false,
?bool $review = false,
?array $reviewGroups = null,
?array $userInfoGroups = null
) {
$this->chat = $chat;
$this->comment = $comment;
$this->commentGroups = $commentGroups !== null ? $commentGroups : new CommentGroups;
$this->copy = $copy;
$this->deleteCommentAuthorOnly = $deleteCommentAuthorOnly;
$this->download = $download;
$this->edit = $edit;
$this->editCommentAuthorOnly = $editCommentAuthorOnly;
$this->fillForms = $fillForms;
$this->modifyContentControl = $modifyContentControl;
$this->modifyFilter = $modifyFilter;
$this->print = $print;
$this->protect = $protect;
$this->rename = $rename;
$this->review = $review;
$this->reviewGroups = $reviewGroups;
$this->userInfoGroups = $userInfoGroups;
}
/**
* Get the value of chat
*/
public function getChat()
{
return $this->chat;
}
/**
* Set the value of chat
*/
public function setChat($chat)
{
$this->chat = $chat;
}
/**
* Get the value of comment
*/
public function getComment()
{
return $this->comment;
}
/**
* Set the value of comment
*/
public function setComment($comment)
{
$this->comment = $comment;
}
/**
* Get the value of commentGroups
*/
public function getCommentGroups()
{
return $this->commentGroups;
}
/**
* Set the value of commentGroups
*/
public function setCommentGroups($commentGroups)
{
$this->commentGroups = $commentGroups;
}
/**
* Get the value of copy
*/
public function getCopy()
{
return $this->copy;
}
/**
* Set the value of copy
*/
public function setCopy($copy)
{
$this->copy = $copy;
}
/**
* Get the value of deleteCommentAuthorOnly
*/
public function getDeleteCommentAuthorOnly()
{
return $this->deleteCommentAuthorOnly;
}
/**
* Set the value of deleteCommentAuthorOnly
*/
public function setDeleteCommentAuthorOnly($deleteCommentAuthorOnly)
{
$this->deleteCommentAuthorOnly = $deleteCommentAuthorOnly;
}
/**
* Get the value of download
*/
public function getDownload()
{
return $this->download;
}
/**
* Set the value of download
*/
public function setDownload($download)
{
$this->download = $download;
}
/**
* Get the value of edit
*/
public function getEdit()
{
return $this->edit;
}
/**
* Set the value of edit
*/
public function setEdit($edit)
{
$this->edit = $edit;
}
/**
* Get the value of editCommentAuthorOnly
*/
public function getEditCommentAuthorOnly()
{
return $this->editCommentAuthorOnly;
}
/**
* Set the value of editCommentAuthorOnly
*/
public function setEditCommentAuthorOnly($editCommentAuthorOnly)
{
$this->editCommentAuthorOnly = $editCommentAuthorOnly;
}
/**
* Get the value of fillForms
*/
public function getFillForms()
{
return $this->fillForms;
}
/**
* Set the value of fillForms
*/
public function setFillForms($fillForms)
{
$this->fillForms = $fillForms;
}
/**
* Get the value of modifyContentControl
*/
public function getModifyContentControl()
{
return $this->modifyContentControl;
}
/**
* Set the value of modifyContentControl
*/
public function setModifyContentControl($modifyContentControl)
{
$this->modifyContentControl = $modifyContentControl;
}
/**
* Get the value of modifyFilter
*/
public function getModifyFilter()
{
return $this->modifyFilter;
}
/**
* Set the value of modifyFilter
*/
public function setModifyFilter($modifyFilter)
{
$this->modifyFilter = $modifyFilter;
}
/**
* Get the value of print
*/
public function getPrint()
{
return $this->print;
}
/**
* Set the value of print
*/
public function setPrint($print)
{
$this->print = $print;
}
/**
* Get the value of protect
*/
public function getProtect()
{
return $this->protect;
}
/**
* Set the value of protect
*/
public function setProtect($protect)
{
$this->protect = $protect;
}
/**
* Get the value of rename
*/
public function getRename()
{
return $this->rename;
}
/**
* Set the value of rename
*/
public function setRename($rename)
{
$this->rename = $rename;
}
/**
* Get the value of review
*/
public function getReview()
{
return $this->review;
}
/**
* Set the value of review
*/
public function setReview($review)
{
$this->review = $review;
}
/**
* Get the value of reviewGroups
*/
public function getReviewGroups()
{
return $this->reviewGroups;
}
/**
* Set the value of reviewGroups
*/
public function setReviewGroups($reviewGroups)
{
$this->reviewGroups = $reviewGroups;
}
/**
* Get the value of userInfoGroups
*/
public function getUserInfoGroups()
{
return $this->userInfoGroups;
}
/**
* Set the value of userInfoGroups
*/
public function setUserInfoGroups($userInfoGroups)
{
$this->userInfoGroups = $userInfoGroups;
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class Recent extends JsonSerializable
{
protected $folder;
protected $title;
protected $url;
public function __construct(string $folder = "", string $title = "", string $url = "")
{
$this->folder = $folder;
$this->title = $title;
$this->url = $url;
}
/**
* Get the value of folder
*/
public function getFolder()
{
return $this->folder;
}
/**
* Set the value of folder
*/
public function setFolder($folder)
{
$this->folder = $folder;
}
/**
* Get the value of title
*/
public function getTitle()
{
return $this->title;
}
/**
* Set the value of title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get the value of url
*/
public function getUrl()
{
return $this->url;
}
/**
* Set the value of url
*/
public function setUrl($url)
{
$this->url = $url;
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class ReferenceData extends JsonSerializable
{
protected $fileKey;
protected $instanceId;
protected $key;
public function __construct(?string $fileKey = "", ?string $instanceId = "", ?string $key = "")
{
$this->fileKey = $fileKey;
$this->instanceId = $instanceId;
$this->key = $key;
}
/**
* Get the value of fileKey
*/
public function getFileKey()
{
return $this->fileKey;
}
/**
* Set the value of fileKey
*/
public function setFileKey($fileKey)
{
$this->fileKey = $fileKey;
}
/**
* Get the value of instanceId
*/
public function getInstanceId()
{
return $this->instanceId;
}
/**
* Set the value of instanceId
*/
public function setInstanceId($instanceId)
{
$this->instanceId = $instanceId;
}
/**
* Get the value of key
*/
public function getKey()
{
return $this->key;
}
/**
* Set the value of key
*/
public function setKey($key)
{
$this->key = $key;
}
}

View File

@@ -0,0 +1,125 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\ReviewDisplay;
class Review extends JsonSerializable
{
protected $hideReviewDisplay;
protected $hoverMode;
protected $reviewDisplay;
protected $showReviewChanges;
protected $trackChanges;
public function __construct(
bool $hideReviewDisplay = false,
bool $hoverMode = false,
ReviewDisplay $reviewDisplay = null,
bool $showReviewChanges = false,
bool $trackChanges = true
) {
$this->hideReviewDisplay = $hideReviewDisplay;
$this->hoverMode = $hoverMode;
$this->reviewDisplay = $reviewDisplay !== null ? $reviewDisplay : new ReviewDisplay;
$this->showReviewChanges = $showReviewChanges;
$this->trackChanges = $trackChanges;
}
/**
* Get the value of hideReviewDisplay
*/
public function getHideReviewDisplay()
{
return $this->hideReviewDisplay;
}
/**
* Set the value of hideReviewDisplay
*/
public function setHideReviewDisplay($hideReviewDisplay)
{
$this->hideReviewDisplay = $hideReviewDisplay;
}
/**
* Get the value of hoverMode
*/
public function getHoverMode()
{
return $this->hoverMode;
}
/**
* Set the value of hoverMode
*/
public function setHoverMode($hoverMode)
{
$this->hoverMode = $hoverMode;
}
/**
* Get the value of reviewDisplay
*/
public function getReviewDisplay()
{
return $this->reviewDisplay;
}
/**
* Set the value of reviewDisplay
*/
public function setReviewDisplay($reviewDisplay)
{
$this->reviewDisplay = $reviewDisplay;
}
/**
* Get the value of showReviewChanges
*/
public function getShowReviewChanges()
{
return $this->showReviewChanges;
}
/**
* Set the value of showReviewChanges
*/
public function setShowReviewChanges($showReviewChanges)
{
$this->showReviewChanges = $showReviewChanges;
}
/**
* Get the value of trackChanges
*/
public function getTrackChanges()
{
return $this->trackChanges;
}
/**
* Set the value of trackChanges
*/
public function setTrackChanges($trackChanges)
{
$this->trackChanges = $trackChanges;
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class ReviewDisplay extends BasicEnum
{
const MARKUP = "markup";
const SIMPLE = "simple";
const FINAL = "final";
const ORIGINAL = "original";
public function __construct($reviewDisplay = null)
{
if (!self::isValidValue($reviewDisplay) && $reviewDisplay !== null) {
throw new \Exception("Unknown review display type");
} else {
$this->value = $reviewDisplay !== null ? $reviewDisplay : self::ORIGINAL;
}
}
}

View File

@@ -0,0 +1,88 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\SharingSettingsPermissions;
class SharingSettings extends JsonSerializable
{
protected $isLink;
protected $sharingSettingsPermissions;
protected $user;
public function __construct(
bool $isLink = false,
SharingSettingsPermissions $sharingSettingsPermissions = null,
string $user = ""
) {
$this->isLink = $isLink;
$this->sharingSettingsPermissions =
$sharingSettingsPermissions !== null ? $sharingSettingsPermissions : new SharingSettingsPermissions;
$this->user = $user;
}
/**
* Get the value of isLink
*/
public function getIsLink()
{
return $this->isLink;
}
/**
* Set the value of isLink
*/
public function setIsLink($isLink)
{
$this->isLink = $isLink;
}
/**
* Get the value of sharingSettingsPermissions
*/
public function getSharingSettingsPermissions()
{
return $this->sharingSettingsPermissions;
}
/**
* Set the value of sharingSettingsPermissions
*/
public function setSharingSettingsPermissions($sharingSettingsPermissions)
{
$this->sharingSettingsPermissions = $sharingSettingsPermissions;
}
/**
* Get the value of user
*/
public function getUser()
{
return $this->user;
}
/**
* Set the value of user
*/
public function setUser($user)
{
$this->user = $user;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class SharingSettingsPermissions extends BasicEnum
{
const FULL_ACCESS = "Full Access";
const READ_ONLY = "Read Only";
const DENY_ACCESS = "Deny Access";
public function __construct($type = null)
{
if (!self::isValidValue($type) && $type !== null) {
throw new \Exception("Unknown sharing settings permission type");
} else {
$this->value = $type !== null ? $type : self::FULL_ACCESS;
}
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class Template extends JsonSerializable
{
protected $image;
protected $title;
protected $url;
public function __construct(string $image = "", string $title = "", string $url = "")
{
$this->image = $image;
$this->title = $title;
$this->url = $url;
}
/**
* Get the value of image
*/
public function getImage()
{
return $this->image;
}
/**
* Set the value of image
*/
public function setImage($image)
{
$this->image = $image;
}
/**
* Get the value of title
*/
public function getTitle()
{
return $this->title;
}
/**
* Set the value of title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* Get the value of url
*/
public function getUrl()
{
return $this->url;
}
/**
* Set the value of url
*/
public function setUrl($url)
{
$this->url = $url;
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class Toolbar extends BasicEnum
{
const TOP = "top";
const BOTTOM = "bottom";
public function __construct($toolbar = null)
{
if (!self::isValidValue($toolbar) && $toolbar !== null) {
throw new \Exception("Unknown toolbar type");
} else {
$this->value = $toolbar !== null ? $toolbar : self::TOP;
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class Type extends BasicEnum
{
const DESKTOP = "desktop";
const MOBILE = "mobile";
const EMBEDDED = "embedded";
public function __construct($type = null)
{
if (!self::isValidValue($type) && $type !== null) {
throw new \Exception("Unknown editors type");
} else {
$this->value = $type !== null ? $type : self::DESKTOP;
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Util\BasicEnum;
class Unit extends BasicEnum
{
const CM = "cm";
const PT = "pt";
const INCH = "inch";
public function __construct($type = null)
{
if (!self::isValidValue($type) && $type !== null) {
throw new \Exception("Unknown unit type");
} else {
$this->value = $type !== null ? $type : self::CM;
}
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Models;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
class User extends JsonSerializable
{
protected $id;
protected $name;
protected $group;
protected $image;
public function __construct(string $id = "", string $name = "", string $group = "", string $image = "")
{
$this->id = $id;
$this->name = $name;
$this->group = $group;
$this->image = $image;
}
public function getGroup()
{
return $this->group;
}
public function setGroup(string $group)
{
$this->group = $group;
}
public function getId()
{
return $this->id;
}
public function setId(string $id)
{
$this->id = $id;
}
public function getImage()
{
return $this->image;
}
public function setImage(array $image)
{
$this->image = $image;
}
public function getName()
{
return $this->name;
}
public function setName(string $name)
{
$this->name = $name;
}
}

View File

@@ -0,0 +1,117 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Service\Callback;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Callback service Interface.
*
* @package Onlyoffice\DocsIntegrationSdk\Service\Callback
*/
use Onlyoffice\DocsIntegrationSdk\Manager\Settings\SettingsManager;
use Onlyoffice\DocsIntegrationSdk\Manager\Security\JwtManager;
use Onlyoffice\DocsIntegrationSdk\Manager\Document\DocumentManager;
use Onlyoffice\DocsIntegrationSdk\Models\Callback;
use Onlyoffice\DocsIntegrationSdk\Models\CallbackDocStatus;
use Onlyoffice\DocsIntegrationSdk\Util\CommonError;
abstract class CallbackService implements CallbackServiceInterface
{
private const TRACKERSTATUS_EDITING = 1;
private const TRACKERSTATUS_MUSTSAVE = 2;
private const TRACKERSTATUS_CORRUPTED = 3;
private const TRACKERSTATUS_CLOSED = 4;
private const TRACKERSTATUS_FORCESAVE = 6;
private const TRACKERSTATUS_CORRUPTEDFORCESAVE = 7;
protected $settingsManager;
protected $jwtManager;
abstract public function processTrackerStatusEditing(Callback $callback, string $fileid);
abstract public function processTrackerStatusMustsave(Callback $callback, string $fileid);
abstract public function processTrackerStatusCorrupted(Callback $callback, string $fileid);
abstract public function processTrackerStatusClosed(Callback $callback, string $fileid);
abstract public function processTrackerStatusForcesave(Callback $callback, string $fileid);
public function __construct(SettingsManager $settingsManager, JwtManager $jwtManager)
{
$this->settingsManager = $settingsManager;
$this->jwtManager = $jwtManager;
}
public function verifyCallback(Callback $callback, string $authorizationHeader = "")
{
if ($this->jwtManager->isJwtEnabled()) {
$token = $callback->getToken();
$payload = null;
$fromHeader = false;
if (!empty($authorizationHeader)) {
$compareHeaders = substr($authorizationHeader, 0, strlen($this->settingsManager->getJwtPrefix()));
if ($compareHeaders === $this->settingsManager->getJwtPrefix()) {
$token = $compareHeaders;
$fromHeader = true;
}
}
if (empty($token)) {
throw new \Exception(CommonError::message(CommonError::CALLBACK_NO_AUTH_TOKEN));
}
$payload = $this->jwtManager->jwtDecode($token);
$callbackFromToken = json_decode($payload, true);
if ($fromHeader) {
$callbackFromToken = $callbackFromToken["payload"];
}
$callback = new Callback;
$callback->mapFromArray($callbackFromToken);
}
return $callback;
}
public function processCallback(Callback $callback, string $fileId)
{
switch ($callback->getStatus()->getValue()) {
case CallbackDocStatus::EDITING:
return $this->processTrackerStatusEditing($callback, $fileId);
case CallbackDocStatus::SAVE:
return $this->processTrackerStatusMustsave($callback, $fileId);
case CallbackDocStatus::SAVE_CORRUPTED:
return $this->processTrackerStatusCorrupted($callback, $fileId);
case CallbackDocStatus::CLOSED:
return $this->processTrackerStatusClosed($callback, $fileId);
case CallbackDocStatus::FORCESAVE:
return $this->processTrackerStatusForcesave($callback, $fileId);
case CallbackDocStatus::FORCESAVE_CORRUPTED:
return $this->processTrackerStatusCorruptedForcesave($callback, $fileId);
default:
throw new \Exception(CommonError::message(CommonError::CALLBACK_NO_STATUS));
}
}
public function processTrackerStatusCorruptedForcesave(Callback $callback, string $fileid)
{
return $this->processTrackerStatusForcesave($callback, $fileid);
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Service\Callback;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Models\Callback;
interface CallbackServiceInterface
{
/**
* Verifies the Callback object.
*
* @param Callback $callback Object with the callback handler parameters.
* @param string $authorizationHeader The authorization header from the callback request.
* @throws Exception If authorization token is not found.
* @return Callback
*/
public function verifyCallback(Callback $callback, string $authorizationHeader);
/**
* Starts the callback handler.
*
* @param Callback $callback Object with the callback handler parameters.
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
*/
public function processCallback(Callback $callback, string $fileId);
/**
* Starts the handler that is called if the callback status is 1 (EDITING).
*
* @param Callback $callback Object with the callback handler parameters.
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
*/
public function processTrackerStatusEditing(Callback $callback, string $fileId);
/**
* Starts the handler that is called if the callback status is 2 (SAVE).
*
* @param Callback $callback Object with the callback handler parameters.
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
*/
public function processTrackerStatusMustsave(Callback $callback, string $fileId);
/**
* Starts the handler that is called if the callback status is 3 (SAVE_CORRUPTED).
*
* @param Callback $callback Object with the callback handler parameters.
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
*/
public function processTrackerStatusCorrupted(Callback $callback, string $fileId);
/**
* Starts the handler that is called if the callback status is 4 (CLOSED).
*
* @param Callback $callback Object with the callback handler parameters.
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
*/
public function processTrackerStatusClosed(Callback $callback, string $fileId);
/**
* Starts the handler that is called if the callback status is 6 (FORCESAVE).
*
* @param Callback $callback Object with the callback handler parameters.
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
*/
public function processTrackerStatusForcesave(Callback $callback, string $fileId);
/**
* Starts the handler that is called if the callback status is 7 (FORCESAVE_CORRUPTED).
*
* @param Callback $callback Object with the callback handler parameters.
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
*/
public function processTrackerStatusCorruptedForcesave(Callback $callback, string $fileId);
}

View File

@@ -0,0 +1,207 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Service\DocEditorConfig;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Manager\Settings\SettingsManager;
use Onlyoffice\DocsIntegrationSdk\Manager\Document\DocumentManager;
use Onlyoffice\DocsIntegrationSdk\Service\DocEditorConfig\DocEditorConfigServiceInterface;
use Onlyoffice\DocsIntegrationSdk\Manager\Security\JwtManager;
use Onlyoffice\DocsIntegrationSdk\Util\CommonError;
use Onlyoffice\DocsIntegrationSdk\Models\Config;
use Onlyoffice\DocsIntegrationSdk\Models\CoEditing;
use Onlyoffice\DocsIntegrationSdk\Models\Customization;
use Onlyoffice\DocsIntegrationSdk\Models\DocEditorConfig;
use Onlyoffice\DocsIntegrationSdk\Models\Document;
use Onlyoffice\DocsIntegrationSdk\Models\DocumentType;
use Onlyoffice\DocsIntegrationSdk\Models\EditorsMode;
use Onlyoffice\DocsIntegrationSdk\Models\Embedded;
use Onlyoffice\DocsIntegrationSdk\Models\GoBack;
use Onlyoffice\DocsIntegrationSdk\Models\Info;
use Onlyoffice\DocsIntegrationSdk\Models\Permissions;
use Onlyoffice\DocsIntegrationSdk\Models\Recent;
use Onlyoffice\DocsIntegrationSdk\Models\ReferenceData;
use Onlyoffice\DocsIntegrationSdk\Models\Template;
use Onlyoffice\DocsIntegrationSdk\Models\Type;
use Onlyoffice\DocsIntegrationSdk\Models\User;
use Onlyoffice\DocsIntegrationSdk\Util\EnvUtil;
abstract class DocEditorConfigService implements DocEditorConfigServiceInterface
{
protected $documentManager;
protected $jwtManager;
protected $settingsManager;
public function __construct(
SettingsManager $settingsManager,
JwtManager $jwtManager,
DocumentManager $documentManager
) {
EnvUtil::loadEnvSettings();
$this->settingsManager = $settingsManager;
$this->jwtManager = $jwtManager;
$this->documentManager = $documentManager;
}
public function createConfig(string $fileId, EditorsMode $mode, string $userAgent)
{
$documentName = $this->documentManager->getDocumentName($fileId);
$type = $this->getType($userAgent);
$ext = $this->documentManager->getExt($documentName);
$documentType = new DocumentType($this->documentManager->getDocType($ext));
$document = $this->getDocument($fileId, $type);
$editorConfig = $this->getDocEditorConfig($fileId, $mode, $type);
$config = new Config(
$documentType,
"100%",
"100%",
"",
$type,
$editorConfig,
$document
);
if ($this->jwtManager->isJwtEnabled()) {
$config->setToken($this->jwtManager->jwtEncode($config));
}
return $config;
}
public function isMobileAgent(string $userAgent = "")
{
$userAgent = !empty($userAgent) ? $userAgent : $_SERVER["HTTP_USER_AGENT"];
$envKey = EnvUtil::envKey("EDITING_SERVICE_MOBILE_USER_AGENT");
// phpcs:ignore
$agentList = isset($_ENV[$envKey]) && !empty($_ENV[$envKey]) ? $_ENV[$envKey] : "android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino";
return preg_match($agentList, $userAgent);
}
public function getDocEditorConfig(string $fileId, EditorsMode $mode, Type $type)
{
$permissions = $this->getPermissions($fileId);
$editorConfig = new DocEditorConfig;
$editorConfig->setCoEditing($this->getCoEditing($fileId, $mode, $type));
$editorConfig->setCreateUrl($this->documentManager->getCreateUrl($fileId));
$editorConfig->setUser($this->getUser());
$editorConfig->setRecent($this->getRecent());
$editorConfig->setTemplates($this->getTemplates($fileId));
$editorConfig->setCustomization($this->getCustomization($fileId));
$editorConfig->setLang($this->getLang());
$editorConfig->setRegion($this->getRegion());
if (($permissions->getEdit() || $permissions->getFillForms() ||
$permissions->getComment() ||$permissions->getReview())
&& $mode->getValue() === EditorsMode::EDIT) {
$editorConfig->setCallbackUrl($this->documentManager->getCallbackUrl($fileId));
}
if ($type->getValue() === Type::EMBEDDED) {
$editorConfig->setEmbedded($this->getEmbedded($fileId));
}
return $editorConfig;
}
public function getDocument(string $fileId, Type $type)
{
$documentName = $this->documentManager->getDocumentName($fileId);
$permissions = $this->getPermissions($fileId);
$document = new Document(
$this->documentManager->getExt($documentName),
$this->documentManager->getDocumentKey($fileId, $type->getValue() === Type::EMBEDDED),
$this->getReferenceData($fileId),
$documentName,
$this->documentManager->getFileUrl($fileId),
$this->getInfo($fileId),
$permissions
);
return $document;
}
public function getCustomization(string $fileId)
{
$goback = new GoBack;
if (!empty($this->documentManager->getGobackUrl($fileId))) {
$goback->setUrl($this->documentManager->getGobackUrl($fileId));
}
$customization = new Customization;
$customization->setGoback($goback);
return $customization;
}
public function getPermissions(string $fileId = "")
{
return null;
}
public function getReferenceData(string $fileId = "")
{
return null;
}
public function getInfo(string $fileId = "")
{
return null;
}
public function getCoEditing(string $fileId = "", EditorsMode $mode = null, Type $type)
{
return null;
}
public function getType(string $userAgent = "")
{
return $this->isMobileAgent($userAgent) ? new Type(Type::MOBILE) : new Type(Type::DESKTOP);
}
public function getUser()
{
return null;
}
public function getRecent()
{
return null;
}
public function getTemplates($fileId)
{
return null;
}
public function getEmbedded($fileId)
{
return null;
}
public function getLang()
{
return "en";
}
public function getRegion()
{
return "en-US";
}
}

View File

@@ -0,0 +1,174 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Service\DocEditorConfig;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Editors config service Interface.
*
* @package Onlyoffice\DocsIntegrationSdk\Service\DocEditorConfig
*/
use Onlyoffice\DocsIntegrationSdk\Models\CoEditing;
use Onlyoffice\DocsIntegrationSdk\Models\Customization;
use Onlyoffice\DocsIntegrationSdk\Models\Document;
use Onlyoffice\DocsIntegrationSdk\Models\EditorsMode;
use Onlyoffice\DocsIntegrationSdk\Models\Embedded;
use Onlyoffice\DocsIntegrationSdk\Models\Info;
use Onlyoffice\DocsIntegrationSdk\Models\Permissions;
use Onlyoffice\DocsIntegrationSdk\Models\Recent;
use Onlyoffice\DocsIntegrationSdk\Models\ReferenceData;
use Onlyoffice\DocsIntegrationSdk\Models\Type;
use Onlyoffice\DocsIntegrationSdk\Models\User;
interface DocEditorConfigServiceInterface
{
/**
* Creates a configuration for the document editor using the User-Agent request header.
*
* @param string $fileId The file ID.
* @param EditorsMode $mode The editor opening mode.
* @param string $userAgent The User-Agent request header that is used
* to determine the platform type ("desktop" or "mobile").
* @throws Exception If the processing fails unexpectedly.
* @return Config
*/
public function createConfig(string $fileId, EditorsMode $mode, string $userAgent);
/**
* Checks whether the mobile agent is used or not.
*
* @param string $userAgent The User-Agent request header.
* @throws Exception If the processing fails unexpectedly.
* @return bool
*/
public function isMobileAgent(string $userAgent);
/**
* Returns the DocEditorConfig object.
*
* @param string $fileId The file ID.
* @param EditorsMode $mode The editor opening mode.
* @param Type $type The platform type used to access the document.
* @throws Exception If the processing fails unexpectedly.
* @return DocEditorConfig
*/
public function getDocEditorConfig(string $fileId, EditorsMode $mode, Type $type);
/**
* Returns the Document object.
*
* @param string $fileId The file ID.
* @param Type $type The platform type used to access the document.
* @throws Exception If the processing fails unexpectedly.
* @return Document
*/
public function getDocument(string $fileId, Type $type);
/**
* Returns the Customization object.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return Customization
*/
public function getCustomization(string $fileId);
/**
* Returns the Permissions object.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return Permissions
*/
public function getPermissions(string $fileId);
/**
* Returns the ReferenceData object.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return ReferenceData
*/
public function getReferenceData(string $fileId);
/**
* Returns the Info object.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return Info
*/
public function getInfo(string $fileId);
/**
* Returns the CoEditing object.
*
* @param string $fileId The file ID.
* @param EditorsMode The editor opening mode.
* @param Type The platform type used to access the document.
* @throws Exception If the processing fails unexpectedly.
* @return CoEditing
*/
public function getCoEditing(string $fileId, EditorsMode $mode, Type $type);
/**
* Returns the Type object.
*
* @param string $userAgent The User-Agent request header.
* @throws Exception If the processing fails unexpectedly.
* @return Type
*/
public function getType(string $userAgent);
/**
* Returns the User object.
*
* @throws Exception If the processing fails unexpectedly.
* @return User
*/
public function getUser();
/**
* Returns array of Recent objects.
*
* @throws Exception If the processing fails unexpectedly.
* @return Recent[]
*/
public function getRecent();
/**
* Returns array of Template objects.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return Template[]
*/
public function getTemplates(string $fileId);
/**
* Returns the Embedded object.
*
* @param string $fileId The file ID.
* @throws Exception If the processing fails unexpectedly.
* @return Embedded
*/
public function getEmbedded(string $fileId);
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Service\Request;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Interface HttpClient.
*
* @package Onlyoffice\DocsIntegrationSdk\Service\Request
*/
interface HttpClientInterface
{
public function request($method, $url, $options);
public function getStatusCode();
public function getBody();
}

View File

@@ -0,0 +1,456 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Service\Request;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Onlyoffice\DocsIntegrationSdk\Manager\Document\DocumentManager;
use Onlyoffice\DocsIntegrationSdk\Manager\Settings\SettingsManager;
use Onlyoffice\DocsIntegrationSdk\Manager\Security\JwtManager;
use Onlyoffice\DocsIntegrationSdk\Models\ConvertRequest;
use Onlyoffice\DocsIntegrationSdk\Service\Request\RequestServiceInterface;
use Onlyoffice\DocsIntegrationSdk\Service\Request\HttpClientInterface;
use Onlyoffice\DocsIntegrationSdk\Util\CommandResponseError;
use Onlyoffice\DocsIntegrationSdk\Util\CommonError;
use Onlyoffice\DocsIntegrationSdk\Util\ConvertResponseError;
/**
* Default Document service.
*
* @package Onlyoffice\DocsIntegrationSdk\Service\Request
*/
abstract class RequestService implements RequestServiceInterface
{
/**
* Minimum supported version of editors
*
* @var float
*/
private const MIN_EDITORS_VERSION = 6.0;
protected SettingsManager $settingsManager;
protected JwtManager $jwtManager;
abstract public function getFileUrlForConvert();
public function __construct(
SettingsManager $settingsManager,
HttpClientInterface $httpClient,
JwtManager $jwtManager
) {
$this->settingsManager = $settingsManager;
$this->jwtManager = $jwtManager;
$this->httpClient = $httpClient;
}
/**
* Request to Document Server
*
* @param string $url - request address
* @param array $method - request method
* @param array $opts - request options
*
* @return string
*/
public function request($url, $method = "GET", $opts = [])
{
if ($this->settingsManager->isIgnoreSSL()) {
$opts["verify"] = false;
}
if (!array_key_exists("timeout", $opts)) {
$opts["timeout"] = 60;
}
$this->httpClient->request($url, $method, $opts);
if ($this->httpClient->getStatusCode() === 200) {
return $this->httpClient->getBody();
}
return "";
}
/**
* Generate an error code table of convertion
*
* @param int $errorCode - Error code
*
* @throws Exception
*/
public function processConvServResponceError($errorCode)
{
$errorMessage = '';
switch ($errorCode) {
case ConvertResponseError::UNKNOWN:
$errorMessage = ConvertResponseError::message(ConvertResponseError::UNKNOWN);
break;
case ConvertResponseError::TIMEOUT:
$errorMessage = ConvertResponseError::message(ConvertResponseError::TIMEOUT);
break;
case ConvertResponseError::CONVERSION:
$errorMessage = ConvertResponseError::message(ConvertResponseError::CONVERSION);
break;
case ConvertResponseError::DOWNLOADING:
$errorMessage = ConvertResponseError::message(ConvertResponseError::DOWNLOADING);
break;
case ConvertResponseError::PASSWORD:
$errorMessage = ConvertResponseError::message(ConvertResponseError::PASSWORD);
break;
case ConvertResponseError::DATABASE:
$errorMessage = ConvertResponseError::message(ConvertResponseError::DATABASE);
break;
case ConvertResponseError::INPUT:
$errorMessage = ConvertResponseError::message(ConvertResponseError::INPUT);
break;
case ConvertResponseError::TOKEN:
$errorMessage = ConvertResponseError::message(ConvertResponseError::TOKEN);
break;
default:
$errorMessage = "ErrorCode = " . $errorCode;
break;
}
throw new \Exception($errorMessage);
}
/**
* Generate an error code table of command
*
* @param string $errorCode - Error code
*
* @throws Exception
*/
public function processCommandServResponceError($errorCode)
{
$errorMessage = "";
switch ($errorCode) {
case CommandResponseError::NO:
return;
case CommandResponseError::KEY:
$errorMessage = CommandResponseError::message(CommandResponseError::KEY);
break;
case CommandResponseError::CALLBACK_URL:
$errorMessage = CommandResponseError::message(CommandResponseError::CALLBACK_URL);
break;
case CommandResponseError::INTERNAL_SERVER:
$errorMessage = CommandResponseError::message(CommandResponseError::INTERNAL_SERVER);
break;
case CommandResponseError::FORCE_SAVE:
$errorMessage = CommandResponseError::message(CommandResponseError::FORCE_SAVE);
break;
case CommandResponseError::COMMAND:
$errorMessage = CommandResponseError::message(CommandResponseError::COMMAND);
break;
case CommandResponseError::TOKEN:
$errorMessage = CommandResponseError::message(CommandResponseError::TOKEN);
break;
default:
$errorMessage = "ErrorCode = " . $errorCode;
break;
}
throw new \Exception($errorMessage);
}
/**
* Request health status
*
* @throws Exception
*
* @return bool
*/
public function healthcheckRequest() : bool
{
$healthcheckUrl = $this->settingsManager->getDocumentServerHealthcheckUrl();
if (empty($healthcheckUrl)) {
throw new \Exception(CommonError::message(CommonError::NO_HEALTHCHECK_ENDPOINT));
}
$response = $this->request($healthcheckUrl);
return $response === "true";
}
/**
* Request for conversion to a service
*
* @param string $documentUri - Uri for the document to convert
* @param string $fromExtension - Document extension
* @param string $toExtension - Extension to which to convert
* @param string $documentRevisionId - Key for caching on service
* @param bool - $isAsync - Perform conversions asynchronously
* @param string $region - Region
*
* @throws Exception
*
* @return array
*/
public function sendRequestToConvertService(
$documentUri,
$fromExtension,
$toExtension,
$documentRevisionId,
$isAsync,
$region = null
) {
$urlToConverter = $this->settingsManager->getConvertServiceUrl(true);
if (empty($urlToConverter)) {
throw new \Exception(CommonError::message(CommonError::NO_CONVERT_SERVICE_ENDPOINT));
}
if (empty($documentRevisionId)) {
$documentRevisionId = $documentUri;
}
$documentRevisionId = DocumentManager::generateRevisionId($documentRevisionId);
if (empty($fromExtension)) {
$fromExtension = pathinfo($documentUri)["extension"];
} else {
$fromExtension = trim($fromExtension, ".");
}
$data = new ConvertRequest;
$data->setAsync($isAsync);
$data->setUrl($documentUri);
$data->setOutputtype(trim($toExtension, "."));
$data->setFiletype($fromExtension);
$data->setTitle($documentRevisionId . "." . $fromExtension);
$data->setKey($documentRevisionId);
if (!is_null($region)) {
$data->setRegion($region);
}
$opts = [
"timeout" => "120",
"headers" => [
'Content-type' => 'application/json'
],
"body" => json_encode($data)
];
if ($this->jwtManager->isJwtEnabled()) {
$params = [
"payload" => json_decode(json_encode($data), true)
];
$token = $this->jwtManager->jwtEncode($params);
$jwtHeader = $this->settingsManager->getJwtHeader();
$jwtPrefix = $this->settingsManager->getJwtPrefix();
if (empty($jwtHeader)) {
throw new \Exception(CommonError::message(CommonError::NO_JWT_HEADER));
} elseif (empty($jwtPrefix)) {
throw new \Exception(CommonError::message(CommonError::NO_JWT_PREFIX));
}
$opts["headers"][$jwtHeader] = (string)$jwtPrefix . $token;
$token = $this->jwtManager->jwtEncode(json_decode(json_encode($data), true));
$data->setToken($token);
$opts["body"] = json_encode($data);
}
$responseXmlData = $this->request($urlToConverter, "POST", $opts);
libxml_use_internal_errors(true);
if (!function_exists("simplexml_load_file")) {
throw new \Exception(CommonError::message(CommonError::READ_XML));
}
$responseData = simplexml_load_string($responseXmlData);
if (!$responseData) {
$exc = CommonError::message(CommonError::BAD_RESPONSE_XML);
foreach (libxml_get_errors() as $error) {
$exc = $exc . PHP_EOL . $error->message;
}
throw new \Exception($exc);
}
return $responseData;
}
/**
* The method is to convert the file to the required format and return the result url
*
* @param string $documentUri - Uri for the document to convert
* @param string $fromExtension - Document extension
* @param string $toExtension - Extension to which to convert
* @param string $documentRevisionId - Key for caching on service
* @param string $region - Region
*
* @return string
*/
public function getConvertedUri($documentUri, $fromExtension, $toExtension, $documentRevisionId, $region = null)
{
$responseFromConvertService = $this->sendRequestToConvertService(
$documentUri,
$fromExtension,
$toExtension,
$documentRevisionId,
false,
$region
);
// phpcs:ignore
$errorElement = $responseFromConvertService->Error;
if ($errorElement->count() > 0) {
$this->processConvServResponceError($errorElement);
}
// phpcs:ignore
$isEndConvert = $responseFromConvertService->EndConvert;
if ($isEndConvert !== null && strtolower($isEndConvert) === "true") {
// phpcs:ignore
return is_string($responseFromConvertService->FileUrl) ? $responseFromConvertService->FileUrl : $responseFromConvertService->FileUrl->__toString();
}
return "";
}
/**
* Send command
*
* @param string $method - type of command
*
* @return array
*/
public function commandRequest($method)
{
$urlCommand = $this->settingsManager->getCommandServiceUrl(true);
if (empty($urlCommand)) {
throw new \Exception(CommonError::message(CommonError::NO_COMMAND_ENDPOINT));
}
$data = [
"c" => $method
];
$opts = [
"headers" => [
"Content-type" => "application/json"
],
"body" => json_encode($data)
];
if ($this->jwtManager->isJwtEnabled()) {
$params = [
"payload" => $data
];
$token = $this->jwtManager->jwtEncode($params);
$jwtHeader = $this->settingsManager->getJwtHeader();
$jwtPrefix = $this->settingsManager->getJwtPrefix();
if (empty($jwtHeader)) {
throw new \Exception(CommonError::message(CommonError::NO_JWT_HEADER));
} elseif (empty($jwtPrefix)) {
throw new \Exception(CommonError::message(CommonError::NO_JWT_PREFIX));
}
$opts["headers"][$jwtHeader] = $jwtPrefix . $token;
$token = $this->jwtManager->jwtEncode($data);
$data["token"] = $token;
$opts["body"] = json_encode($data);
}
$response = $this->request($urlCommand, "post", $opts);
$data = json_decode($response);
$this->processCommandServResponceError($data->error);
return $data;
}
/**
* Checking document service location
*
* @return array
*/
public function checkDocServiceUrl()
{
$version = null;
$documentServerUrl = $this->settingsManager->getDocumentServerUrl();
if (empty($documentServerUrl)) {
throw new \Exception(CommonError::message(CommonError::NO_DOCUMENT_SERVER_URL));
}
try {
if ((isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on" || $_SERVER["HTTPS"] == 1)
|| isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https")
&& preg_match('/^http:\/\//i', $documentServerUrl)) {
throw new \Exception(CommonError::message(CommonError::MIXED_CONTENT));
}
} catch (\Exception $e) {
return [$e->getMessage(), $version];
}
try {
$healthcheckResponse = $this->healthcheckRequest();
if (!$healthcheckResponse) {
throw new \Exception(CommonError::message(CommonError::BAD_HEALTHCHECK_STATUS));
}
} catch (\Exception $e) {
return [$e->getMessage(), $version];
}
try {
$commandResponse = $this->commandRequest('version');
if (empty($commandResponse)) {
throw new \Exception(CommonError::message(CommonError::BAD_HEALTHCHECK_STATUS));
}
$version = $commandResponse->version;
$versionF = floatval($version);
if ($versionF > 0.0 && $versionF <= self::MIN_EDITORS_VERSION) {
throw new \Exception(CommonError::message(CommonError::NOT_SUPPORTED_VERSION));
}
} catch (\Exception $e) {
return [$e->getMessage(), $version];
}
try {
$fileUrl = $this->getFileUrlForConvert();
if (!empty($fileUrl)) {
if (!empty($this->settingsManager->getStorageUrl())) {
$fileUrl = str_replace(
$this->settingsManager->getServerUrl(),
$this->settingsManager->getStorageUrl(),
$fileUrl
);
}
$convertedFileUri = $this->getConvertedUri($fileUrl, "docx", "docx", "check_" . rand());
}
} catch (\Exception $e) {
return [$e->getMessage(), $version];
}
try {
$this->request($convertedFileUri);
} catch (\Exception $e) {
return [$e->getMessage(), $version];
}
return ["", $version];
}
}

View File

@@ -0,0 +1,134 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Service\Request;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Interface DocumentService.
*
* @package Onlyoffice\DocsIntegrationSdk\Service\Request
*/
interface RequestServiceInterface
{
/**
* Returns url of file for convert
*
* @throws Exception If the processing fails unexpectedly.
* @return string
*/
public function getFileUrlForConvert();
/**
* Returns response body as string
*
* @param string $url Url for request.
* @param string $method Method of request.
* @param array $opts Options of request (headers, body).
* @throws Exception If the processing fails unexpectedly.
* @return string
*/
public function request(string $url, string $method, array $opts);
/**
* Returns error text by code from converting service.
*
* @param int $errorCode Code of error (See ConvertResponseError Util).
* @throws Exception If the processing fails unexpectedly.
* @return string
*/
public function processConvServResponceError(int $errorCode);
/**
* Returns error text by code from command service.
*
* @param int $errorCode Code of error (See CommandResponseError Util).
* @throws Exception If the processing fails unexpectedly.
* @return string
*/
public function processCommandServResponceError(int $errorCode);
/**
* Request health status of Document Server.
*
* @throws Exception If the processing fails unexpectedly.
* @return bool
*/
public function healthcheckRequest();
/**
* Request for conversion to a service. Returns response as array.
*
* @param string $documentUri - Uri for the document to convert
* @param string $fromExtension - Document extension
* @param string $toExtension - Extension to which to convert
* @param string $documentRevisionId - Key for caching on service
* @param bool - $isAsync - Perform conversions asynchronously
* @param string $region - Region value
* @throws Exception If the processing fails unexpectedly.
* @return array
*/
public function sendRequestToConvertService(
string $documentUri,
string $fromExtension,
string $toExtension,
string $documentRevisionId,
bool $isAsync,
string $region
);
/**
* The method is to convert the file to the required format and return the result url.
*
* @param string $documentUri - Uri for the document to convert
* @param string $fromExtension - Document extension
* @param string $toExtension - Extension to which to convert
* @param string $documentRevisionId - Key for caching on service
* @param string $region - Region value
* @throws Exception If the processing fails unexpectedly.
* @return string
*/
public function getConvertedUri(
string $documentUri,
string $fromExtension,
string $toExtension,
string $documentRevisionId,
string $region
);
/**
* Request health status of Document Server.
*
* @param string $method - type of command
* @throws Exception If the processing fails unexpectedly.
* @return array
*/
public function commandRequest(string $method);
/**
* Checking document service location
*
* @throws Exception If the processing fails unexpectedly.
* @return array
*/
public function checkDocServiceUrl();
}

View File

@@ -0,0 +1,67 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Util;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
abstract class BasicEnum
{
private static $constCacheArray = null;
private static function getConstants()
{
if (self::$constCacheArray == null) {
self::$constCacheArray = [];
}
$calledClass = get_called_class();
if (!array_key_exists($calledClass, self::$constCacheArray)) {
$reflect = new \ReflectionClass($calledClass);
self::$constCacheArray[$calledClass] = $reflect->getConstants();
}
return self::$constCacheArray[$calledClass];
}
public static function isValidName($name, $strict = false)
{
$constants = self::getConstants();
if ($strict) {
return array_key_exists($name, $constants);
}
$keys = array_map("strtolower", array_keys($constants));
return in_array(strtolower($name), $keys);
}
public static function isValidValue($value, $strict = true)
{
$values = array_values(self::getConstants());
return in_array($value, $values, $strict);
}
public function getValue()
{
return $this->value;
}
public function setValue($value)
{
$this->value = $value;
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Util;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Error messages.
*
* @package Onlyoffice\DocsIntegrationSdk\Util
*/
class CommandResponseError
{
const NO = 0;
const KEY = 1;
const CALLBACK_URL = 2;
const INTERNAL_SERVER = 3;
const FORCE_SAVE = 4;
const COMMAND = 5;
const TOKEN = 6;
public static function message($code): string
{
switch ($code) {
case self::NO:
return "No errors";
case self::KEY:
return "Document key is missing or no document with such key could be found";
case self::CALLBACK_URL:
return "Callback url not correct";
case self::FORCE_SAVE:
return "No changes were applied to the document before the forcesave command was received";
case self::INTERNAL_SERVER:
return "Internal server error";
case self::COMMAND:
return "Command not correct";
case self::TOKEN:
return "Invalid token";
default:
return "Unknown error";
}
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Util;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Error messages.
*
* @package Onlyoffice\DocsIntegrationSdk\Util
*/
class CommonError
{
const NO_HEALTHCHECK_ENDPOINT = 1;
const NO_DOCUMENT_SERVER_URL = 2;
const NO_CONVERT_SERVICE_ENDPOINT = 3;
const NO_JWT_HEADER = 4;
const NO_JWT_PREFIX = 5;
const READ_XML = 6;
const BAD_RESPONSE_XML = 7;
const NO_COMMAND_ENDPOINT = 8;
const MIXED_CONTENT = 9;
const BAD_HEALTHCHECK_STATUS = 10;
const DOC_SERVICE_ERROR = 11;
const NOT_SUPPORTED_VERSION = 12;
const EMPTY_FORMATS_ASSET = 13;
const FORMATS_ASSET_JSON_ERROR = 14;
const UNKNOWN_EXT = 15;
const FILE_TEMPLATE_IS_NOT_EXISTS = 16;
const NO_API_URL = 17;
const CALLBACK_NO_AUTH_TOKEN = 18;
const CALLBACK_NO_STATUS = 18;
public static function message($code): string
{
switch ($code) {
case self::NO_HEALTHCHECK_ENDPOINT:
return "There is no healthcheck endpoint in the application configuration";
case self::NO_DOCUMENT_SERVER_URL:
return "There is no document server URL in the application configuration";
case self::NO_CONVERT_SERVICE_ENDPOINT:
return "There is no convert service endpoint in the application configuration";
case self::NO_JWT_HEADER:
return "There is no JWT header in the application configuration";
case self::NO_JWT_PREFIX:
return "There is no JWT prefix in the application configuration";
case self::READ_XML:
return "Can't read XML";
case self::BAD_RESPONSE_XML:
return "Bad response";
case self::NO_COMMAND_ENDPOINT:
return "There is no command endpoint in the application configuration";
case self::MIXED_CONTENT:
return "Mixed Active Content is not allowed. HTTPS address for ONLYOFFICE Docs is required";
case self::BAD_HEALTHCHECK_STATUS:
return "Bad healthcheck status";
case self::DOC_SERVICE_ERROR:
return "Error occurred in the document service";
case self::NOT_SUPPORTED_VERSION:
return "Not supported version";
case self::EMPTY_FORMATS_ASSET:
return "Formats submodule error";
case self::FORMATS_ASSET_JSON_ERROR:
return "Formats submodule JSON error";
case self::UNKNOWN_EXT:
return "Unknown file extension";
case self::FILE_TEMPLATE_IS_NOT_EXISTS:
return "File template is not exists";
case self::NO_API_URL:
return "There is no document server API URL in the application configuration";
case self::CALLBACK_NO_AUTH_TOKEN:
return "Not found authorization token";
case self::CALLBACK_NO_STATUS:
return "Callback has no status";
default:
return "Unknown error";
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Util;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/**
* Error messages.
*
* @package Onlyoffice\DocsIntegrationSdk\Util
*/
class ConvertResponseError
{
const UNKNOWN = -1;
const TIMEOUT = -2;
const CONVERSION = -3;
const DOWNLOADING = -4;
const PASSWORD = -5;
const DATABASE = -6;
const INPUT = -7;
const TOKEN = -8;
public static function message($code): string
{
switch ($code) {
case self::UNKNOWN:
return "Unknown error";
case self::TIMEOUT:
return "Timeout conversion error";
case self::CONVERSION:
return "Conversion error";
case self::DOWNLOADING:
return "Error while downloading the document file to be converted";
case self::PASSWORD:
return "Incorrect password";
case self::DATABASE:
return "Error while accessing the conversion result database";
case self::INPUT:
return "Error document request";
case self::TOKEN:
return "Invalid token";
default:
return "Undefined error";
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Onlyoffice\DocsIntegrationSdk\Util;
/**
*
* (c) Copyright Ascensio System SIA 2024
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
use Dotenv\Dotenv;
/**
* ENV Utility.
*
* @package Onlyoffice\DocsIntegrationSdk\Util
*/
class EnvUtil
{
private const ENV_SETTINGS_PREFIX = "DOCS_INTEGRATION_SDK";
public function __construct()
{
static::loadEnvSettings();
}
public static function loadEnvSettings()
{
$dotenv = Dotenv::createImmutable(dirname(dirname(__DIR__)));
$dotenv->safeLoad();
}
public static function envKey($key)
{
return mb_strtoupper(self::ENV_SETTINGS_PREFIX . "_" . $key);
}
}

View File

@@ -0,0 +1,175 @@
<?php
/*
* Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace PhpOption;
use Traversable;
/**
* @template T
*
* @extends Option<T>
*/
final class LazyOption extends Option
{
/** @var callable(mixed...):(Option<T>) */
private $callback;
/** @var array<int, mixed> */
private $arguments;
/** @var Option<T>|null */
private $option;
/**
* @template S
* @param callable(mixed...):(Option<S>) $callback
* @param array<int, mixed> $arguments
*
* @return LazyOption<S>
*/
public static function create($callback, array $arguments = []): self
{
return new self($callback, $arguments);
}
/**
* @param callable(mixed...):(Option<T>) $callback
* @param array<int, mixed> $arguments
*/
public function __construct($callback, array $arguments = [])
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException('Invalid callback given');
}
$this->callback = $callback;
$this->arguments = $arguments;
}
public function isDefined(): bool
{
return $this->option()->isDefined();
}
public function isEmpty(): bool
{
return $this->option()->isEmpty();
}
public function get()
{
return $this->option()->get();
}
public function getOrElse($default)
{
return $this->option()->getOrElse($default);
}
public function getOrCall($callable)
{
return $this->option()->getOrCall($callable);
}
public function getOrThrow(\Exception $ex)
{
return $this->option()->getOrThrow($ex);
}
public function orElse(Option $else)
{
return $this->option()->orElse($else);
}
public function ifDefined($callable)
{
$this->option()->forAll($callable);
}
public function forAll($callable)
{
return $this->option()->forAll($callable);
}
public function map($callable)
{
return $this->option()->map($callable);
}
public function flatMap($callable)
{
return $this->option()->flatMap($callable);
}
public function filter($callable)
{
return $this->option()->filter($callable);
}
public function filterNot($callable)
{
return $this->option()->filterNot($callable);
}
public function select($value)
{
return $this->option()->select($value);
}
public function reject($value)
{
return $this->option()->reject($value);
}
/**
* @return Traversable<T>
*/
public function getIterator(): Traversable
{
return $this->option()->getIterator();
}
public function foldLeft($initialValue, $callable)
{
return $this->option()->foldLeft($initialValue, $callable);
}
public function foldRight($initialValue, $callable)
{
return $this->option()->foldRight($initialValue, $callable);
}
/**
* @return Option<T>
*/
private function option(): Option
{
if (null === $this->option) {
/** @var mixed */
$option = call_user_func_array($this->callback, $this->arguments);
if ($option instanceof Option) {
$this->option = $option;
} else {
throw new \RuntimeException(sprintf('Expected instance of %s', Option::class));
}
}
return $this->option;
}
}

View File

@@ -0,0 +1,136 @@
<?php
/*
* Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace PhpOption;
use EmptyIterator;
/**
* @extends Option<mixed>
*/
final class None extends Option
{
/** @var None|null */
private static $instance;
/**
* @return None
*/
public static function create(): self
{
if (null === self::$instance) {
self::$instance = new self();
}
return self::$instance;
}
public function get()
{
throw new \RuntimeException('None has no value.');
}
public function getOrCall($callable)
{
return $callable();
}
public function getOrElse($default)
{
return $default;
}
public function getOrThrow(\Exception $ex)
{
throw $ex;
}
public function isEmpty(): bool
{
return true;
}
public function isDefined(): bool
{
return false;
}
public function orElse(Option $else)
{
return $else;
}
public function ifDefined($callable)
{
// Just do nothing in that case.
}
public function forAll($callable)
{
return $this;
}
public function map($callable)
{
return $this;
}
public function flatMap($callable)
{
return $this;
}
public function filter($callable)
{
return $this;
}
public function filterNot($callable)
{
return $this;
}
public function select($value)
{
return $this;
}
public function reject($value)
{
return $this;
}
public function getIterator(): EmptyIterator
{
return new EmptyIterator();
}
public function foldLeft($initialValue, $callable)
{
return $initialValue;
}
public function foldRight($initialValue, $callable)
{
return $initialValue;
}
private function __construct()
{
}
}

View File

@@ -0,0 +1,434 @@
<?php
/*
* Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace PhpOption;
use ArrayAccess;
use IteratorAggregate;
/**
* @template T
*
* @implements IteratorAggregate<T>
*/
abstract class Option implements IteratorAggregate
{
/**
* Creates an option given a return value.
*
* This is intended for consuming existing APIs and allows you to easily
* convert them to an option. By default, we treat ``null`` as the None
* case, and everything else as Some.
*
* @template S
*
* @param S $value The actual return value.
* @param S $noneValue The value which should be considered "None"; null by
* default.
*
* @return Option<S>
*/
public static function fromValue($value, $noneValue = null)
{
if ($value === $noneValue) {
return None::create();
}
return new Some($value);
}
/**
* Creates an option from an array's value.
*
* If the key does not exist in the array, the array is not actually an
* array, or the array's value at the given key is null, None is returned.
* Otherwise, Some is returned wrapping the value at the given key.
*
* @template S
*
* @param array<string|int,S>|ArrayAccess<string|int,S>|null $array A potential array or \ArrayAccess value.
* @param string|int|null $key The key to check.
*
* @return Option<S>
*/
public static function fromArraysValue($array, $key)
{
if ($key === null || !(is_array($array) || $array instanceof ArrayAccess) || !isset($array[$key])) {
return None::create();
}
return new Some($array[$key]);
}
/**
* Creates a lazy-option with the given callback.
*
* This is also a helper constructor for lazy-consuming existing APIs where
* the return value is not yet an option. By default, we treat ``null`` as
* None case, and everything else as Some.
*
* @template S
*
* @param callable $callback The callback to evaluate.
* @param array $arguments The arguments for the callback.
* @param S $noneValue The value which should be considered "None";
* null by default.
*
* @return LazyOption<S>
*/
public static function fromReturn($callback, array $arguments = [], $noneValue = null)
{
return new LazyOption(static function () use ($callback, $arguments, $noneValue) {
/** @var mixed */
$return = call_user_func_array($callback, $arguments);
if ($return === $noneValue) {
return None::create();
}
return new Some($return);
});
}
/**
* Option factory, which creates new option based on passed value.
*
* If value is already an option, it simply returns. If value is callable,
* LazyOption with passed callback created and returned. If Option
* returned from callback, it returns directly. On other case value passed
* to Option::fromValue() method.
*
* @template S
*
* @param Option<S>|callable|S $value
* @param S $noneValue Used when $value is mixed or
* callable, for None-check.
*
* @return Option<S>|LazyOption<S>
*/
public static function ensure($value, $noneValue = null)
{
if ($value instanceof self) {
return $value;
} elseif (is_callable($value)) {
return new LazyOption(static function () use ($value, $noneValue) {
/** @var mixed */
$return = $value();
if ($return instanceof self) {
return $return;
} else {
return self::fromValue($return, $noneValue);
}
});
} else {
return self::fromValue($value, $noneValue);
}
}
/**
* Lift a function so that it accepts Option as parameters.
*
* We return a new closure that wraps the original callback. If any of the
* parameters passed to the lifted function is empty, the function will
* return a value of None. Otherwise, we will pass all parameters to the
* original callback and return the value inside a new Option, unless an
* Option is returned from the function, in which case, we use that.
*
* @template S
*
* @param callable $callback
* @param mixed $noneValue
*
* @return callable
*/
public static function lift($callback, $noneValue = null)
{
return static function () use ($callback, $noneValue) {
/** @var array<int, mixed> */
$args = func_get_args();
$reduced_args = array_reduce(
$args,
/** @param bool $status */
static function ($status, self $o) {
return $o->isEmpty() ? true : $status;
},
false
);
// if at least one parameter is empty, return None
if ($reduced_args) {
return None::create();
}
$args = array_map(
/** @return T */
static function (self $o) {
// it is safe to do so because the fold above checked
// that all arguments are of type Some
/** @var T */
return $o->get();
},
$args
);
return self::ensure(call_user_func_array($callback, $args), $noneValue);
};
}
/**
* Returns the value if available, or throws an exception otherwise.
*
* @throws \RuntimeException If value is not available.
*
* @return T
*/
abstract public function get();
/**
* Returns the value if available, or the default value if not.
*
* @template S
*
* @param S $default
*
* @return T|S
*/
abstract public function getOrElse($default);
/**
* Returns the value if available, or the results of the callable.
*
* This is preferable over ``getOrElse`` if the computation of the default
* value is expensive.
*
* @template S
*
* @param callable():S $callable
*
* @return T|S
*/
abstract public function getOrCall($callable);
/**
* Returns the value if available, or throws the passed exception.
*
* @param \Exception $ex
*
* @return T
*/
abstract public function getOrThrow(\Exception $ex);
/**
* Returns true if no value is available, false otherwise.
*
* @return bool
*/
abstract public function isEmpty();
/**
* Returns true if a value is available, false otherwise.
*
* @return bool
*/
abstract public function isDefined();
/**
* Returns this option if non-empty, or the passed option otherwise.
*
* This can be used to try multiple alternatives, and is especially useful
* with lazy evaluating options:
*
* ```php
* $repo->findSomething()
* ->orElse(new LazyOption(array($repo, 'findSomethingElse')))
* ->orElse(new LazyOption(array($repo, 'createSomething')));
* ```
*
* @param Option<T> $else
*
* @return Option<T>
*/
abstract public function orElse(self $else);
/**
* This is similar to map() below except that the return value has no meaning;
* the passed callable is simply executed if the option is non-empty, and
* ignored if the option is empty.
*
* In all cases, the return value of the callable is discarded.
*
* ```php
* $comment->getMaybeFile()->ifDefined(function($file) {
* // Do something with $file here.
* });
* ```
*
* If you're looking for something like ``ifEmpty``, you can use ``getOrCall``
* and ``getOrElse`` in these cases.
*
* @deprecated Use forAll() instead.
*
* @param callable(T):mixed $callable
*
* @return void
*/
abstract public function ifDefined($callable);
/**
* This is similar to map() except that the return value of the callable has no meaning.
*
* The passed callable is simply executed if the option is non-empty, and ignored if the
* option is empty. This method is preferred for callables with side-effects, while map()
* is intended for callables without side-effects.
*
* @param callable(T):mixed $callable
*
* @return Option<T>
*/
abstract public function forAll($callable);
/**
* Applies the callable to the value of the option if it is non-empty,
* and returns the return value of the callable wrapped in Some().
*
* If the option is empty, then the callable is not applied.
*
* ```php
* (new Some("foo"))->map('strtoupper')->get(); // "FOO"
* ```
*
* @template S
*
* @param callable(T):S $callable
*
* @return Option<S>
*/
abstract public function map($callable);
/**
* Applies the callable to the value of the option if it is non-empty, and
* returns the return value of the callable directly.
*
* In contrast to ``map``, the return value of the callable is expected to
* be an Option itself; it is not automatically wrapped in Some().
*
* @template S
*
* @param callable(T):Option<S> $callable must return an Option
*
* @return Option<S>
*/
abstract public function flatMap($callable);
/**
* If the option is empty, it is returned immediately without applying the callable.
*
* If the option is non-empty, the callable is applied, and if it returns true,
* the option itself is returned; otherwise, None is returned.
*
* @param callable(T):bool $callable
*
* @return Option<T>
*/
abstract public function filter($callable);
/**
* If the option is empty, it is returned immediately without applying the callable.
*
* If the option is non-empty, the callable is applied, and if it returns false,
* the option itself is returned; otherwise, None is returned.
*
* @param callable(T):bool $callable
*
* @return Option<T>
*/
abstract public function filterNot($callable);
/**
* If the option is empty, it is returned immediately.
*
* If the option is non-empty, and its value does not equal the passed value
* (via a shallow comparison ===), then None is returned. Otherwise, the
* Option is returned.
*
* In other words, this will filter all but the passed value.
*
* @param T $value
*
* @return Option<T>
*/
abstract public function select($value);
/**
* If the option is empty, it is returned immediately.
*
* If the option is non-empty, and its value does equal the passed value (via
* a shallow comparison ===), then None is returned; otherwise, the Option is
* returned.
*
* In other words, this will let all values through except the passed value.
*
* @param T $value
*
* @return Option<T>
*/
abstract public function reject($value);
/**
* Binary operator for the initial value and the option's value.
*
* If empty, the initial value is returned. If non-empty, the callable
* receives the initial value and the option's value as arguments.
*
* ```php
*
* $some = new Some(5);
* $none = None::create();
* $result = $some->foldLeft(1, function($a, $b) { return $a + $b; }); // int(6)
* $result = $none->foldLeft(1, function($a, $b) { return $a + $b; }); // int(1)
*
* // This can be used instead of something like the following:
* $option = Option::fromValue($integerOrNull);
* $result = 1;
* if ( ! $option->isEmpty()) {
* $result += $option->get();
* }
* ```
*
* @template S
*
* @param S $initialValue
* @param callable(S, T):S $callable
*
* @return S
*/
abstract public function foldLeft($initialValue, $callable);
/**
* foldLeft() but with reversed arguments for the callable.
*
* @template S
*
* @param S $initialValue
* @param callable(T, S):S $callable
*
* @return S
*/
abstract public function foldRight($initialValue, $callable);
}

View File

@@ -0,0 +1,169 @@
<?php
/*
* Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace PhpOption;
use ArrayIterator;
/**
* @template T
*
* @extends Option<T>
*/
final class Some extends Option
{
/** @var T */
private $value;
/**
* @param T $value
*/
public function __construct($value)
{
$this->value = $value;
}
/**
* @template U
*
* @param U $value
*
* @return Some<U>
*/
public static function create($value): self
{
return new self($value);
}
public function isDefined(): bool
{
return true;
}
public function isEmpty(): bool
{
return false;
}
public function get()
{
return $this->value;
}
public function getOrElse($default)
{
return $this->value;
}
public function getOrCall($callable)
{
return $this->value;
}
public function getOrThrow(\Exception $ex)
{
return $this->value;
}
public function orElse(Option $else)
{
return $this;
}
public function ifDefined($callable)
{
$this->forAll($callable);
}
public function forAll($callable)
{
$callable($this->value);
return $this;
}
public function map($callable)
{
return new self($callable($this->value));
}
public function flatMap($callable)
{
/** @var mixed */
$rs = $callable($this->value);
if (!$rs instanceof Option) {
throw new \RuntimeException('Callables passed to flatMap() must return an Option. Maybe you should use map() instead?');
}
return $rs;
}
public function filter($callable)
{
if (true === $callable($this->value)) {
return $this;
}
return None::create();
}
public function filterNot($callable)
{
if (false === $callable($this->value)) {
return $this;
}
return None::create();
}
public function select($value)
{
if ($this->value === $value) {
return $this;
}
return None::create();
}
public function reject($value)
{
if ($this->value === $value) {
return None::create();
}
return $this;
}
/**
* @return ArrayIterator<int, T>
*/
public function getIterator(): ArrayIterator
{
return new ArrayIterator([$this->value]);
}
public function foldLeft($initialValue, $callable)
{
return $callable($initialValue, $this->value);
}
public function foldRight($initialValue, $callable)
{
return $callable($this->value, $initialValue);
}
}

View File

@@ -0,0 +1,232 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Polyfill\Ctype;
/**
* Ctype implementation through regex.
*
* @internal
*
* @author Gert de Pagter <BackEndTea@gmail.com>
*/
final class Ctype
{
/**
* Returns TRUE if every character in text is either a letter or a digit, FALSE otherwise.
*
* @see https://php.net/ctype-alnum
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_alnum($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z0-9]/', $text);
}
/**
* Returns TRUE if every character in text is a letter, FALSE otherwise.
*
* @see https://php.net/ctype-alpha
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_alpha($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^A-Za-z]/', $text);
}
/**
* Returns TRUE if every character in text is a control character from the current locale, FALSE otherwise.
*
* @see https://php.net/ctype-cntrl
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_cntrl($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^\x00-\x1f\x7f]/', $text);
}
/**
* Returns TRUE if every character in the string text is a decimal digit, FALSE otherwise.
*
* @see https://php.net/ctype-digit
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_digit($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^0-9]/', $text);
}
/**
* Returns TRUE if every character in text is printable and actually creates visible output (no white space), FALSE otherwise.
*
* @see https://php.net/ctype-graph
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_graph($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^!-~]/', $text);
}
/**
* Returns TRUE if every character in text is a lowercase letter.
*
* @see https://php.net/ctype-lower
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_lower($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^a-z]/', $text);
}
/**
* Returns TRUE if every character in text will actually create output (including blanks). Returns FALSE if text contains control characters or characters that do not have any output or control function at all.
*
* @see https://php.net/ctype-print
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_print($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^ -~]/', $text);
}
/**
* Returns TRUE if every character in text is printable, but neither letter, digit or blank, FALSE otherwise.
*
* @see https://php.net/ctype-punct
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_punct($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^!-\/\:-@\[-`\{-~]/', $text);
}
/**
* Returns TRUE if every character in text creates some sort of white space, FALSE otherwise. Besides the blank character this also includes tab, vertical tab, line feed, carriage return and form feed characters.
*
* @see https://php.net/ctype-space
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_space($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^\s]/', $text);
}
/**
* Returns TRUE if every character in text is an uppercase letter.
*
* @see https://php.net/ctype-upper
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_upper($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^A-Z]/', $text);
}
/**
* Returns TRUE if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f] , FALSE otherwise.
*
* @see https://php.net/ctype-xdigit
*
* @param mixed $text
*
* @return bool
*/
public static function ctype_xdigit($text)
{
$text = self::convert_int_to_char_for_ctype($text, __FUNCTION__);
return \is_string($text) && '' !== $text && !preg_match('/[^A-Fa-f0-9]/', $text);
}
/**
* Converts integers to their char versions according to normal ctype behaviour, if needed.
*
* If an integer between -128 and 255 inclusive is provided,
* it is interpreted as the ASCII value of a single character
* (negative values have 256 added in order to allow characters in the Extended ASCII range).
* Any other integer is interpreted as a string containing the decimal digits of the integer.
*
* @param mixed $int
* @param string $function
*
* @return mixed
*/
private static function convert_int_to_char_for_ctype($int, $function)
{
if (!\is_int($int)) {
return $int;
}
if ($int < -128 || $int > 255) {
return (string) $int;
}
if (\PHP_VERSION_ID >= 80100) {
@trigger_error($function.'(): Argument of type int will be interpreted as string in the future', \E_USER_DEPRECATED);
}
if ($int < 0) {
$int += 256;
}
return \chr($int);
}
}

View File

@@ -0,0 +1,12 @@
Symfony Polyfill / Ctype
========================
This component provides `ctype_*` functions to users who run php versions without the ctype extension.
More information can be found in the
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
License
=======
This library is released under the [MIT license](LICENSE).

View File

@@ -0,0 +1,50 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Polyfill\Ctype as p;
if (\PHP_VERSION_ID >= 80000) {
return require __DIR__.'/bootstrap80.php';
}
if (!function_exists('ctype_alnum')) {
function ctype_alnum($text) { return p\Ctype::ctype_alnum($text); }
}
if (!function_exists('ctype_alpha')) {
function ctype_alpha($text) { return p\Ctype::ctype_alpha($text); }
}
if (!function_exists('ctype_cntrl')) {
function ctype_cntrl($text) { return p\Ctype::ctype_cntrl($text); }
}
if (!function_exists('ctype_digit')) {
function ctype_digit($text) { return p\Ctype::ctype_digit($text); }
}
if (!function_exists('ctype_graph')) {
function ctype_graph($text) { return p\Ctype::ctype_graph($text); }
}
if (!function_exists('ctype_lower')) {
function ctype_lower($text) { return p\Ctype::ctype_lower($text); }
}
if (!function_exists('ctype_print')) {
function ctype_print($text) { return p\Ctype::ctype_print($text); }
}
if (!function_exists('ctype_punct')) {
function ctype_punct($text) { return p\Ctype::ctype_punct($text); }
}
if (!function_exists('ctype_space')) {
function ctype_space($text) { return p\Ctype::ctype_space($text); }
}
if (!function_exists('ctype_upper')) {
function ctype_upper($text) { return p\Ctype::ctype_upper($text); }
}
if (!function_exists('ctype_xdigit')) {
function ctype_xdigit($text) { return p\Ctype::ctype_xdigit($text); }
}

View File

@@ -0,0 +1,46 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Polyfill\Ctype as p;
if (!function_exists('ctype_alnum')) {
function ctype_alnum(mixed $text): bool { return p\Ctype::ctype_alnum($text); }
}
if (!function_exists('ctype_alpha')) {
function ctype_alpha(mixed $text): bool { return p\Ctype::ctype_alpha($text); }
}
if (!function_exists('ctype_cntrl')) {
function ctype_cntrl(mixed $text): bool { return p\Ctype::ctype_cntrl($text); }
}
if (!function_exists('ctype_digit')) {
function ctype_digit(mixed $text): bool { return p\Ctype::ctype_digit($text); }
}
if (!function_exists('ctype_graph')) {
function ctype_graph(mixed $text): bool { return p\Ctype::ctype_graph($text); }
}
if (!function_exists('ctype_lower')) {
function ctype_lower(mixed $text): bool { return p\Ctype::ctype_lower($text); }
}
if (!function_exists('ctype_print')) {
function ctype_print(mixed $text): bool { return p\Ctype::ctype_print($text); }
}
if (!function_exists('ctype_punct')) {
function ctype_punct(mixed $text): bool { return p\Ctype::ctype_punct($text); }
}
if (!function_exists('ctype_space')) {
function ctype_space(mixed $text): bool { return p\Ctype::ctype_space($text); }
}
if (!function_exists('ctype_upper')) {
function ctype_upper(mixed $text): bool { return p\Ctype::ctype_upper($text); }
}
if (!function_exists('ctype_xdigit')) {
function ctype_xdigit(mixed $text): bool { return p\Ctype::ctype_xdigit($text); }
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,13 @@
Symfony Polyfill / Mbstring
===========================
This component provides a partial, native PHP implementation for the
[Mbstring](https://php.net/mbstring) extension.
More information can be found in the
[main Polyfill README](https://github.com/symfony/polyfill/blob/main/README.md).
License
=======
This library is released under the [MIT license](LICENSE).

View File

@@ -0,0 +1,119 @@
<?php
return [
'İ' => 'i̇',
'µ' => 'μ',
'ſ' => 's',
'ͅ' => 'ι',
'ς' => 'σ',
'ϐ' => 'β',
'ϑ' => 'θ',
'ϕ' => 'φ',
'ϖ' => 'π',
'ϰ' => 'κ',
'ϱ' => 'ρ',
'ϵ' => 'ε',
'ẛ' => 'ṡ',
'' => 'ι',
'ß' => 'ss',
'ʼn' => 'ʼn',
'ǰ' => 'ǰ',
'ΐ' => 'ΐ',
'ΰ' => 'ΰ',
'և' => 'եւ',
'ẖ' => 'ẖ',
'ẗ' => 'ẗ',
'ẘ' => 'ẘ',
'ẙ' => 'ẙ',
'ẚ' => 'aʾ',
'ẞ' => 'ss',
'ὐ' => 'ὐ',
'ὒ' => 'ὒ',
'ὔ' => 'ὔ',
'ὖ' => 'ὖ',
'ᾀ' => 'ἀι',
'ᾁ' => 'ἁι',
'ᾂ' => 'ἂι',
'ᾃ' => 'ἃι',
'ᾄ' => 'ἄι',
'ᾅ' => 'ἅι',
'ᾆ' => 'ἆι',
'ᾇ' => 'ἇι',
'ᾈ' => 'ἀι',
'ᾉ' => 'ἁι',
'ᾊ' => 'ἂι',
'ᾋ' => 'ἃι',
'ᾌ' => 'ἄι',
'ᾍ' => 'ἅι',
'ᾎ' => 'ἆι',
'ᾏ' => 'ἇι',
'ᾐ' => 'ἠι',
'ᾑ' => 'ἡι',
'ᾒ' => 'ἢι',
'ᾓ' => 'ἣι',
'ᾔ' => 'ἤι',
'ᾕ' => 'ἥι',
'ᾖ' => 'ἦι',
'ᾗ' => 'ἧι',
'ᾘ' => 'ἠι',
'ᾙ' => 'ἡι',
'ᾚ' => 'ἢι',
'ᾛ' => 'ἣι',
'ᾜ' => 'ἤι',
'ᾝ' => 'ἥι',
'ᾞ' => 'ἦι',
'ᾟ' => 'ἧι',
'ᾠ' => 'ὠι',
'ᾡ' => 'ὡι',
'ᾢ' => 'ὢι',
'ᾣ' => 'ὣι',
'ᾤ' => 'ὤι',
'ᾥ' => 'ὥι',
'ᾦ' => 'ὦι',
'ᾧ' => 'ὧι',
'ᾨ' => 'ὠι',
'ᾩ' => 'ὡι',
'ᾪ' => 'ὢι',
'ᾫ' => 'ὣι',
'ᾬ' => 'ὤι',
'ᾭ' => 'ὥι',
'ᾮ' => 'ὦι',
'ᾯ' => 'ὧι',
'ᾲ' => 'ὰι',
'ᾳ' => 'αι',
'ᾴ' => 'άι',
'ᾶ' => 'ᾶ',
'ᾷ' => 'ᾶι',
'ᾼ' => 'αι',
'ῂ' => 'ὴι',
'ῃ' => 'ηι',
'ῄ' => 'ήι',
'ῆ' => 'ῆ',
'ῇ' => 'ῆι',
'ῌ' => 'ηι',
'ῒ' => 'ῒ',
'ῖ' => 'ῖ',
'ῗ' => 'ῗ',
'ῢ' => 'ῢ',
'ῤ' => 'ῤ',
'ῦ' => 'ῦ',
'ῧ' => 'ῧ',
'ῲ' => 'ὼι',
'ῳ' => 'ωι',
'ῴ' => 'ώι',
'ῶ' => 'ῶ',
'ῷ' => 'ῶι',
'ῼ' => 'ωι',
'ff' => 'ff',
'fi' => 'fi',
'fl' => 'fl',
'ffi' => 'ffi',
'ffl' => 'ffl',
'ſt' => 'st',
'st' => 'st',
'ﬓ' => 'մն',
'ﬔ' => 'մե',
'ﬕ' => 'մի',
'ﬖ' => 'վն',
'ﬗ' => 'մխ',
];

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,172 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Polyfill\Mbstring as p;
if (\PHP_VERSION_ID >= 80000) {
return require __DIR__.'/bootstrap80.php';
}
if (!function_exists('mb_convert_encoding')) {
function mb_convert_encoding($string, $to_encoding, $from_encoding = null) { return p\Mbstring::mb_convert_encoding($string, $to_encoding, $from_encoding); }
}
if (!function_exists('mb_decode_mimeheader')) {
function mb_decode_mimeheader($string) { return p\Mbstring::mb_decode_mimeheader($string); }
}
if (!function_exists('mb_encode_mimeheader')) {
function mb_encode_mimeheader($string, $charset = null, $transfer_encoding = null, $newline = "\r\n", $indent = 0) { return p\Mbstring::mb_encode_mimeheader($string, $charset, $transfer_encoding, $newline, $indent); }
}
if (!function_exists('mb_decode_numericentity')) {
function mb_decode_numericentity($string, $map, $encoding = null) { return p\Mbstring::mb_decode_numericentity($string, $map, $encoding); }
}
if (!function_exists('mb_encode_numericentity')) {
function mb_encode_numericentity($string, $map, $encoding = null, $hex = false) { return p\Mbstring::mb_encode_numericentity($string, $map, $encoding, $hex); }
}
if (!function_exists('mb_convert_case')) {
function mb_convert_case($string, $mode, $encoding = null) { return p\Mbstring::mb_convert_case($string, $mode, $encoding); }
}
if (!function_exists('mb_internal_encoding')) {
function mb_internal_encoding($encoding = null) { return p\Mbstring::mb_internal_encoding($encoding); }
}
if (!function_exists('mb_language')) {
function mb_language($language = null) { return p\Mbstring::mb_language($language); }
}
if (!function_exists('mb_list_encodings')) {
function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); }
}
if (!function_exists('mb_encoding_aliases')) {
function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); }
}
if (!function_exists('mb_check_encoding')) {
function mb_check_encoding($value = null, $encoding = null) { return p\Mbstring::mb_check_encoding($value, $encoding); }
}
if (!function_exists('mb_detect_encoding')) {
function mb_detect_encoding($string, $encodings = null, $strict = false) { return p\Mbstring::mb_detect_encoding($string, $encodings, $strict); }
}
if (!function_exists('mb_detect_order')) {
function mb_detect_order($encoding = null) { return p\Mbstring::mb_detect_order($encoding); }
}
if (!function_exists('mb_parse_str')) {
function mb_parse_str($string, &$result = []) { parse_str($string, $result); return (bool) $result; }
}
if (!function_exists('mb_strlen')) {
function mb_strlen($string, $encoding = null) { return p\Mbstring::mb_strlen($string, $encoding); }
}
if (!function_exists('mb_strpos')) {
function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strpos($haystack, $needle, $offset, $encoding); }
}
if (!function_exists('mb_strtolower')) {
function mb_strtolower($string, $encoding = null) { return p\Mbstring::mb_strtolower($string, $encoding); }
}
if (!function_exists('mb_strtoupper')) {
function mb_strtoupper($string, $encoding = null) { return p\Mbstring::mb_strtoupper($string, $encoding); }
}
if (!function_exists('mb_substitute_character')) {
function mb_substitute_character($substitute_character = null) { return p\Mbstring::mb_substitute_character($substitute_character); }
}
if (!function_exists('mb_substr')) {
function mb_substr($string, $start, $length = 2147483647, $encoding = null) { return p\Mbstring::mb_substr($string, $start, $length, $encoding); }
}
if (!function_exists('mb_stripos')) {
function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_stripos($haystack, $needle, $offset, $encoding); }
}
if (!function_exists('mb_stristr')) {
function mb_stristr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_stristr($haystack, $needle, $before_needle, $encoding); }
}
if (!function_exists('mb_strrchr')) {
function mb_strrchr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrchr($haystack, $needle, $before_needle, $encoding); }
}
if (!function_exists('mb_strrichr')) {
function mb_strrichr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strrichr($haystack, $needle, $before_needle, $encoding); }
}
if (!function_exists('mb_strripos')) {
function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strripos($haystack, $needle, $offset, $encoding); }
}
if (!function_exists('mb_strrpos')) {
function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) { return p\Mbstring::mb_strrpos($haystack, $needle, $offset, $encoding); }
}
if (!function_exists('mb_strstr')) {
function mb_strstr($haystack, $needle, $before_needle = false, $encoding = null) { return p\Mbstring::mb_strstr($haystack, $needle, $before_needle, $encoding); }
}
if (!function_exists('mb_get_info')) {
function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); }
}
if (!function_exists('mb_http_output')) {
function mb_http_output($encoding = null) { return p\Mbstring::mb_http_output($encoding); }
}
if (!function_exists('mb_strwidth')) {
function mb_strwidth($string, $encoding = null) { return p\Mbstring::mb_strwidth($string, $encoding); }
}
if (!function_exists('mb_substr_count')) {
function mb_substr_count($haystack, $needle, $encoding = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $encoding); }
}
if (!function_exists('mb_output_handler')) {
function mb_output_handler($string, $status) { return p\Mbstring::mb_output_handler($string, $status); }
}
if (!function_exists('mb_http_input')) {
function mb_http_input($type = null) { return p\Mbstring::mb_http_input($type); }
}
if (!function_exists('mb_convert_variables')) {
function mb_convert_variables($to_encoding, $from_encoding, &...$vars) { return p\Mbstring::mb_convert_variables($to_encoding, $from_encoding, ...$vars); }
}
if (!function_exists('mb_ord')) {
function mb_ord($string, $encoding = null) { return p\Mbstring::mb_ord($string, $encoding); }
}
if (!function_exists('mb_chr')) {
function mb_chr($codepoint, $encoding = null) { return p\Mbstring::mb_chr($codepoint, $encoding); }
}
if (!function_exists('mb_scrub')) {
function mb_scrub($string, $encoding = null) { $encoding = null === $encoding ? mb_internal_encoding() : $encoding; return mb_convert_encoding($string, $encoding, $encoding); }
}
if (!function_exists('mb_str_split')) {
function mb_str_split($string, $length = 1, $encoding = null) { return p\Mbstring::mb_str_split($string, $length, $encoding); }
}
if (!function_exists('mb_str_pad')) {
function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, ?string $encoding = null): string { return p\Mbstring::mb_str_pad($string, $length, $pad_string, $pad_type, $encoding); }
}
if (!function_exists('mb_ucfirst')) {
function mb_ucfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_ucfirst($string, $encoding); }
}
if (!function_exists('mb_lcfirst')) {
function mb_lcfirst(string $string, ?string $encoding = null): string { return p\Mbstring::mb_lcfirst($string, $encoding); }
}
if (!function_exists('mb_trim')) {
function mb_trim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_trim($string, $characters, $encoding); }
}
if (!function_exists('mb_ltrim')) {
function mb_ltrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_ltrim($string, $characters, $encoding); }
}
if (!function_exists('mb_rtrim')) {
function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_rtrim($string, $characters, $encoding); }
}
if (extension_loaded('mbstring')) {
return;
}
if (!defined('MB_CASE_UPPER')) {
define('MB_CASE_UPPER', 0);
}
if (!defined('MB_CASE_LOWER')) {
define('MB_CASE_LOWER', 1);
}
if (!defined('MB_CASE_TITLE')) {
define('MB_CASE_TITLE', 2);
}

View File

@@ -0,0 +1,167 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Symfony\Polyfill\Mbstring as p;
if (!function_exists('mb_convert_encoding')) {
function mb_convert_encoding(array|string|null $string, ?string $to_encoding, array|string|null $from_encoding = null): array|string|false { return p\Mbstring::mb_convert_encoding($string ?? '', (string) $to_encoding, $from_encoding); }
}
if (!function_exists('mb_decode_mimeheader')) {
function mb_decode_mimeheader(?string $string): string { return p\Mbstring::mb_decode_mimeheader((string) $string); }
}
if (!function_exists('mb_encode_mimeheader')) {
function mb_encode_mimeheader(?string $string, ?string $charset = null, ?string $transfer_encoding = null, ?string $newline = "\r\n", ?int $indent = 0): string { return p\Mbstring::mb_encode_mimeheader((string) $string, $charset, $transfer_encoding, (string) $newline, (int) $indent); }
}
if (!function_exists('mb_decode_numericentity')) {
function mb_decode_numericentity(?string $string, array $map, ?string $encoding = null): string { return p\Mbstring::mb_decode_numericentity((string) $string, $map, $encoding); }
}
if (!function_exists('mb_encode_numericentity')) {
function mb_encode_numericentity(?string $string, array $map, ?string $encoding = null, ?bool $hex = false): string { return p\Mbstring::mb_encode_numericentity((string) $string, $map, $encoding, (bool) $hex); }
}
if (!function_exists('mb_convert_case')) {
function mb_convert_case(?string $string, ?int $mode, ?string $encoding = null): string { return p\Mbstring::mb_convert_case((string) $string, (int) $mode, $encoding); }
}
if (!function_exists('mb_internal_encoding')) {
function mb_internal_encoding(?string $encoding = null): string|bool { return p\Mbstring::mb_internal_encoding($encoding); }
}
if (!function_exists('mb_language')) {
function mb_language(?string $language = null): string|bool { return p\Mbstring::mb_language($language); }
}
if (!function_exists('mb_list_encodings')) {
function mb_list_encodings(): array { return p\Mbstring::mb_list_encodings(); }
}
if (!function_exists('mb_encoding_aliases')) {
function mb_encoding_aliases(?string $encoding): array { return p\Mbstring::mb_encoding_aliases((string) $encoding); }
}
if (!function_exists('mb_check_encoding')) {
function mb_check_encoding(array|string|null $value = null, ?string $encoding = null): bool { return p\Mbstring::mb_check_encoding($value, $encoding); }
}
if (!function_exists('mb_detect_encoding')) {
function mb_detect_encoding(?string $string, array|string|null $encodings = null, ?bool $strict = false): string|false { return p\Mbstring::mb_detect_encoding((string) $string, $encodings, (bool) $strict); }
}
if (!function_exists('mb_detect_order')) {
function mb_detect_order(array|string|null $encoding = null): array|bool { return p\Mbstring::mb_detect_order($encoding); }
}
if (!function_exists('mb_parse_str')) {
function mb_parse_str(?string $string, &$result = []): bool { parse_str((string) $string, $result); return (bool) $result; }
}
if (!function_exists('mb_strlen')) {
function mb_strlen(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strlen((string) $string, $encoding); }
}
if (!function_exists('mb_strpos')) {
function mb_strpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strpos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
}
if (!function_exists('mb_strtolower')) {
function mb_strtolower(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtolower((string) $string, $encoding); }
}
if (!function_exists('mb_strtoupper')) {
function mb_strtoupper(?string $string, ?string $encoding = null): string { return p\Mbstring::mb_strtoupper((string) $string, $encoding); }
}
if (!function_exists('mb_substitute_character')) {
function mb_substitute_character(string|int|null $substitute_character = null): string|int|bool { return p\Mbstring::mb_substitute_character($substitute_character); }
}
if (!function_exists('mb_substr')) {
function mb_substr(?string $string, ?int $start, ?int $length = null, ?string $encoding = null): string { return p\Mbstring::mb_substr((string) $string, (int) $start, $length, $encoding); }
}
if (!function_exists('mb_stripos')) {
function mb_stripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_stripos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
}
if (!function_exists('mb_stristr')) {
function mb_stristr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_stristr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
}
if (!function_exists('mb_strrchr')) {
function mb_strrchr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrchr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
}
if (!function_exists('mb_strrichr')) {
function mb_strrichr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strrichr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
}
if (!function_exists('mb_strripos')) {
function mb_strripos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strripos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
}
if (!function_exists('mb_strrpos')) {
function mb_strrpos(?string $haystack, ?string $needle, ?int $offset = 0, ?string $encoding = null): int|false { return p\Mbstring::mb_strrpos((string) $haystack, (string) $needle, (int) $offset, $encoding); }
}
if (!function_exists('mb_strstr')) {
function mb_strstr(?string $haystack, ?string $needle, ?bool $before_needle = false, ?string $encoding = null): string|false { return p\Mbstring::mb_strstr((string) $haystack, (string) $needle, (bool) $before_needle, $encoding); }
}
if (!function_exists('mb_get_info')) {
function mb_get_info(?string $type = 'all'): array|string|int|false|null { return p\Mbstring::mb_get_info((string) $type); }
}
if (!function_exists('mb_http_output')) {
function mb_http_output(?string $encoding = null): string|bool { return p\Mbstring::mb_http_output($encoding); }
}
if (!function_exists('mb_strwidth')) {
function mb_strwidth(?string $string, ?string $encoding = null): int { return p\Mbstring::mb_strwidth((string) $string, $encoding); }
}
if (!function_exists('mb_substr_count')) {
function mb_substr_count(?string $haystack, ?string $needle, ?string $encoding = null): int { return p\Mbstring::mb_substr_count((string) $haystack, (string) $needle, $encoding); }
}
if (!function_exists('mb_output_handler')) {
function mb_output_handler(?string $string, ?int $status): string { return p\Mbstring::mb_output_handler((string) $string, (int) $status); }
}
if (!function_exists('mb_http_input')) {
function mb_http_input(?string $type = null): array|string|false { return p\Mbstring::mb_http_input($type); }
}
if (!function_exists('mb_convert_variables')) {
function mb_convert_variables(?string $to_encoding, array|string|null $from_encoding, mixed &$var, mixed &...$vars): string|false { return p\Mbstring::mb_convert_variables((string) $to_encoding, $from_encoding ?? '', $var, ...$vars); }
}
if (!function_exists('mb_ord')) {
function mb_ord(?string $string, ?string $encoding = null): int|false { return p\Mbstring::mb_ord((string) $string, $encoding); }
}
if (!function_exists('mb_chr')) {
function mb_chr(?int $codepoint, ?string $encoding = null): string|false { return p\Mbstring::mb_chr((int) $codepoint, $encoding); }
}
if (!function_exists('mb_scrub')) {
function mb_scrub(?string $string, ?string $encoding = null): string { $encoding ??= mb_internal_encoding(); return mb_convert_encoding((string) $string, $encoding, $encoding); }
}
if (!function_exists('mb_str_split')) {
function mb_str_split(?string $string, ?int $length = 1, ?string $encoding = null): array { return p\Mbstring::mb_str_split((string) $string, (int) $length, $encoding); }
}
if (!function_exists('mb_str_pad')) {
function mb_str_pad(string $string, int $length, string $pad_string = ' ', int $pad_type = STR_PAD_RIGHT, ?string $encoding = null): string { return p\Mbstring::mb_str_pad($string, $length, $pad_string, $pad_type, $encoding); }
}
if (!function_exists('mb_ucfirst')) {
function mb_ucfirst($string, ?string $encoding = null): string { return p\Mbstring::mb_ucfirst($string, $encoding); }
}
if (!function_exists('mb_lcfirst')) {
function mb_lcfirst($string, ?string $encoding = null): string { return p\Mbstring::mb_lcfirst($string, $encoding); }
}
if (!function_exists('mb_trim')) {
function mb_trim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_trim($string, $characters, $encoding); }
}
if (!function_exists('mb_ltrim')) {
function mb_ltrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_ltrim($string, $characters, $encoding); }
}
if (!function_exists('mb_rtrim')) {
function mb_rtrim(string $string, ?string $characters = null, ?string $encoding = null): string { return p\Mbstring::mb_rtrim($string, $characters, $encoding); }
}
if (extension_loaded('mbstring')) {
return;
}
if (!defined('MB_CASE_UPPER')) {
define('MB_CASE_UPPER', 0);
}
if (!defined('MB_CASE_LOWER')) {
define('MB_CASE_LOWER', 1);
}
if (!defined('MB_CASE_TITLE')) {
define('MB_CASE_TITLE', 2);
}

View File

@@ -0,0 +1,115 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Polyfill\Php80;
/**
* @author Ion Bazan <ion.bazan@gmail.com>
* @author Nico Oelgart <nicoswd@gmail.com>
* @author Nicolas Grekas <p@tchwork.com>
*
* @internal
*/
final class Php80
{
public static function fdiv(float $dividend, float $divisor): float
{
return @($dividend / $divisor);
}
public static function get_debug_type($value): string
{
switch (true) {
case null === $value: return 'null';
case \is_bool($value): return 'bool';
case \is_string($value): return 'string';
case \is_array($value): return 'array';
case \is_int($value): return 'int';
case \is_float($value): return 'float';
case \is_object($value): break;
case $value instanceof \__PHP_Incomplete_Class: return '__PHP_Incomplete_Class';
default:
if (null === $type = @get_resource_type($value)) {
return 'unknown';
}
if ('Unknown' === $type) {
$type = 'closed';
}
return "resource ($type)";
}
$class = \get_class($value);
if (false === strpos($class, '@')) {
return $class;
}
return (get_parent_class($class) ?: key(class_implements($class)) ?: 'class').'@anonymous';
}
public static function get_resource_id($res): int
{
if (!\is_resource($res) && null === @get_resource_type($res)) {
throw new \TypeError(sprintf('Argument 1 passed to get_resource_id() must be of the type resource, %s given', get_debug_type($res)));
}
return (int) $res;
}
public static function preg_last_error_msg(): string
{
switch (preg_last_error()) {
case \PREG_INTERNAL_ERROR:
return 'Internal error';
case \PREG_BAD_UTF8_ERROR:
return 'Malformed UTF-8 characters, possibly incorrectly encoded';
case \PREG_BAD_UTF8_OFFSET_ERROR:
return 'The offset did not correspond to the beginning of a valid UTF-8 code point';
case \PREG_BACKTRACK_LIMIT_ERROR:
return 'Backtrack limit exhausted';
case \PREG_RECURSION_LIMIT_ERROR:
return 'Recursion limit exhausted';
case \PREG_JIT_STACKLIMIT_ERROR:
return 'JIT stack limit exhausted';
case \PREG_NO_ERROR:
return 'No error';
default:
return 'Unknown error';
}
}
public static function str_contains(string $haystack, string $needle): bool
{
return '' === $needle || false !== strpos($haystack, $needle);
}
public static function str_starts_with(string $haystack, string $needle): bool
{
return 0 === strncmp($haystack, $needle, \strlen($needle));
}
public static function str_ends_with(string $haystack, string $needle): bool
{
if ('' === $needle || $needle === $haystack) {
return true;
}
if ('' === $haystack) {
return false;
}
$needleLength = \strlen($needle);
return $needleLength <= \strlen($haystack) && 0 === substr_compare($haystack, $needle, -$needleLength);
}
}

View File

@@ -0,0 +1,103 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Polyfill\Php80;
/**
* @author Fedonyuk Anton <info@ensostudio.ru>
*
* @internal
*/
class PhpToken implements \Stringable
{
/**
* @var int
*/
public $id;
/**
* @var string
*/
public $text;
/**
* @var int
*/
public $line;
/**
* @var int
*/
public $pos;
public function __construct(int $id, string $text, int $line = -1, int $position = -1)
{
$this->id = $id;
$this->text = $text;
$this->line = $line;
$this->pos = $position;
}
public function getTokenName(): ?string
{
if ('UNKNOWN' === $name = token_name($this->id)) {
$name = \strlen($this->text) > 1 || \ord($this->text) < 32 ? null : $this->text;
}
return $name;
}
/**
* @param int|string|array $kind
*/
public function is($kind): bool
{
foreach ((array) $kind as $value) {
if (\in_array($value, [$this->id, $this->text], true)) {
return true;
}
}
return false;
}
public function isIgnorable(): bool
{
return \in_array($this->id, [\T_WHITESPACE, \T_COMMENT, \T_DOC_COMMENT, \T_OPEN_TAG], true);
}
public function __toString(): string
{
return (string) $this->text;
}
/**
* @return static[]
*/
public static function tokenize(string $code, int $flags = 0): array
{
$line = 1;
$position = 0;
$tokens = token_get_all($code, $flags);
foreach ($tokens as $index => $token) {
if (\is_string($token)) {
$id = \ord($token);
$text = $token;
} else {
[$id, $text, $line] = $token;
}
$tokens[$index] = new static($id, $text, $line, $position);
$position += \strlen($text);
}
return $tokens;
}
}

Some files were not shown because too many files have changed in this diff Show More