/** * @return CollectionPaged */ public static function getAll() { $return = []; $db = App::di()->getDb('MAIN'); $sql = 'select SQL_CALC_FOUND_ROWS * from ip_to_country LIMIT 10'; foreach ($db->query($sql) as $result) { $item = new static(); $item->map($result); $return[] = $item; } $count = $db->fetchOne('SELECT FOUND_ROWS() as count')['count']; $collection = new CollectionPaged($return, (int) $count, 1); return $collection; }
<?php declare (strict_types=1); // ini set configuration ini_set('display_errors', '1'); ini_set('default_socket_timeout', '30'); ini_set('report_memleaks', '1'); mb_internal_encoding('UTF-8'); error_reporting(E_ALL); // date date_default_timezone_set('UTC'); // autoload require '../vendor/autoload.php'; use Cawa\Core\App; putenv('APP_ENV=' . App::DEV); $app = App::create(realpath("../")); $app->init(); $app->registerModule(new Cawa\Clockwork\Module()); $app->registerModule(new Cawa\SwaggerServer\Module([new \Cawa\SwaggerServer\ServiceNamespace('Example', 'Cawa\\SwaggerServer\\ExamplesService', [2, 3])], ['web' => ['password' => md5(strtolower('web') . 'pass'), 'ip' => ['127.0.0.1/16'], 'services' => ['Example.*' => '.*']]])); $app->handle(); $app->end();
<?php /* @var $this \Cawa\Core\Config */ use Cawa\Core\App; use Cawa\Http\Client; use Cawa\Log\Output\SyslogUdp; use Psr\Log\LogLevel; $udp = new SyslogUdp(SyslogUdp::FACILITY_LOG_LOCAL0, "Сáша"); $udp->setMinimumLevel(LogLevel::EMERGENCY); $config = ["ip" => ["admin" => ["127.0.0.1"], "remoteAddressHeaders" => ["REMOTE_ADDR"]], "email" => ["default" => "smtp://*****:*****@prod:3306/database", "SLAVE" => "mysql://*****:*****@prod:3307/database"], "httpclient" => ["GOOGLE" => "http://www.google.com", "GOOGLE_FN" => function () { $client = new Client(); $client->setBaseUri("http://www.google.com"); $client->getClient()->setOption(Client\AbstractClient::OPTIONS_DEBUG, true)->setOption(Client\AbstractClient::OPTIONS_SSL_VERIFY, false); return $client; }]]); } else { /* |-------------------------------------------------------------------------- | Development |-------------------------------------------------------------------------- */ $config = array_merge($config, ["db" => ["MAIN" => "mysql://root:@127.0.0.1:3306/test", "SLAVE" => "mysql://root:@127.0.0.1:3307/test"], "httpclient" => ["GOOGLE" => "http://www.google.fr", "GOOGLE_FN" => function () { $client = new Client(); $client->setBaseUri("http://www.google.fr");
<?php /* @var $this \Cawa\Router\Router */ use Cawa\Core\App; use Cawa\Router\Route; return [Route::create()->setName("directResponse")->setMatch("/fr/direct")->setController(function (array $args = array()) { App::response()->setStatus(422); App::response()->addHeader("maman-sd78fsd5f4", "sdfsd"); return "Super"; }), Route::create()->setName("nolanguage")->setMatch("/")->setController("SampleApp\\Controller\\Index::redirect"), Route::create()->setName("index")->setMatch("/{{L}}")->setController("SampleApp\\Controller\\Index::method"), Route::create()->setName("indexTwig")->setMatch("/{{L}}/twig")->setController("SampleApp\\Controller\\Index::twig"), Route::create()->setResponseCode(404)->setController("SampleApp\\Controller\\Index::notFound")->setOption(Route::OPTIONS_CACHE, 60)];