first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-06-08 17:09:23 -04:00
commit df3a033196
17887 changed files with 8637778 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
<?php
/**
* @file classes/core/maps/Base.php
*
* Copyright (c) 2014-2020 Simon Fraser University
* Copyright (c) 2000-2020 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class Base
*
* @brief A base class for creating extensible maps of any kind.
*/
namespace PKP\core\maps;
abstract class Base
{
/** @var array Callbacks that should be applied to each object in the map. */
protected $extensions = [];
/**
* Extend the map with a custom callback function
*
* Example:
*
* $map->extend(function($output, $input, $map) {
* $output['example'] = $input->example;
* return $output;
* })
*
*/
public function extend(callable $cb): self
{
$this->extensions[] = $cb;
return $this;
}
/**
* Run extensions applied to this map
*
* Run the callback functions registered with extend.
*
* @param mixed $output The output the object is being mapped to
* @param mixed $input The object that is being mapped from
*/
protected function withExtensions($output, $input)
{
foreach ($this->extensions as $extension) {
$output = call_user_func($extension, $output, $input, $this);
}
return $output;
}
}
+77
View File
@@ -0,0 +1,77 @@
<?php
/**
* @file classes/core/maps/Schema.php
*
* Copyright (c) 2014-2020 Simon Fraser University
* Copyright (c) 2000-2020 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class schema
*
* @brief A base class for mapping objects to their schema properties
*/
namespace PKP\core\maps;
use Illuminate\Support\Enumerable;
use PKP\context\Context;
use PKP\core\PKPApplication;
use PKP\core\PKPRequest;
use PKP\services\PKPSchemaService;
abstract class Schema extends Base
{
public PKPRequest $request;
public ?Context $context;
public PKPSchemaService $schemaService;
/** The collection of objects being mapped. Null if only one item is being mapped. */
public Enumerable $collection;
/** The property names for a summary of this entity according to its schema */
public array $summaryProps;
/** The property names of this entity according to its schema */
public array $props;
/** The name of the schema for this entity. One of the \PKP\services\PKPSchemaService::SCHEMA_... constants */
public string $schema;
public function __construct(PKPRequest $request, ?Context $context, PKPSchemaService $schemaService)
{
$this->request = $request;
$this->context = $context;
$this->schemaService = $schemaService;
}
/**
* Get the property names of this entity according to its schema
*/
protected function getProps(): array
{
return $this->props ?? $this->schemaService->getFullProps($this->schema);
}
/**
* Get the property names for a summary of this entity according to its schema
*/
protected function getSummaryProps(): array
{
return $this->summaryProps ?? $this->schemaService->getSummaryProps($this->schema);
}
/**
* Get the URL to an object in the REST API
*/
protected function getApiUrl(string $route, $contextPath = PKPApplication::CONTEXT_ID_ALL): string
{
return $this->request->getDispatcher()->url(
$this->request,
PKPApplication::ROUTE_API,
$contextPath,
$route,
);
}
}