• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aimeos / aimeos-core / a084ab96-f2bd-4717-8234-f3a880500f28

22 Sep 2024 08:23AM UTC coverage: 91.637% (-0.1%) from 91.75%
a084ab96-f2bd-4717-8234-f3a880500f28

push

circleci

aimeos
Use decorators for supplier managers to handle related items

1 of 1 new or added line in 1 file covered. (100.0%)

4 existing lines in 1 file now uncovered.

9544 of 10415 relevant lines covered (91.64%)

77.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.0
/src/MShop/Service/Manager/Base.php
1
<?php
2

3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2024
7
 * @package MShop
8
 * @subpackage Service
9
 */
10

11

12
namespace Aimeos\MShop\Service\Manager;
13

14

15
/**
16
 * Abstract class for service managers.
17
 *
18
 * @package MShop
19
 * @subpackage Service
20
 */
21
abstract class Base
22
        extends \Aimeos\MShop\Common\Manager\Base
23
{
24
        /**
25
         * Returns the service provider which is responsible for the service item.
26
         *
27
         * @param \Aimeos\MShop\Service\Item\Iface $item Delivery or payment service item object
28
         * @param string $type Service type code
29
         * @return \Aimeos\MShop\Service\Provider\Iface Service provider object
30
         * @throws \LogicException If provider couldn't be found
31
         */
32
        public function getProvider( \Aimeos\MShop\Service\Item\Iface $item, string $type ) : \Aimeos\MShop\Service\Provider\Iface
33
        {
34
                $type = ucwords( $type );
13✔
35
                $context = $this->context();
13✔
36
                $names = explode( ',', $item->getProvider() );
13✔
37

38
                if( ctype_alnum( $type ) === false ) {
13✔
UNCOV
39
                        throw new \LogicException( sprintf( 'Invalid characters in type name "%1$s"', $type ), 400 );
×
40
                }
41

42
                if( ( $provider = array_shift( $names ) ) === null ) {
13✔
UNCOV
43
                        throw new \LogicException( sprintf( 'Provider in "%1$s" not available', $item->getProvider() ), 400 );
×
44
                }
45

46
                if( ctype_alnum( $provider ) === false ) {
13✔
47
                        throw new \LogicException( sprintf( 'Invalid characters in provider name "%1$s"', $provider ), 400 );
1✔
48
                }
49

50
                $classname = '\Aimeos\MShop\Service\Provider\\' . $type . '\\' . $provider;
13✔
51
                $interface = \Aimeos\MShop\Service\Provider\Factory\Iface::class;
13✔
52

53
                $provider = \Aimeos\Utils::create( $classname, [$context, $item], $interface );
13✔
54

55
                /** mshop/service/provider/delivery/decorators
56
                 * Adds a list of decorators to all delivery provider objects automatcally
57
                 *
58
                 * Decorators extend the functionality of a class by adding new aspects
59
                 * (e.g. log what is currently done), executing the methods of the underlying
60
                 * class only in certain conditions (e.g. only for logged in users) or
61
                 * modify what is returned to the caller.
62
                 *
63
                 * This option allows you to wrap decorators
64
                 * ("\Aimeos\MShop\Service\Provider\Decorator\*") around the delivery provider.
65
                 *
66
                 *  mshop/service/provider/delivery/decorators = array( 'decorator1' )
67
                 *
68
                 * This would add the decorator named "decorator1" defined by
69
                 * "\Aimeos\MShop\Service\Provider\Decorator\Decorator1" to all delivery provider
70
                 * objects.
71
                 *
72
                 * @param array List of decorator names
73
                 * @since 2014.03
74
                 * @see mshop/service/provider/payment/decorators
75
                 */
76

77
                /** mshop/service/provider/payment/decorators
78
                 * Adds a list of decorators to all payment provider objects automatcally
79
                 *
80
                 * Decorators extend the functionality of a class by adding new aspects
81
                 * (e.g. log what is currently done), executing the methods of the underlying
82
                 * class only in certain conditions (e.g. only for logged in users) or
83
                 * modify what is returned to the caller.
84
                 *
85
                 * This option allows you to wrap decorators
86
                 * ("\Aimeos\MShop\Service\Provider\Decorator\*") around the payment provider.
87
                 *
88
                 *  mshop/service/provider/payment/decorators = array( 'decorator1' )
89
                 *
90
                 * This would add the decorator named "decorator1" defined by
91
                 * "\Aimeos\MShop\Service\Provider\Decorator\Decorator1" to all payment provider
92
                 * objects.
93
                 *
94
                 * @param array List of decorator names
95
                 * @since 2014.03
96
                 * @see mshop/service/provider/delivery/decorators
97
                 */
98
                $decorators = $context->config()->get( 'mshop/service/provider/' . $item->getType() . '/decorators', [] );
13✔
99

100
                $provider = $this->addServiceDecorators( $item, $provider, $names );
13✔
101
                return $this->addServiceDecorators( $item, $provider, $decorators );
13✔
102
        }
103

104

105
        /**
106
         * Wraps the named service decorators around the service provider.
107
         *
108
         * @param \Aimeos\MShop\Service\Item\Iface $serviceItem Service item object
109
         * @param \Aimeos\MShop\Service\Provider\Iface $provider Service provider object
110
         * @param array $names List of decorator names that should be wrapped around the provider object
111
         * @return \Aimeos\MShop\Service\Provider\Iface
112
         */
113
        protected function addServiceDecorators( \Aimeos\MShop\Service\Item\Iface $serviceItem,
114
                \Aimeos\MShop\Service\Provider\Iface $provider, array $names ) : \Aimeos\MShop\Service\Provider\Iface
115
        {
116
                $context = $this->context();
13✔
117
                $classprefix = '\Aimeos\MShop\Service\Provider\Decorator\\';
13✔
118

119
                foreach( $names as $name )
13✔
120
                {
121
                        if( ctype_alnum( $name ) === false )
1✔
122
                        {
UNCOV
123
                                $msg = $context->translate( 'mshop', 'Invalid characters in class name "%1$s"' );
×
UNCOV
124
                                throw new \Aimeos\MShop\Service\Exception( sprintf( $msg, $name ), 400 );
×
125
                        }
126

127
                        $classname = $classprefix . $name;
1✔
128
                        $interface = \Aimeos\MShop\Service\Provider\Decorator\Iface::class;
1✔
129

130
                        $provider = \Aimeos\Utils::create( $classname, [$provider, $context, $serviceItem], $interface );
1✔
131
                }
132

133
                return $provider;
13✔
134
        }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc