本文整理汇总了PHP中Silex\Application::raw方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::raw方法的具体用法?PHP Application::raw怎么用?PHP Application::raw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Silex\Application
的用法示例。
在下文中一共展示了Application::raw方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Application $app)
{
$app['listener.general'] = $app->share(function ($app) {
return new Listener\GeneralListener($app);
});
$app['listener.exception'] = $app->share(function ($app) {
$rootPath = $app['resources']->getPath('root');
return new Listener\ExceptionListener($rootPath, $app['render'], $app['logger.system'], $app['session'], $app['config']->get('general/debug', false));
});
$app['listener.not_found'] = $app->share(function ($app) {
return new Listener\NotFoundListener($app['config']->get('general/notfound'), $app['storage.legacy'], $app['templatechooser'], $app['render']);
});
/*
* Creating the actual url generator flushes all controllers.
* We aren't ready for this since controllers.mount event hasn't fired yet.
* RedirectListener doesn't use the url generator until kernel.response
* (way after controllers have been added).
*/
$app['listener.redirect'] = $app->share(function ($app) {
return new Listener\RedirectListener($app['session'], $app['url_generator.lazy'], $app['users'], $app['access_control']);
});
$app['listener.session'] = $app->share(function ($app) {
$debug = $app['debug'] && $app['config']->get('general/debug_show_loggedoff', false);
return new Listener\SessionListener($app['logger.flash'], $debug);
});
$app['listener.pager'] = $app->share(function ($app) {
return new Listener\PagerListener($app->raw('pager'));
});
$app['listener.snippet'] = $app->share(function ($app) {
return new Listener\SnippetListener($app['asset.queue.snippet'], $app['config'], $app['resources'], $app['render']);
});
$app['listener.zone_guesser'] = $app->share(function ($app) {
return new Listener\ZoneGuesser($app);
});
}
示例2: register
/**
* {@inheritDoc}
*/
public function register(Application $app)
{
$app['routing.resource'] = null;
$app['routing.options'] = array();
$app['routing.loader.xml'] = $app->share(function (Application $app) {
return new XmlFileLoader($app['config.locator']);
});
$app['routing.loader.php'] = $app->share(function (Application $app) {
return new PhpFileLoader($app['config.locator']);
});
$app['routing.loader.yml'] = $app->share(function (Application $app) {
return new YamlFileLoader($app['config.locator']);
});
$app['routing.loader.null'] = $app->share(function (Application $app) {
return new NullLoader();
});
$app['routing.loader.resolver'] = $app->share(function (Application $app) {
$loaders = array($app['routing.loader.xml'], $app['routing.loader.php'], $app['routing.loader.null']);
if (class_exists('Symfony\\Component\\Yaml\\Yaml')) {
$loaders[] = $app['routing.loader.yml'];
}
return new LoaderResolver($loaders);
});
$app['routing.loader'] = $app->share(function (Application $app) {
return new DelegatingLoader($app['routing.loader.resolver']);
});
$app['router'] = $app->share(function (Application $app) {
$defaults = array('debug' => $app['debug'], 'matcher_base_class' => 'Silex\\RedirectableUrlMatcher', 'matcher_class' => 'Silex\\RedirectableUrlMatcher');
$options = array_replace($defaults, $app['routing.options']);
return new Router($app['routing.loader'], $app['routing.resource'], $options, $app['request_context'], $app['logger']);
});
$app['routes'] = function (Application $app) {
return $app['router']->getRouteCollection();
};
$app['url_matcher'] = $app->raw('router');
$app['url_generator'] = $app->raw('router');
}
示例3: searchContentType
public function searchContentType($contenttypename, array $parameters = [], &$pager = [])
{
$where = [];
$tablename = $this->getContenttypeTablename($contenttypename);
$contenttype = $this->app['config']->get('contenttypes/' . $contenttypename);
// If this contenttype has 'searchable: false', we skip it.
if (isset($contenttype['searchable']) && $contenttype['searchable'] === false) {
return [];
}
// for all the non-reserved parameters that are fields, we assume people want to do a 'where'
foreach ($parameters as $key => $value) {
if (in_array($key, ['order', 'where', 'limit', 'offset'])) {
continue;
// Skip this one.
}
if (!$this->isValidColumn($key, $contenttype)) {
continue;
// Also skip if 'key' isn't a field in the contenttype.
}
$where[] = $this->parseWhereParameter($key, $value);
}
// @todo update with nice search string
// If we need to filter, add the WHERE for that.
// Meh, InnoDB doesn't support full text search.
if (!empty($parameters['filter'])) {
$filter = $this->app['db']->quote($parameters['filter']);
$filterWhere = [];
foreach ($contenttype['fields'] as $key => $value) {
if (in_array($value['type'], ['text', 'textarea', 'html', 'markdown'])) {
$filterWhere[] = sprintf("%s LIKE '%%%s%%'", $key, $filter);
}
}
if (!empty($filterWhere)) {
$where[] = '(' . implode(' OR ', $filterWhere) . ')';
}
}
$limit = !empty($parameters['limit']) ? $parameters['limit'] : 9999;
$page = !empty($parameters['page']) ? $parameters['page'] : 1;
// If we're allowed to use pagination, use the 'page' parameter.
if (!empty($parameters['paging']) && $this->app->raw('request') instanceof Request) {
$page = $this->app['request']->get('page', $page);
}
$queryparams = "";
// implode 'where'
if (!empty($where)) {
$queryparams .= sprintf(' WHERE (%s)', implode(" AND ", $where));
}
// Order, with a special case for 'RANDOM'.
if (!empty($parameters['order'])) {
if ($parameters['order'] == "RANDOM") {
$dboptions = $this->app['db']->getParams();
$queryparams .= sprintf(' ORDER BY %s', $dboptions['randomfunction']);
} else {
$order = $this->getEscapedSortorder($parameters['order'], false);
if (!empty($order)) {
$queryparams .= sprintf(' ORDER BY %s', $order);
}
}
}
// Make the query for the pager.
$pagerquery = sprintf('SELECT COUNT(*) AS count FROM %s %s', $tablename, $queryparams);
// Add the limit
$queryparams = $this->app['db']->getDatabasePlatform()->modifyLimitQuery($queryparams, $limit, ($page - 1) * $limit);
// Make the query to get the results.
$query = "SELECT * FROM {$tablename}" . $queryparams;
$rows = $this->app['db']->fetchAll($query);
// Make sure content is set, and all content has information about its contenttype
$content = [];
foreach ($rows as $row) {
$content[$row['id']] = $this->getContentObject($contenttype, $row);
}
// TODO: Check if we need to hydrate here!
// Make sure all content has their taxonomies and relations
$this->getTaxonomy($content);
$this->getRelation($content);
// Set up the $pager array with relevant values.
$rowcount = $this->app['db']->executeQuery($pagerquery)->fetch();
$pager = ['for' => 'search', 'count' => $rowcount['count'], 'totalpages' => ceil($rowcount['count'] / $limit), 'current' => $page, 'showing_from' => ($page - 1) * $limit + 1, 'showing_to' => ($page - 1) * $limit + count($content)];
return $content;
}
示例4: register
public function register(Application $app)
{
$app['knp_menu.factory'] = $app->share(function () use ($app) {
if (isset($app['url_generator'])) {
return new RouterAwareFactory($app['url_generator']);
}
return new MenuFactory();
});
$app['knp_menu.renderer.list'] = $app->share(function () use ($app){
return new ListRenderer($app['charset']);
});
$app['knp_menu.menu_provider'] = $app->share(function () use ($app){
return new PimpleMenuProvider($app, $app['knp_menu.menus']);
});
if (!isset($app['knp_menu.menus'])) {
$app['knp_menu.menus'] = array();
}
$app['knp_menu.renderer_provider'] = $app->share(function () use ($app){
$app['knp_menu.renderers'] = array_merge(
array('list' => 'knp_menu.renderer.list'),
isset($app['knp_menu.renderer.twig']) ? array('twig' => 'knp_menu.renderer.twig') : array(),
isset($app['knp_menu.renderers']) ? $app['knp_menu.renderers'] : array()
);
return new PimpleRendererProvider($app, $app['knp_menu.default_renderer'], $app['knp_menu.renderers']);
});
if (!isset($app['knp_menu.default_renderer'])) {
$app['knp_menu.default_renderer'] = 'list';
}
$app['knp_menu.helper'] = $app->share(function () use ($app){
return new Helper($app['knp_menu.renderer_provider'], $app['knp_menu.menu_provider']);
});
if (isset($app['twig'])) {
$app['knp_menu.twig_extension'] = $app->share(function () use ($app){
return new MenuExtension($app['knp_menu.helper']);
});
$app['knp_menu.renderer.twig'] = $app->share(function () use ($app){
return new TwigRenderer($app['knp_menu.template']);
});
if (!isset($app['knp_menu.template'])) {
$app['knp_menu.template'] = 'knp_menu.html.twig';
}
$oldTwig = $app->raw('twig');
$app['twig'] = $app->share(function($c) use ($oldTwig, $app) {
$twig = $oldTwig($c);
$twig->addExtension($app['knp_menu.renderer.twig']);
$twig->addExtension($app['knp_menu.twig_extension']);
return $twig;
});
$oldLoader = $app->raw('twig.loader.filesystem');
$app['twig.loader.filesystem'] = $app->share(function($c) use ($oldLoader, $app) {
$loader = $oldLoader($c);
$loader->addPath(__DIR__.'/../Resources/views');
return $loader;
});
}
}
示例5: raw
/**
* @param string $key
* @return mixed
*/
public function raw($key)
{
return $this->container->raw($key);
}
示例6: register
/**
* Registers services on the given app.
*
* This method should only be used to configure services and parameters.
* It should not get services.
*
* @param Application $app
*/
public function register(Application $app)
{
$app['zend.authentication.firewalls'] = isset($app['zend.authentication.firewalls']) ? $app['zend.authentication.firewalls'] : [];
$app['zend.authentication.storage_factory.session'] = $app->protect(function (array $options) use($app) {
return $app->share(function () use($app, $options) {
return new Session(isset($options['namespace']) ? $options['namespace'] : null, isset($options['member']) ? $options['member'] : null);
});
});
$app['zend.authentication.storage_factory.non_persistent'] = $app->protect(function () use($app) {
return $app->share(function () {
return new NonPersistent();
});
});
$app['zend.authentication.storage_factory.chain'] = $app->protect(function (array $options) use($app) {
return $app->share(function () use($app, $options) {
$options = array_map(function ($option) use($app) {
/* @var $factory \Closure */
$factory = is_string($option) ? $app->raw($option) : $app['zend.authentication.storage_factory.' . $option['type']]($option['options']);
return $factory($app);
}, $options);
$chain = new Chain();
foreach ($options as $option) {
$chain->add($option);
}
return $chain;
});
});
$app['zend.authentication.adapter_factory.db'] = $app->protect(function (array $options) use($app) {
return $app->share(function () use($app, $options) {
return new Database($app['db'], $options);
});
});
$app['zend.authentication.adapter_factory.digest'] = $app->protect(function (array $options) use($app) {
return $app->share(function () use($app, $options) {
return new Digest($options);
});
});
$app['zend.authentication.adapter_factory.http_basic'] = $app->protect(function (array $options) use($app) {
return $app->share(function () use($app, $options) {
$filename = $options['filename'];
unset($options['filename']);
return new Http\HttpBasic(new FileResolver($filename), $this['request_stack']->getCurrentRequest(), $options);
});
});
$app['zend.authentication.adapter_factory.http_digest'] = $app->protect(function (array $options) use($app) {
return $app->share(function () use($app, $options) {
$filename = $options['filename'];
unset($options['filename']);
return new Http\HttpDigest(new FileResolver($filename), $this['request_stack']->getCurrentRequest(), $options);
});
});
$app['zend.authentication.adapter_factory.callback'] = $app->protect(function (array $options) use($app) {
return $app->share(function () use($options) {
return new Callback($options['callback']);
});
});
$app['zend.authentication.adapter_factory.chain'] = $app->protect(function (array $options) use($app) {
return $app->share(function () use($app, $options) {
$options = array_map(function ($option) use($app) {
/* @var $factory \Closure */
$factory = is_string($option) ? $app->raw($option) : $app['zend.authentication.adapter_factory.' . $option['type']]($option['options']);
return $factory($app);
}, $options);
return new \SilexCMF\ZendAuthentication\Adapter\Chain($options, isset($app['logger']) ? $app['logger'] : null);
});
});
$app['zend.authentication.listener_factory.form'] = $app->protect(function ($name, array $options) use($app) {
return $app->share(function () use($app, $name, $options) {
return new FormListener($app['zend.authentication.service.' . $name], $options['pattern'], $options['whitelist'], new Container('zend.authentication.session.' . $name), $options['form']);
});
});
$app['zend.authentication.listener_factory.http'] = $app->protect(function ($name, array $options) use($app) {
return $app->share(function () use($app, $name, $options) {
return new HttpListener($app['zend.authentication.service.' . $name], $options['pattern'], $options['whitelist']);
});
});
$app['zend.authentication.listener_factory.logout'] = $app->protect(function ($name, array $options) use($app) {
return $app->share(function () use($app, $name, $options) {
$options = $this->logoutListenerOptions->resolve($options);
return new LogoutListener($app['zend.authentication.service.' . $name], $options['logout_url'], $options['target_url']);
});
});
$app['zend.authentication.service_factory'] = $app->protect(function ($name, array $options) use($app) {
$options = $this->authenticationServiceOptions->resolve($options);
$storageId = 'zend.authentication.storage.' . $name;
if (!isset($app[$storageId])) {
$app[$storageId] = is_string($options['storage']) ? $app->raw($options['storage']) : $app['zend.authentication.storage_factory.' . $options['storage']['type']]($options['storage']['options']);
}
$adapterId = 'zend.authentication.adapter.' . $name;
if (!isset($app[$adapterId])) {
$app[$adapterId] = is_string($options['adapter']) ? $app->raw($options['adapter']) : $app['zend.authentication.adapter_factory.' . $options['storage']['type']]($options['storage']['options']);
}
//.........这里部分代码省略.........