Initial commit

This commit is contained in:
root
2026-01-19 17:44:46 +01:00
commit 823af8b11d
8721 changed files with 1130846 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Field\Address;
use Espo\ORM\Value\AttributeExtractor;
use Espo\Core\Field\Address;
use stdClass;
use InvalidArgumentException;
/**
* @implements AttributeExtractor<Address>
*/
class AddressAttributeExtractor implements AttributeExtractor
{
public function extract(object $value, string $field): stdClass
{
if (!$value instanceof Address) {
throw new InvalidArgumentException();
}
return (object) [
$field . 'Street' => $value->getStreet(),
$field . 'City' => $value->getCity(),
$field . 'Country' => $value->getCountry(),
$field . 'State' => $value->getState(),
$field . 'PostalCode' => $value->getPostalCode(),
];
}
public function extractFromNull(string $field): stdClass
{
return (object) [
$field . 'Street' => null,
$field . 'City' => null,
$field . 'Country' => null,
$field . 'State' => null,
$field . 'PostalCode' => null,
];
}
}

View File

@@ -0,0 +1,105 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Field\Address;
use Espo\Core\Field\Address;
/**
* An address value builder.
*/
class AddressBuilder
{
private ?string $street;
private ?string $city;
private ?string $country;
private ?string $state;
private ?string $postalCode;
public function clone(Address $address): self
{
$this->setStreet($address->getStreet());
$this->setCity($address->getCity());
$this->setCountry($address->getCountry());
$this->setState($address->getState());
$this->setPostalCode($address->getPostalCode());
return $this;
}
public function setStreet(?string $street): self
{
$this->street = $street;
return $this;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
public function setCountry(?string $country): self
{
$this->country = $country;
return $this;
}
public function setState(?string $state): self
{
$this->state = $state;
return $this;
}
public function setPostalCode(?string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
public function build(): Address
{
return new Address(
$this->country,
$this->state,
$this->city,
$this->street,
$this->postalCode
);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Field\Address;
use Espo\ORM\Entity;
use Espo\ORM\Value\ValueFactory;
use Espo\Core\Field\Address;
class AddressFactory implements ValueFactory
{
public function isCreatableFromEntity(Entity $entity, string $field): bool
{
return true;
}
public function createFromEntity(Entity $entity, string $field): Address
{
return (new AddressBuilder())
->setStreet($entity->get($field . 'Street'))
->setCity($entity->get($field . 'City'))
->setCountry($entity->get($field . 'Country'))
->setState($entity->get($field . 'State'))
->setPostalCode($entity->get($field . 'PostalCode'))
->build();
}
}

View File

@@ -0,0 +1,40 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Field\Address;
use Espo\Core\Field\Address;
/**
* An address formatter.
*/
interface AddressFormatter
{
public function format(Address $address): string;
}

View File

@@ -0,0 +1,63 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Field\Address;
use RuntimeException;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\Config;
class AddressFormatterFactory
{
public function __construct(
private AddressFormatterMetadataProvider $metadataProvider,
private InjectableFactory $injectableFactory,
private Config $config
) {}
public function create(int $format): AddressFormatter
{
/** @var ?class-string<AddressFormatter> $className */
$className = $this->metadataProvider->getFormatterClassName($format);
if (!$className) {
throw new RuntimeException("Unknown address format '{$format}'.");
}
return $this->injectableFactory->create($className);
}
public function createDefault(): AddressFormatter
{
$format = $this->config->get('addressFormat') ?? 1;
return $this->create($format);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Field\Address;
use Espo\Core\Utils\Metadata;
class AddressFormatterMetadataProvider
{
private $metadata;
public function __construct(Metadata $metadata)
{
$this->metadata = $metadata;
}
public function getFormatterClassName(int $format): ?string
{
return $this->metadata->get([
'app', 'addressFormats', strval($format), 'formatterClassName',
]);
}
}