@param Agenda $agenda
@param bool   $lazyLoad if false the agenda object only holds the ID

@return Agenda

@throws \Http\Client\Exception
963816
public function create(Agenda $agenda, $lazyLoad = false): Agenda
    {
        $payload = $this->getClient()->getSerializer()->serialize(['agendas' => [$agenda]], 'json');
        $agenda = $this->getClient()->call($payload, null, self::ENDPOINT, Agenda::class, false, 'POST');

        if ($lazyLoad) {
            return $this->get($agenda->getId());
        }

        return $agenda;
    }
373524
public function distribuiSenhaAgendamento(
        Request $request,
        AtendimentoService $atendimentoService,
        TranslatorInterface $translator,
        Agendamento $agendamento
    ) {
        if ($agendamento->getDataConfirmacao()) {
            throw new Exception($translator->trans('error.schedule.confirmed', [], self::DOMAIN));
        }
        
        $data = $agendamento->getData()->format('Y-m-d');
        $hora = $agendamento->getHora()->format('H:i');
        $dt   = DateTime::createFromFormat('Y-m-d H:i', "{$data} {$hora}");
        $now  = new DateTime();
        $diff = $now->diff($dt);
        $mins = $diff->i + ($diff->h * 60);
        $max  = 30;
        
        if ($mins > $max) {
            throw new Exception($translator->trans('error.schedule.expired', [], self::DOMAIN));
        }
        
        $envelope   = new Envelope();
        $usuario    = $this->getUser();
        $unidade    = $agendamento->getUnidade();
        $servico    = $agendamento->getServico();
        $prioridade = 1;
        $cliente    = $agendamento->getCliente();
        
        $data = $atendimentoService->distribuiSenha($unidade, $usuario, $servico, $prioridade, $cliente, $agendamento);
        $envelope->setData($data);

        return $this->json($envelope);
    }
941479
private function scheduleTask(TaskInterface $task, array $workload)
    {
        return $this->taskScheduler->createTask($task->getHandlerClass(), $workload)
            ->executeAt($task->getSchedule())
            ->schedule();
    }
1003115
public function syncRoles($slugs, $reload = true)
    {
        /** @var  \Illuminate\Database\Eloquent\Collection  $roles */
        $roles = app(RoleContract::class)->whereIn('slug', $slugs)->get();

        event(new SyncingUserWithRoles($this, $roles));
        $synced = $this->roles()->sync($roles->pluck('id'));
        event(new SyncedUserWithRoles($this, $roles, $synced));

        $this->loadRoles($reload);

        return $synced;
    }
1360022
protected function loadRealPackage(LazyPackageInterface $package)
    {
        $realPackage = false;

        try {
            $data = $this->driver->getComposerInformation($this->identifier);
            $valid = \is_array($data);
            $data = $this->preProcess($this->driver, $this->validateData($data), $this->identifier);

            if ($this->verbose) {
                $this->io->write('Importing '.($valid ? '' : 'empty ').$this->type.' '.$data['version'].' ('.$data['version_normalized'].')');
            }

            /** @var CompletePackageInterface $realPackage */
            $realPackage = $this->loader->load($data);
        } catch (\Exception $e) {
            if ($this->verbose) {
                $filename = $this->assetType->getFilename();
                $this->io->write('<'.$this->getIoTag().'>Skipped '.$this->type.' '.$package->getPrettyVersion().', '.($e instanceof TransportException ? 'no '.$filename.' file was found' : $e->getMessage()).'</'.$this->getIoTag().'>');
            }
        }
        $this->driver->cleanup();

        return $realPackage;
    }
732367
protected function createLazyLoader($type, $identifier, array $packageData, VcsDriverInterface $driver)
    {
        $lazyLoader = new LazyAssetPackageLoader($type, $identifier, $packageData);
        $lazyLoader->setAssetType($this->assetType);
        $lazyLoader->setLoader($this->loader);
        $lazyLoader->setDriver(clone $driver);
        $lazyLoader->setIO($this->io);
        $lazyLoader->setAssetRepositoryManager($this->assetRepositoryManager);

        return $lazyLoader;
    }
97332
public function poll($forceFullSync = false)
    {
        /** @var PollTaskRepository $pollTaskRepository */
        $pollTaskRepository     = $this->entityManager->getRepository(PollTask::class);
        $lastSuccessfulPollTask = $pollTaskRepository->findLastSuccessfulForPoller($this->getName());

        $rootDseDnsHostName = $this->fetcher->getRootDseDnsHostName();
        $invocationId       = $this->fetcher->getInvocationId();

        $isFullSyncRequired = $this->isFullSyncRequired($forceFullSync, $lastSuccessfulPollTask, $rootDseDnsHostName, $invocationId);
        $highestCommitedUSN = $this->fetcher->getHighestCommittedUSN();

        $currentTask = $this->createCurrentPollTask(
            $invocationId,
            $highestCommitedUSN,
            $rootDseDnsHostName,
            $lastSuccessfulPollTask,
            $isFullSyncRequired
        );

        $this->entityManager->persist($currentTask);
        $this->entityManager->flush();
        try {
            if ($isFullSyncRequired) {
                $fetchedEntriesCount = $this->fullSync($currentTask, $highestCommitedUSN);
            } else {
                $usnChangedStartFrom = $lastSuccessfulPollTask->getMaxUSNChangedValue() + 1;
                $fetchedEntriesCount = $this->incrementalSync($currentTask, $usnChangedStartFrom, $highestCommitedUSN);
            }
            $currentTask->succeed($fetchedEntriesCount);

            return $fetchedEntriesCount;
        } catch (Exception $e) {
            $currentTask->fail($e->getMessage());
            throw $e;
        } finally {
            $this->entityManager->flush();
        }
    }
1009165
public function getProperties($lazyLoad = true)
    {
        if ($lazyLoad) {
            $this->ensureFull();
        }
        $keys = $this->getPropertyNames();

        return array_intersect_key($this->data, array_flip($keys));
    }
826336
public function load($client_id = null)
	{
		if (!is_null($client_id))
		{
			$client = ClientManager::client($client_id, (! is_numeric($client_id)));
		}
		else
		{
			$client = $this->app['client'];
		}

		if (!$client)
		{
			throw new \InvalidArgumentException(sprintf('Invalid client type of "%s".', $client_id));
		}

		return $this->getTemplate((int)$client->id, $this->style);
	}
1020444
protected function getAgenda()
    {
        if (!$this->agenda) {
            $this->agenda = $this->loader->getAgenda();
        }
        
        return $this->agenda;
    }
983951
protected static function lazyInitStatic ( Closure $container, $dependency = null, array $params = [ ] )
    {
        /** @var string $key */
        if ( $dependency === null ) {
            $key = LazyInitHelper::createBacktraceKey();
        } elseif ( is_array( $dependency ) ) {
            $key = LazyInitHelper::createDependencyKey( $dependency );
        } else {
            $key = $dependency;
        }
        if ( !array_key_exists( $key, static::$lazyInitStaticData ) ) {
            static::$lazyInitStaticData[ $key ] = call_user_func_array( $container, $params );
        }

        return static::$lazyInitStaticData[ $key ];
    }
1018846
public static function onChange(PathInterface $cache, Loader $load = null): self
    {
        $self = new self($cache, $load);
        $self->debug = true;

        return $self;
    }
1097153
private function createLazyDefinition($registry, Definition $definition)
    {
        $lazy = new Definition(LazyRegistry::class, [
            new Reference('service_container'),
            new Reference($registry),
        ]);

        foreach ($definition->getMethodCalls() as $methodCall) {
            if ($methodCall[0] === 'offsetSet') {
                $methodCall[1][1] = (string) $methodCall[1][1];
                $lazy->addMethodCall('setLazy', $methodCall[1]);
            }
        }

        return $lazy;
    }
938614
public function getCollectionFor(array $rids, $lazy = true, $fetchPlan = null)
    {
        if ($lazy) {
            $proxies = array();
            foreach ($rids as $rid) {
                $proxies[] = $this->getProxyFor(new Rid($rid), $lazy);
            }

            return new ArrayCollection($proxies);
        }

        $results = $this->getHydrator()->load($rids, $fetchPlan);

        if (is_array($results)) {
            return $this->getHydrator()->hydrateCollection($results);
        }

        return null;

    }
1242444
public static function lazyConnection($dsn, $name = false)
    {
        Eresus_Kernel::log(__METHOD__, LOG_DEBUG, '("%s", %s)', $dsn, $name);
        self::$lazyConnectionDSNs[$name] = $dsn;
    }
618539
private function _getProviderInfosRecordById($providerId = null)
    {
        if ($providerId)
        {
            $providerRecord = Oauth_ProviderInfosRecord::model()->findById($providerId);

            if (!$providerRecord)
            {
                throw new Exception(Craft::t('No oauth provider exists with the ID “{id}”', array('id' => $providerId)));
            }
        }
        else
        {
            $providerRecord = new Oauth_ProviderInfosRecord();
        }

        return $providerRecord;
    }
1076386
public static function timer(int $dueTime, AsyncSchedulerInterface $scheduler = null): TimerObservable
    {
        return new TimerObservable($dueTime, $scheduler ?: Scheduler::getAsync());
    }