# payplug/3.1.0/src/Traits/ServiceGetter.php

PayPlug for WooCommerce (Official), version 3.1.0. 61 lines.

- Page: https://pluginprobe.com/plugins/payplug/3.1.0/code/src/Traits/ServiceGetter.php
- Raw: https://pluginprobe.com/plugins/payplug/3.1.0/raw/src/Traits/ServiceGetter.php
- Modified: 2026-09-25T08:27:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/payplug/3.1.0/code/src/Traits/ServiceGetter.php#L10-L20`.

```php
<?php

namespace Payplug\PayplugWoocommerce\Traits;

trait ServiceGetter
{
    private $configuration;
    private $api;

    /**
     * @param $name
     *
     * @return object|null
     */
    public function get_service($name = '')
    {
        if (!is_string($name) || empty($name)) {
            return null;
        }

        try {
            $service_name = '\Payplug\PayplugWoocommerce\Service\\';
            $service_name .= str_replace('_', '', ucwords($name, '_'));

            if (!class_exists($service_name)) {
                return null;
            }
            $service = new $service_name();
            //			$this->{$name} = new $service_name();
        } catch (\Exception $e) {
            return null;
        }

        return $service;
    }

    /**
     * @return object|null
     */
    public function get_configuration()
    {
        $this->configuration = empty($this->configuration)
            ? $this->get_service('configuration')
            : $this->configuration;

        return $this->configuration;
    }

    /**
     * @return object|null
     */
    public function get_api()
    {
        $this->api = empty($this->api)
            ? $this->get_service('api')
            : $this->api;

        return $this->api;
    }
}

```
