1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PSFS\base; |
4
|
|
|
|
5
|
|
|
use PSFS\base\config\Config; |
6
|
|
|
use PSFS\base\exception\AccessDeniedException; |
7
|
|
|
use PSFS\base\exception\ConfigException; |
8
|
|
|
use PSFS\base\exception\RouterException; |
9
|
|
|
use PSFS\base\types\helpers\AdminHelper; |
10
|
|
|
use PSFS\base\types\helpers\I18nHelper; |
11
|
|
|
use PSFS\base\types\helpers\RequestHelper; |
12
|
|
|
use PSFS\base\types\helpers\RouterHelper; |
13
|
|
|
use PSFS\base\types\helpers\SecurityHelper; |
14
|
|
|
use PSFS\base\types\SingletonTrait; |
15
|
|
|
use PSFS\controller\base\Admin; |
16
|
|
|
use PSFS\services\AdminServices; |
17
|
|
|
use Symfony\Component\Finder\Finder; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Router |
22
|
|
|
* @package PSFS |
23
|
|
|
*/ |
24
|
|
|
class Router |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
use SingletonTrait; |
28
|
|
|
|
29
|
|
|
protected $routing; |
30
|
|
|
protected $slugs; |
31
|
|
|
private $domains; |
32
|
|
|
/** |
33
|
|
|
* @var Finder $finder |
34
|
|
|
*/ |
35
|
|
|
private $finder; |
36
|
|
|
/** |
37
|
|
|
* @var \PSFS\base\Cache $cache |
38
|
|
|
*/ |
39
|
|
|
private $cache; |
40
|
|
|
/** |
41
|
|
|
* @var bool headersSent |
42
|
|
|
*/ |
43
|
|
|
protected $headersSent = false; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Constructor Router |
47
|
|
|
* @throws ConfigException |
48
|
|
|
*/ |
49
|
6 |
|
public function __construct() |
50
|
|
|
{ |
51
|
6 |
|
$this->finder = new Finder(); |
52
|
6 |
|
$this->cache = Cache::getInstance(); |
53
|
6 |
|
$this->init(); |
54
|
6 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Inicializador Router |
58
|
|
|
* @throws ConfigException |
59
|
|
|
*/ |
60
|
1 |
|
public function init() |
61
|
|
|
{ |
62
|
1 |
|
if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json") || Config::getInstance()->getDebugMode()) { |
63
|
1 |
|
$this->hydrateRouting(); |
64
|
1 |
|
$this->simpatize(); |
65
|
1 |
|
} else { |
66
|
1 |
|
list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", Cache::JSON, TRUE); |
|
|
|
|
67
|
1 |
|
$this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, TRUE); |
|
|
|
|
68
|
|
|
} |
69
|
1 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Método que deriva un error HTTP de página no encontrada |
73
|
|
|
* |
74
|
|
|
* @param \Exception $e |
75
|
|
|
* |
76
|
|
|
* @return string HTML |
77
|
|
|
*/ |
78
|
|
|
public function httpNotFound(\Exception $e = NULL) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
Logger::log('Throw not found exception'); |
81
|
|
|
if (NULL === $e) { |
82
|
|
|
Logger::log('Not found page throwed without previous exception', LOG_WARNING); |
83
|
|
|
$e = new \Exception(_('Page not found'), 404); |
84
|
|
|
} |
85
|
|
|
$template = Template::getInstance()->setStatus($e->getCode()); |
86
|
|
|
if (preg_match('/json/i', Request::getInstance()->getServer('CONTENT_TYPE'))) { |
87
|
|
|
return $template->output(json_encode(array( |
88
|
|
|
"success" => FALSE, |
89
|
|
|
"error" => $e->getMessage(), |
90
|
|
|
)), 'application/json'); |
91
|
|
|
} else { |
92
|
|
|
return $template->render('error.html.twig', array( |
93
|
|
|
'exception' => $e, |
94
|
|
|
'trace' => $e->getTraceAsString(), |
95
|
|
|
'error_page' => TRUE, |
96
|
|
|
)); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Método que devuelve las rutas |
102
|
|
|
* @return string|null |
103
|
|
|
*/ |
104
|
|
|
public function getSlugs() |
105
|
|
|
{ |
106
|
|
|
return $this->slugs; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Method that extract all routes in the platform |
111
|
|
|
* @return array |
112
|
|
|
*/ |
113
|
|
|
public function getAllRoutes() { |
114
|
|
|
$routes = []; |
115
|
|
|
foreach($this->routing as $path => $route) { |
116
|
|
|
if(array_key_exists('slug', $route)) { |
117
|
|
|
$routes[$route['slug']] = $path; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
return $routes; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Método que calcula el objeto a enrutar |
125
|
|
|
* |
126
|
|
|
* @param string|null $route |
127
|
|
|
* |
128
|
|
|
* @throws \Exception |
129
|
|
|
* @return string HTML |
|
|
|
|
130
|
|
|
*/ |
131
|
|
|
public function execute($route) |
132
|
|
|
{ |
133
|
|
|
Logger::log('Executing the request'); |
134
|
|
|
try { |
135
|
|
|
//Check CORS for requests |
136
|
|
|
RequestHelper::checkCORS(); |
137
|
|
|
// Checks restricted access |
138
|
|
|
SecurityHelper::checkRestrictedAccess($route); |
139
|
|
|
//Search action and execute |
140
|
|
|
$this->searchAction($route); |
141
|
|
|
} catch (AccessDeniedException $e) { |
142
|
|
|
Logger::log(_('Solicitamos credenciales de acceso a zona restringida')); |
143
|
|
|
return Admin::staticAdminLogon($route); |
144
|
|
|
} catch (RouterException $r) { |
145
|
|
|
Logger::log($r->getMessage(), LOG_WARNING); |
146
|
|
|
} catch (\Exception $e) { |
147
|
|
|
Logger::log($e->getMessage(), LOG_ERR); |
148
|
|
|
throw $e; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $this->httpNotFound(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Método que busca el componente que ejecuta la ruta |
156
|
|
|
* |
157
|
|
|
* @param string $route |
158
|
|
|
* |
159
|
|
|
* @throws \PSFS\base\exception\RouterException |
160
|
|
|
*/ |
161
|
|
|
protected function searchAction($route) |
162
|
|
|
{ |
163
|
|
|
Logger::log('Searching action to execute: ' . $route, LOG_INFO); |
164
|
|
|
//Revisamos si tenemos la ruta registrada |
165
|
|
|
$parts = parse_url($route); |
166
|
|
|
$path = (array_key_exists('path', $parts)) ? $parts['path'] : $route; |
167
|
|
|
$httpRequest = Request::getInstance()->getMethod(); |
168
|
|
|
foreach ($this->routing as $pattern => $action) { |
169
|
|
|
list($httpMethod, $routePattern) = RouterHelper::extractHttpRoute($pattern); |
170
|
|
|
$matched = RouterHelper::matchRoutePattern($routePattern, $path); |
171
|
|
|
if ($matched && ($httpMethod === "ALL" || $httpRequest === $httpMethod) && RouterHelper::compareSlashes($routePattern, $path)) { |
|
|
|
|
172
|
|
|
$get = RouterHelper::extractComponents($route, $routePattern); |
173
|
|
|
/** @var $class \PSFS\base\types\Controller */ |
174
|
|
|
$class = RouterHelper::getClassToCall($action); |
175
|
|
|
try { |
176
|
|
|
$this->executeCachedRoute($route, $action, $class, $get); |
177
|
|
|
} catch (\Exception $e) { |
178
|
|
|
Logger::log($e->getMessage(), LOG_ERR); |
179
|
|
|
throw new RouterException($e->getMessage(), 404, $e); |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
throw new RouterException(_("Ruta no encontrada")); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Método que manda las cabeceras de autenticación |
188
|
|
|
* @return string HTML |
|
|
|
|
189
|
|
|
*/ |
190
|
|
|
protected function sentAuthHeader() |
191
|
|
|
{ |
192
|
|
|
return AdminServices::getInstance()->setAdminHeaders(); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Method that gather all the routes in the project |
197
|
|
|
*/ |
198
|
1 |
|
private function generateRouting() |
199
|
|
|
{ |
200
|
1 |
|
$base = SOURCE_DIR; |
201
|
1 |
|
$modulesPath = realpath(CORE_DIR); |
202
|
1 |
|
$this->routing = $this->inspectDir($base, "PSFS", array()); |
203
|
1 |
|
if (file_exists($modulesPath)) { |
204
|
|
|
$module = ""; |
|
|
|
|
205
|
|
|
if(file_exists($modulesPath . DIRECTORY_SEPARATOR . 'module.json')) { |
206
|
|
|
$mod_cfg = json_decode(file_get_contents($modulesPath . DIRECTORY_SEPARATOR . 'module.json'), true); |
207
|
|
|
$module = $mod_cfg['module']; |
|
|
|
|
208
|
|
|
} |
209
|
|
|
$modules = $this->finder->directories()->in($modulesPath)->depth(0); |
210
|
|
|
foreach($modules as $modulePath) { |
211
|
|
|
$module = $modulePath->getBasename(); |
212
|
|
|
$this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing); |
|
|
|
|
213
|
|
|
} |
214
|
|
|
} |
215
|
1 |
|
$this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE); |
216
|
1 |
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Método que regenera el fichero de rutas |
220
|
|
|
* @throws ConfigException |
221
|
|
|
*/ |
222
|
1 |
|
public function hydrateRouting() |
223
|
|
|
{ |
224
|
1 |
|
$this->generateRouting(); |
225
|
1 |
|
$home = Config::getInstance()->get('home_action'); |
226
|
1 |
|
if (NULL !== $home || $home !== '') { |
227
|
1 |
|
$home_params = NULL; |
228
|
1 |
|
foreach ($this->routing as $pattern => $params) { |
229
|
1 |
|
list($method, $route) = RouterHelper::extractHttpRoute($pattern); |
230
|
1 |
|
if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) { |
231
|
|
|
$home_params = $params; |
232
|
|
|
} |
233
|
1 |
|
} |
234
|
1 |
|
if (NULL !== $home_params) { |
235
|
|
|
$this->routing['/'] = $home_params; |
236
|
|
|
} |
237
|
1 |
|
} |
238
|
1 |
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Método que inspecciona los directorios en busca de clases que registren rutas |
242
|
|
|
* |
243
|
|
|
* @param string $origen |
244
|
|
|
* @param string $namespace |
245
|
|
|
* @param array $routing |
246
|
|
|
* |
247
|
|
|
* @return array |
248
|
|
|
* @throws ConfigException |
249
|
|
|
*/ |
250
|
1 |
|
private function inspectDir($origen, $namespace = 'PSFS', $routing = []) |
251
|
|
|
{ |
252
|
1 |
|
$files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php"); |
253
|
1 |
|
foreach ($files as $file) { |
254
|
1 |
|
$filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname())); |
255
|
1 |
|
$routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace); |
256
|
1 |
|
} |
257
|
1 |
|
$this->finder = new Finder(); |
258
|
|
|
|
259
|
1 |
|
return $routing; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Checks that a namespace exists |
264
|
|
|
* @param string $namespace |
265
|
|
|
* @return bool |
266
|
|
|
*/ |
267
|
1 |
|
public static function exists($namespace) { |
268
|
1 |
|
return (class_exists($namespace) || interface_exists($namespace) || trait_exists($namespace)); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Método que añade nuevas rutas al array de referencia |
273
|
|
|
* |
274
|
|
|
* @param string $namespace |
275
|
|
|
* @param array $routing |
276
|
|
|
* @param string $module |
277
|
|
|
* |
278
|
|
|
* @return array |
279
|
|
|
* @throws ConfigException |
280
|
|
|
*/ |
281
|
1 |
|
private function addRouting($namespace, &$routing, $module = 'PSFS') |
282
|
|
|
{ |
283
|
1 |
|
if (self::exists($namespace)) { |
284
|
1 |
|
$reflection = new \ReflectionClass($namespace); |
285
|
1 |
|
if (FALSE === $reflection->isAbstract() && FALSE === $reflection->isInterface()) { |
286
|
1 |
|
$this->extractDomain($reflection); |
287
|
1 |
|
$classComments = $reflection->getDocComment(); |
288
|
1 |
|
preg_match('/@api\ (.*)\n/im', $classComments, $apiPath); |
289
|
1 |
|
$api = ''; |
290
|
1 |
|
if (count($apiPath)) { |
291
|
|
|
$api = array_key_exists(1, $apiPath) ? $apiPath[1] : $api; |
292
|
|
|
} |
293
|
1 |
|
foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { |
294
|
1 |
|
list($route, $info) = RouterHelper::extractRouteInfo($method, $api, $module); |
295
|
1 |
|
if(null !== $route && null !== $info) { |
296
|
1 |
|
$info['class'] = $namespace; |
297
|
1 |
|
$routing[$route] = $info; |
298
|
1 |
|
} |
299
|
1 |
|
} |
300
|
1 |
|
} |
301
|
1 |
|
} |
302
|
|
|
|
303
|
1 |
|
return $routing; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Método que extrae de la ReflectionClass los datos necesarios para componer los dominios en los templates |
308
|
|
|
* |
309
|
|
|
* @param \ReflectionClass $class |
310
|
|
|
* |
311
|
|
|
* @return Router |
312
|
|
|
* @throws ConfigException |
313
|
|
|
*/ |
314
|
1 |
|
protected function extractDomain(\ReflectionClass $class) |
315
|
|
|
{ |
316
|
|
|
//Calculamos los dominios para las plantillas |
317
|
1 |
|
if ($class->hasConstant("DOMAIN") && !$class->isAbstract()) { |
318
|
1 |
|
if(!$this->domains) { |
319
|
1 |
|
$this->domains = []; |
320
|
1 |
|
} |
321
|
1 |
|
$domain = "@" . $class->getConstant("DOMAIN") . "/"; |
322
|
1 |
|
if(!array_key_exists($domain, $this->domains)) { |
323
|
1 |
|
$this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain); |
324
|
1 |
|
} |
325
|
1 |
|
} |
326
|
|
|
|
327
|
1 |
|
return $this; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Método que genera las urls amigables para usar dentro del framework |
332
|
|
|
* @return Router |
333
|
|
|
*/ |
334
|
1 |
|
public function simpatize() |
335
|
|
|
{ |
336
|
1 |
|
$translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php"; |
337
|
1 |
|
$absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName; |
338
|
1 |
|
$this->generateSlugs($absoluteTranslationFileName); |
339
|
1 |
|
Config::createDir(CONFIG_DIR); |
340
|
1 |
|
Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE); |
|
|
|
|
341
|
|
|
|
342
|
1 |
|
return $this; |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Método que devuelve una ruta del framework |
347
|
|
|
* |
348
|
|
|
* @param string $slug |
349
|
|
|
* @param boolean $absolute |
350
|
|
|
* @param array $params |
351
|
|
|
* |
352
|
|
|
* @return string|null |
353
|
|
|
* @throws RouterException |
354
|
|
|
*/ |
355
|
1 |
|
public function getRoute($slug = '', $absolute = FALSE, $params = []) |
356
|
|
|
{ |
357
|
1 |
|
if (strlen($slug) === 0) { |
358
|
|
|
return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/'; |
359
|
|
|
} |
360
|
1 |
|
if (NULL === $slug || !array_key_exists($slug, $this->slugs)) { |
361
|
|
|
throw new RouterException(_("No existe la ruta especificada")); |
362
|
|
|
} |
363
|
1 |
|
$url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug]; |
364
|
1 |
|
if (!empty($params)) foreach ($params as $key => $value) { |
365
|
|
|
$url = str_replace("{" . $key . "}", $value, $url); |
366
|
1 |
|
} elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) { |
367
|
1 |
|
$url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"]; |
|
|
|
|
368
|
1 |
|
} |
369
|
|
|
|
370
|
1 |
|
return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Método que devuelve las rutas de administración |
375
|
|
|
* @return array |
376
|
|
|
*/ |
377
|
1 |
|
public function getAdminRoutes() |
378
|
|
|
{ |
379
|
1 |
|
return AdminHelper::getAdminRoutes($this->routing); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Método que devuelve le controlador del admin |
384
|
|
|
* @return Admin |
385
|
|
|
*/ |
386
|
|
|
public function getAdmin() |
387
|
|
|
{ |
388
|
|
|
return Admin::getInstance(); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* Método que extrae los dominios |
393
|
|
|
* @return array |
394
|
|
|
*/ |
395
|
|
|
public function getDomains() |
396
|
|
|
{ |
397
|
|
|
return $this->domains ?: []; |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* Método que ejecuta una acción del framework y revisa si lo tenemos cacheado ya o no |
402
|
|
|
* |
403
|
|
|
* @param string $route |
404
|
|
|
* @param array|null $action |
405
|
|
|
* @param types\Controller $class |
406
|
|
|
* @param array $params |
|
|
|
|
407
|
|
|
*/ |
408
|
|
|
protected function executeCachedRoute($route, $action, $class, $params = NULL) |
409
|
|
|
{ |
410
|
|
|
Logger::log('Executing route ' . $route, LOG_INFO); |
411
|
|
|
Security::getInstance()->setSessionKey("__CACHE__", $action); |
412
|
|
|
$cache = Cache::needCache(); |
413
|
|
|
$execute = TRUE; |
414
|
|
|
if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) { |
415
|
|
|
$cacheDataName = $this->cache->getRequestCacheHash(); |
416
|
|
|
$tmpDir = substr($cacheDataName, 0, 2) . DIRECTORY_SEPARATOR . substr($cacheDataName, 2, 2) . DIRECTORY_SEPARATOR; |
|
|
|
|
417
|
|
|
$cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName, |
418
|
|
|
$cache, function () {}); |
|
|
|
|
419
|
|
|
if (NULL !== $cachedData) { |
420
|
|
|
$headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName . ".headers", |
|
|
|
|
421
|
|
|
$cache, function () {}, Cache::JSON); |
|
|
|
|
422
|
|
|
Template::getInstance()->renderCache($cachedData, $headers); |
423
|
|
|
$execute = FALSE; |
424
|
|
|
} |
425
|
|
|
} |
426
|
|
|
if ($execute) { |
427
|
|
|
Logger::log(_('Start executing action'), LOG_DEBUG); |
428
|
|
|
if(false === call_user_func_array(array($class, $action['method']), $params)) { |
429
|
|
|
Logger::log(_('An error ocurred trying to execute the action'), LOG_ERR, [error_get_last()]); |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Parse slugs to create translations |
436
|
|
|
* |
437
|
|
|
* @param string $absoluteTranslationFileName |
438
|
|
|
*/ |
439
|
1 |
|
private function generateSlugs($absoluteTranslationFileName) |
440
|
|
|
{ |
441
|
1 |
|
$translations = I18nHelper::generateTranslationsFile($absoluteTranslationFileName); |
442
|
1 |
|
foreach ($this->routing as $key => &$info) { |
443
|
1 |
|
$keyParts = $key; |
444
|
1 |
|
if (FALSE === strstr("#|#", $key)) { |
445
|
1 |
|
$keyParts = explode("#|#", $key); |
446
|
1 |
|
$keyParts = array_key_exists(1, $keyParts) ? $keyParts[1] : ''; |
447
|
1 |
|
} |
448
|
1 |
|
$slug = RouterHelper::slugify($keyParts); |
449
|
1 |
|
if (NULL !== $slug && !array_key_exists($slug, $translations)) { |
450
|
1 |
|
$translations[$slug] = $key; |
451
|
1 |
|
file_put_contents($absoluteTranslationFileName, "\$translations[\"{$slug}\"] = _(\"{$slug}\");\n", FILE_APPEND); |
|
|
|
|
452
|
1 |
|
} |
453
|
1 |
|
$this->slugs[$slug] = $key; |
454
|
1 |
|
$info["slug"] = $slug; |
455
|
1 |
|
} |
456
|
1 |
|
} |
457
|
|
|
|
458
|
|
|
} |
459
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.