本文整理汇总了PHP中Phalcon\Text::endsWith方法的典型用法代码示例。如果您正苦于以下问题:PHP Text::endsWith方法的具体用法?PHP Text::endsWith怎么用?PHP Text::endsWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Text
的用法示例。
在下文中一共展示了Text::endsWith方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: env
/**
* Gets the value of an environment variable. Supports boolean, empty and null.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
function env($key, $default = null)
{
$value = getenv($key);
if ($value === false) {
return value($default);
}
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
case 'empty':
case '(empty)':
return '';
case 'null':
case '(null)':
return;
}
if (Text::startsWith($value, '"') && Text::endsWith($value, '"')) {
return substr($value, 1, -1);
}
return $value;
}
示例2: eager
public function eager($model, $field = null, $localKey = null, $foreignKey = '_id')
{
if ($field == null || $localKey == null) {
$className = strtolower((new \ReflectionClass($model))->getShortName());
if (Text::endsWith($className, 's')) {
$className = substr($className, 0, -1);
}
}
if ($field == null) {
$field = $className;
}
if ($localKey == null) {
$localKey = $className . '_id';
}
$keys = [];
foreach ($this->array as $item) {
if (!in_array($item->{$localKey}, $keys)) {
$keys[] = $item->{$localKey};
}
}
$result = $model::init()->find([$foreignKey => ['$in' => $keys]])->keyBy('_id');
foreach ($this->array as $item) {
$item->setRelation($field, $result[(string) $item->{$localKey}]);
}
return $this;
}
示例3: getIdFieldName
protected function getIdFieldName($model)
{
$className = strtolower((new \ReflectionClass($model))->getShortName());
if (Text::endsWith($className, 's')) {
$className = substr($className, 0, -1);
}
return $className . '_id';
}
示例4: endsWith
public static function endsWith($str, $end, $ignoreCase = true)
{
return parent::endsWith($str, $end, $ignoreCase);
}
示例5: testEndsWith
public function testEndsWith()
{
$this->assertFalse(PhText::endsWith("", ""));
$this->assertFalse(PhText::endsWith("", "hello"));
$this->assertTrue(PhText::endsWith("Hello", "o"));
$this->assertTrue(PhText::endsWith("Hello", "lo"));
$this->assertTrue(PhText::endsWith("Hello", "Hello"));
$this->assertFalse(PhText::endsWith("Hello", "LLO"));
$this->assertFalse(PhText::endsWith("Hello", "hello"));
$this->assertFalse(PhText::endsWith("Hello", "hello", true));
$this->assertTrue(PhText::endsWith("Hello", "hello", false));
$this->assertTrue(PhText::endsWith("Hello", "o", false));
}
示例6: getOperations
public function getOperations($controllerClass)
{
$operations = array();
$ref = new \ReflectionClass($controllerClass);
$methods = $ref->getMethods();
$reader = new \Phalcon\Annotations\Adapter\Memory();
$reflector = $reader->get($controllerClass);
$operationAnnotations = $reflector->getMethodsAnnotations();
foreach ($methods as $method) {
if (!\Phalcon\Text::endsWith($method->name, 'Action')) {
continue;
}
$operationKey = substr($method->name, 0, -6);
$operationName = $operationKey;
$operationDes = '';
if (isset($operationAnnotations[$method->name]) && ($annotations = $operationAnnotations[$method->name])) {
if (!$annotations->has('operationName') || !$annotations->has('operationDescription')) {
continue;
}
$annotation = $annotations->get('operationName');
$operationName = implode('', $annotation->getArguments());
$annotation = $annotations->get('operationDescription');
$operationDes = implode('', $annotation->getArguments());
}
$operation = array('name' => $operationName, 'resourceKey' => $controllerClass, 'operationKey' => $operationKey, 'description' => $operationDes);
$operations[] = $operation;
}
return $operations;
}
示例7: endsWith
public static function endsWith($str, $end, $ignoreCase = null)
{
return Text::endsWith($str, $end, $ignoreCase);
}
示例8: boot
public function boot(Container $container)
{
// Pails 不使用Phalcon的Module功能,通过Namespace组织Controllers.
// 如果出现多级,比如AdminApi,则一定要以Namespace的形式组织 Admin\Api\xxxxController
//
// Note: from phalcon 3, closure bind di as $this by default. so no use($app) needed.
//
$container->setShared('router', function () {
//
$router = new Annotations(false);
$router->removeExtraSlashes(true);
$router->setEventsManager($this->get('eventsManager'));
$router->setDefaultNamespace('App\\Controllers');
$router->setDefaultController('application');
$router->setDefaultAction('index');
// Process /config/routes.php
// Verb Path Action Route Name
// GET /photo index photo.index
// GET /photo/create create photo.create
// POST /photo store photo.store
// GET /photo/{photo} show photo.show
// GET /photo/{photo}/edit edit photo.edit
// PUT/PATCH /photo/{photo} update photo.update
// DELETE /photo/{photo} destroy photo.destroy
foreach ($this->getConfig('routes') as $url => $route) {
// $resourceDefaults = ['index', 'create', 'store', 'show', 'edit', 'update', 'destroy'];
//
// // a RESTful resource
// if (isset($route['resource'])) {
// if (!isset($route[''])) {}
// foreach ($this->getResourceMethods($defaults, $options) as $m) {
// $this->{'addResource'.ucfirst($m)}($url, $route, $options);
// }
// } else {
// if (count($route) !== count($route, COUNT_RECURSIVE)) {
// if (isset($route['pattern']) && isset($route['paths'])) {
// $method = isset($route['httpMethods']) ? $route['httpMethods'] : null;
// $router->add($route['pattern'], $route['paths'], $method);
// } else {
// throw new \RuntimeException(sprintf('No route pattern and paths found by route %s', $url));
// }
// } else {
// $router->add($url, $route);
// }
// }
}
// 定义注解路由
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->path('Controllers')), \RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $item) {
if (Text::endsWith($item, "Controller.php", false)) {
$name = str_replace([$this->path('Controllers') . DIRECTORY_SEPARATOR, "Controller.php"], "", $item);
$name = str_replace(DIRECTORY_SEPARATOR, "\\", $name);
$router->addResource('App\\Controllers\\' . $name);
}
}
// 定义404路由
$router->notFound(["controller" => "application", "action" => "notfound"]);
//
return $router;
});
}
示例9: testEndsWithException
public function testEndsWithException()
{
$this->setExpectedException('\\Phalcon\\Exception');
\Phalcon\Text::endsWith(false, 'he');
}