Initialize service

@param  array $args
@return mixed
347055
protected function initService(array $args = null) {
		$reflection = $this->getReflection();
		
		if ($args === null) {
			return $reflection->newInstance();
		}
		
		return $reflection->newInstanceArgs($args);
	}
1141147
public function handle(array $args)
  {
    switch ( strtoupper(request()->getMethod()) ) {
      case "GET"    : return $this->handleGET($args); break;
      case "POST"   : return $this->handlePOST($args); break;
      case "PUT"    : return $this->handlePUT($args); break;
      case "PATCH"  : return $this->handlePATCH($args); break;
      case "DELETE" : return $this->handleDELETE($args); break;
      case "HEAD"   : return $this->handleHEAD($args); break;
      case "OPTIONS": return $this->handleOPTIONS($args); break;
      default       : return $this->handleCUSTOM($args); break;
    }
  }
424487
public static function getInstance(...$args)
    {
        $class = static::class;

        if (empty(static::$instances[$class])) {
            static::$instances[$class] = Ioc::getContainer()->newInstance($class, ...$args);
        }

        return static::$instances[$class];
    }
587903
public function afterFetch(Array &$args) {
        $model = $args[0];
        $results = $args[1];
        $table = $model->getName();
        $chartService = new Garp_Service_Google_Chart();
        $ini = Garp_Config_Ini::getCached(APPLICATION_PATH.'/configs/routes.ini');
        $routes = $ini->routes->toArray();
        $view = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getResource('view');

        $routeFound = false;
        foreach ($routes as $r) {
            if (
                array_key_exists('route', $r) &&
                $r['route'] === '/'.$table.'/:slug'
            ) {
                $routeFound = $r;
                break;
            }
        }

        if (!$routeFound) {
            throw new Exception('There is no direct route to this object.');
        }

        // provide uniform interface, so we can always loop
        if (!$results instanceof Garp_Db_Table_Rowset) {
            $results = array($results);
        }

        foreach ($results as $row) {
            if (
                isset($row->slug) &&
                $row->slug
            ) {
                $refUrl = $view->fullUrl('/'.$table.'/'.$row->slug);
                $row->setVirtual('qrcode', $chartService->fetchQRCodeUrl($refUrl));
            }
        }

        // return the pointer to 0
        if ($results instanceof Garp_Db_Table_Rowset) {
            $results->rewind();
        } else {
        // also, return results to the original format if it was no Rowset to begin with.
            $results = $results[0];
        }
    }
1259038
protected function applyArgsToMailService(array $args)
    {
        if (isset($args['body'])) {
            $body = $args['body'];
            if (is_array($body)) {
                $charset = $body['charset'] ?? MailServiceInterface::DEFAULT_CHARSET;
                if (isset($body['content']) && is_string($body['content'])) {
                    $this->mailService->setBody($body['content'], $charset);
                } elseif (isset($body['template']) && is_array($body['template'])) {
                    $name = $body['template']['name'] ?? '';
                    $params = $body['template']['params'] ?? [];
                    if (!empty($name)) {
                        $this->mailService->setTemplate($name, $params, $charset);
                    }
                }
            } else {
                $this->mailService->setBody($body);
            }
        }

        if (isset($args['subject'])) {
            $this->mailService->setSubject($args['subject']);
        }

        if (isset($args['to'])) {
            $this->mailService->getMessage()->setTo($args['to']);
        }

        if (isset($args['from'])) {
            $from = $args['from'];
            if (is_array($from)) {
                $fromAddress = array_keys($from);
                $fromName = array_values($from);
                $this->mailService->getMessage()->setFrom($fromAddress[0], $fromName[0]);
            } else {
                $this->mailService->getMessage()->setFrom($from);
            }
        }

        if (isset($args['cc'])) {
            $this->mailService->getMessage()->setCc($args['cc']);
        }

        if (isset($args['bcc'])) {
            $this->mailService->getMessage()->setBcc($args['bcc']);
        }

        if (isset($args['attachments'])) {
            $this->mailService->setAttachments($args['attachments']);
        }
    }
693053
public function update( array $args ) {

		if ( self::$ran ) {
			return new NullLog();
		}

		if ( $this->is_cron() || $this->is_cli() ) {
			$this->register_event_listener();
		}

		return new NullLog();
	}
1240341
public function update( array $args ) {

		switch ( current_filter() ) {
			case 'phpmailer_init' :
				return $this->on_mailer_init( $args );
			case 'wp_mail_failed' :
				return $this->on_mail_failed( $args );
		}

		return new NullLog();
	}
1106498
public function getServiceByArgs($id, $args) {
		$processedArgs = $this->processArgs($args);
		
		if ($this->factoryMode) {
			return $this->initService($id, $processedArgs);
		}
		
		$fullId = $id . ':' . $this->getIdByArgs($args);
		
		if (! isset($this->services[$fullId])) {
			$this->services[$fullId] = $this->initService($id, $processedArgs);
		}
		
		return $this->services[$fullId];
	}
620662
public function provide($name, $args)
    {
        $services = $this->getServices();
        if (isset($services[$name])) {
            return (new Service($name, $services[$name]))
                ->resolve($args, $this->getDi());
        } else {
            $method = self::METHOD_PREFIX . $name;
            if (method_exists($this, $method)) {
                if (empty($args)) {
                    return $this->$method();
                } else {
                    return call_user_func_array([$this, $method], $args);
                }
            } else {
                throw new Exception("Cannot load '{$name}' from " . get_class($this));
            }
        }
    }
516464
public function createSessionAsync(array $args)
    {
        $database = $this->pluck('database', $args);
        $opts = $this->addResourcePrefixHeader([], $database);
        $opts['credentialsWrapper'] = $this->credentialsWrapper;
        $transport = $this->spannerClient->getTransport();

        $request = new CreateSessionRequest([
            'database' => $database
        ]);

        $session = $this->pluck('session', $args, false);

        if ($session) {
            $sessionMessage = new Session($session);
            $request->setSession($sessionMessage);
        }

        return $transport->startUnaryCall(
            new Call(
                'google.spanner.v1.Spanner/CreateSession',
                Session::class,
                $request
            ),
            $opts
        );
    }
828145
public function getService($args = null) {
		if ($this->isFactory()) {
			return $this->getServiceByFactory();
		}
		
		if ($args === null) {
			return $this->getCommonService();
		}
		
		return $this->getServiceByArgs($args);
	}
726537
private function on_mailer_init( array $args ) {

		$mailer = $args ? reset( $args ) : NULL;
		if ( $mailer instanceof \PHPMailer ) {
			$mailer->SMTPDebug   = 2;
			$mailer->Debugoutput = function ( $message ) {

				// Log the mailer debug message.
				do_action( \Inpsyde\Wonolog\LOG, new Debug( $message, Channels::HTTP ) );
			};
		}

		return new NullLog();
	}
1045751
public function setArguments(array $args)
    {
        $className = $this->className;
        $method = $this->method;

        $arguments = [];

        if (isset(self::$params[$className][$method])) {
            foreach (self::$params[$className][$method] as ['index' => $index, 'default' => $default]) {
                $arguments[$index] = \array_key_exists($index, $args) ? $args[$index] : $default;
            }
        } else {
            $reflectionMethod = new \ReflectionMethod($this->object, $method);

            $parameters = $reflectionMethod->getParameters();
            foreach ($parameters as $index => $parameter) {
                $name = $parameter->getName();
                $default = $parameter->isDefaultValueAvailable() ? $parameter->getDefaultValue() : null;

                self::$params[$className][$method][$name] = [
                    'index' => $index,
                    'default' => $default,
                ];

                $arguments[$index] = \array_key_exists($index, $args) ? $args[$index] : $default;
            }
        }

        $this->arguments = $arguments;

        return $this;
    }
39590
public static function init ($name = null, ...$args) {
		$name = implode('<>', (array) ($name ?? static::$multitonDefaultName));
		$instance = (static::$multitonInstances[static::class][$name] ?? static::$multitonInstances[static::class][$name] = new static(...$args));
		$instance->multitonName = $name;
		return $instance;
	}
1253617
public function reset($args = null) {
		if ($args === null) {
			$this->service = null;
			return;
		}
		
		$args = $this->normalizeArgs($args);
		$id   = $this->getIdByArgs($args);
		
		unset($this->servicesByArgs[$id]);
	}
33376
protected function _createObject( $args ) {
		$user_id = wp_insert_user( $args );
		if ( $user_id && ! is_wp_error( $user_id ) ) {
			$this->_debug( 'Generated user with ID: ' . $user_id );
		} elseif ( is_wp_error( $user_id ) ) {
			$this->_debug(
				'User generation failed with message [%s] %s',
				$user_id->get_error_code(),
				$user_id->get_error_message()
			);
		} else {
			$this->_debug( 'User generation failed' );
		}


		return $user_id;
	}
775852
public static function createServiceManager(array $config = [])
    {
        $serviceManager = new ServiceManager(new Config($config));

        $serviceManager->addInitializer(
            function ($instance, ServiceLocatorInterface $serviceLocator) {
                if ($instance instanceof ModelManagerAwareInterface) {
                    $instance->setModelManager($serviceLocator->get('modelmanager'));
                }
            }
        );

        $serviceManager->addInitializer(
            function ($instance, ServiceLocatorInterface $serviceLocator) {
                if ($instance instanceof ServiceLocatorAwareInterface) {
                    $instance->setServiceLocator($serviceLocator);
                }
            }
        );

        return $serviceManager;
    }