本文整理汇总了PHP中Slim\Helper\Set类的典型用法代码示例。如果您正苦于以下问题:PHP Set类的具体用法?PHP Set怎么用?PHP Set使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Set类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public function get()
{
$request = $this->getSlim()->request();
// Check authentication
$this->getSlim()->auth->checkPermission('profile');
// TODO: Validation.
$params = new Set($request->get());
$agent = $params->get('agent');
$agent = json_decode($agent, true);
$view = new AgentView(['agent' => $agent]);
$view = $view->renderGet();
Resource::jsonResponse(Resource::STATUS_OK, $view);
}
示例2: activityGet
/**
* Fetches activity profiles according to the given parameters.
*
* @param array $request The incoming HTTP request
*
* @return array An array of activityProfile objects.
*/
public function activityGet($request)
{
$params = new Set($request->get());
$collection = $this->getDocumentManager()->getCollection('activities');
$cursor = $collection->find();
$cursor->where('id', $params->get('activityId'));
if ($cursor->count() === 0) {
throw new Exception('Activity does not exist.', Resource::STATUS_NOT_FOUND);
}
$this->cursor = $cursor;
$this->single = true;
return $this;
}
示例3: set
/**
* Set cookie
*
* The second argument may be a single scalar value, in which case
* it will be merged with the default settings and considered the `value`
* of the merged result.
*
* The second argument may also be an array containing any or all of
* the keys shown in the default settings above. This array will be
* merged with the defaults shown above.
*
* @param string $key Cookie name
* @param mixed $value Cookie settings
*/
public function set($key, $value)
{
if (is_array($value)) {
$cookieSettings = array_replace($this->defaults, $value);
} else {
$cookieSettings = array_replace($this->defaults, array('value' => $value));
}
parent::set($key, $cookieSettings);
}
示例4: configureIoc
/**
* Configure inversion of control/dependency injection container.
*
* @param \Slim\Helper\Set $container IOC container
*/
protected function configureIoc(\Slim\Helper\Set $container)
{
$container->singleton('i18nCache', function ($c) {
return new JsonCache($c->settings['i18n.path'], $c->log);
});
$container->singleton('i18nContext', function ($c) {
return new I18nContext($c->i18nCache, $c->settings['i18n.default'], $c->log);
});
$container->singleton('mailer', function ($c) {
return new Mailer(array('Host' => $c->settings['smtp.host']), $c->log);
});
$container->singleton('parsoid', function ($c) {
return new ParsoidClient($c->settings['parsoid.url'], $c->settings['parsoid.cache'], $c->log);
});
$container->singleton('quips', function ($c) {
$settings = array('url' => $c->settings['es.url'], 'log' => true);
if ($c->settings['es.user'] !== '') {
$creds = base64_encode($c->settings['es.user'] . ':' . $c->settings['es.password']);
$settings['headers'] = array('Authorization' => "Basic {$creds}");
}
$client = new \Elastica\Client($settings);
$client->setLogger($c->log);
return new Quips($client, $c->log);
});
$container->singleton('oauthConfig', function ($c) {
$conf = new \MediaWiki\OAuthClient\ClientConfig($c->settings['oauth.endpoint']);
$conf->setRedirURL($c->settings['oauth.redir']);
$conf->setConsumer(new \MediaWiki\OAuthClient\Consumer($c->settings['oauth.consumer_token'], $c->settings['oauth.secret_token']));
return $conf;
});
$container->singleton('oauthClient', function ($c) {
$client = new \MediaWiki\OAuthClient\Client($c->oauthConfig, $c->log);
$client->setCallback($c->settings['oauth.callback']);
return $client;
});
$container->singleton('userManager', function ($c) {
return new OAuthUserManager($c->oauthClient, $c->log);
});
$container->singleton('authManager', function ($c) {
return new AuthManager($c->userManager);
});
// TODO: figure out where to send logs
}
示例5: get
public function get()
{
$request = $this->getSlim()->request();
// Check authentication
$this->getSlim()->auth->checkPermission('attachments');
$params = new Set($request->get());
if (!$params->has('sha2')) {
throw new \Exception('Missing sha2 parameter!', Resource::STATUS_BAD_REQUEST);
}
$sha2 = $params->get('sha2');
$encoding = $params->get('encoding');
// Fetch attachment metadata and data
$metadata = $this->attachmentService->fetchMetadataBySha2($sha2);
$data = $this->attachmentService->fetchFileBySha2($sha2);
if ($encoding !== 'binary') {
$data = base64_encode($data);
}
$this->getSlim()->response->headers->set('Content-Type', $metadata->getContentType());
Resource::response(Resource::STATUS_OK, $data);
}
示例6: loginPost
/**
* Logs the user in.
*
* @return \API\Document\User The user document
*/
public function loginPost($request)
{
$params = new Set($request->post());
// CSRF protection
if (!$params->has('csrfToken') || !isset($_SESSION['csrfToken']) || $params->get('csrfToken') !== $_SESSION['csrfToken']) {
throw new \Exception('Invalid CSRF token.', Resource::STATUS_BAD_REQUEST);
}
// This could be in JSON schema as well :)
if (!$params->has('email') || !$params->has('password')) {
throw new \Exception('Username or password missing!', Resource::STATUS_BAD_REQUEST);
}
$collection = $this->getDocumentManager()->getCollection('users');
$cursor = $collection->find();
$cursor->where('email', $params->get('email'));
$cursor->where('passwordHash', sha1($params->get('password')));
$document = $cursor->current();
if (null === $document) {
$errorMessage = 'Invalid login attempt. Try again!';
$this->errors[] = $errorMessage;
throw new \Exception($errorMessage, Resource::STATUS_UNAUTHORIZED);
}
$this->single = true;
$this->users = [$document];
// Set the session
$_SESSION['userId'] = $document->getId();
$_SESSION['expiresAt'] = time() + 3600;
//1 hour
// Set the Remember me cookie
$rememberMeStorage = new RemembermeMongoStorage($this->getDocumentManager());
$rememberMe = new Rememberme\Authenticator($rememberMeStorage);
if ($params->has('rememberMe')) {
$rememberMe->createCookie($document->getId());
} else {
$rememberMe->clearCookie();
}
return $document;
}
示例7: configureIoc
/**
* Configure inversion of control/dependency injection container.
*
* @param \Slim\Helper\Set $container IOC container
*/
protected function configureIoc(\Slim\Helper\Set $container)
{
$container->singleton('i18nCache', function ($c) {
return new JsonCache($c->settings['i18n.path'], $c->log);
});
$container->singleton('i18nContext', function ($c) {
return new I18nContext($c->i18nCache, $c->settings['i18n.default'], $c->log);
});
$container->singleton('mailer', function ($c) {
return new Mailer(['Host' => $c->settings['smtp.host']], $c->log);
});
$container->singleton('parsoid', function ($c) {
return new ParsoidClient($c->settings['parsoid.url'], $c->settings['parsoid.cache'], $c->log);
});
$container->singleton('logs', function ($c) {
return new Logs(new \Elastica\Client(['url' => $c->settings['es.url']]), $c->log);
});
// TODO: figure out where to send logs
}
示例8: testConsumeSlimContainer
public function testConsumeSlimContainer()
{
$anoterContainer = new Set();
$anoterContainer->foo = [];
$anoterContainer->bar = new \stdClass();
$anoterContainer->baz = function ($c) {
return 'Hello';
};
$anoterContainer->singleton('foobar', function ($c) {
return 'Hello';
});
$anoterContainer->barfoo = [$this, 'fakeMethod'];
$this->container->consumeSlimContainer($anoterContainer);
$this->assertTrue($this->sm->has('foo'));
$this->assertTrue($this->container->has('foo'));
$this->assertTrue($this->sm->has('bar'));
$this->assertTrue($this->container->has('bar'));
$this->assertTrue($this->sm->has('baz'));
$this->assertTrue($this->container->has('baz'));
$this->assertTrue($this->sm->has('foobar'));
$this->assertTrue($this->container->has('foobar'));
$this->assertTrue($this->sm->has('barfoo'));
$this->assertTrue($this->container->has('barfoo'));
}
示例9: accessTokenDelete
/**
* Tries to delete an access token.
*/
public function accessTokenDelete($request)
{
$params = new Set($request->get());
$this->deleteToken($params->get('key'), $params->get('secret'));
return $this;
}
示例10: function
// Database layer setup
$app->hook('slim.before', function () use($app) {
$app->container->singleton('mongo', function () use($app) {
$client = new Client($app->config('database')['host_uri']);
$client->map([$app->config('database')['db_name'] => '\\API\\Collection']);
$client->useDatabase($app->config('database')['db_name']);
return $client;
});
});
// CORS compatibility layer (Internet Explorer)
$app->hook('slim.before.router', function () use($app) {
if ($app->request->isPost() && $app->request->get('method')) {
$method = $app->request->get('method');
$app->environment()['REQUEST_METHOD'] = strtoupper($method);
mb_parse_str($app->request->getBody(), $postData);
$parameters = new Set($postData);
if ($parameters->has('content')) {
$content = $parameters->get('content');
$app->environment()['slim.input'] = $content;
$parameters->remove('content');
} else {
// Content is the only valid body parameter...everything else are either headers or query parameters
$app->environment()['slim.input'] = '';
}
$app->request->headers->replace($parameters->all());
$app->environment()['slim.request.query_hash'] = $parameters->all();
}
});
// Parse version
$app->hook('slim.before.dispatch', function () use($app) {
// Version
示例11: init
/**
* @param Set $container
*/
public function init(Set $container)
{
$this->add($container->get('slim.middleware.request_logging'));
$this->add($container->get('slim.middleware.store_events'));
}
示例12: init
public function init(Set $container)
{
$this->add(new FakeMiddleware($container->get('logger')));
}
示例13: renderGet
public function renderGet()
{
$agent = new Set($this->agent);
$object = ['objectType' => 'Person'];
if ($agent->has('name')) {
$object['name'] = [$agent->get('name')];
}
if ($agent->has('mbox')) {
$object['mbox'] = [$agent->get('mbox')];
}
if ($agent->has('mbox_sha1sum')) {
$object['mbox_sha1sum'] = [$agent->get('mbox_sha1sum')];
}
if ($agent->has('openid')) {
$object['openid'] = [$agent->get('openid')];
}
if ($agent->has('account')) {
$object['account'] = [$agent->get('account')];
}
return $object;
}
示例14: get
/**
* @param string $key The data key
* @param mixed $default The value to return if data key does not exist
* @return mixed The data value, or the default value
*/
public function get($key, $default = null)
{
if ($value = parent::get($key, $default)) {
return $value;
}
return $this->pimple[$key];
}
示例15: set
/**
* @param string $key
* @param Tag $tag
*
* @throws InvalidTagException if the passed $value is not a Tag
*/
public function set($key, $tag)
{
if ($tag instanceof Tag) {
throw InvalidTagException::build([], ['invalidTag' => $tag]);
}
parent::set($key, $tag);
}