mirror of
https://github.com/php/doc-es.git
synced 2026-03-24 23:42:11 +01:00
git-svn-id: https://svn.php.net/repository/phpdoc/es/trunk@324053 c90b9560-bf6c-de11-be94-00142212c4b1
158 lines
4.6 KiB
XML
158 lines
4.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: a6a1f2a7a647e6b34343bbddbbe8a816903f1bbd Maintainer: seros Status: ready -->
|
|
<!-- Reviewed: no -->
|
|
|
|
<phpdoc:classref xml:id="class.sessionhandlerinterface" xmlns:phpdoc="http://php.net/ns/phpdoc" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
|
|
|
|
<title>La clase SessionHandlerInterface</title>
|
|
<titleabbrev>SessionHandlerInterface</titleabbrev>
|
|
|
|
<partintro>
|
|
|
|
<!-- {{{ SessionHandlerInterface intro -->
|
|
<section xml:id="sessionhandlerinterface.intro">
|
|
&reftitle.intro;
|
|
<para>
|
|
<classname>SessionHandlerInterface</classname> es una
|
|
<link linkend="language.oop5.interfaces">interfaz</link> que define un
|
|
prototipo para crear un gestor de sesiones personalizado. Para pasar un gestor de
|
|
sesiones personalizado a <function>session_set_save_handler</function> usando su
|
|
invocación de <literal>POO</literal>, la clase debe implementar esta interfaz.
|
|
</para>
|
|
<para>
|
|
Observe que los métodos de llamada de retorno de esta clase están diseñados para ser llamados internamente por
|
|
PHP y no para ser llamados desde código de espacio de usuario.
|
|
</para>
|
|
</section>
|
|
<!-- }}} -->
|
|
|
|
<section xml:id="sessionhandlerinterface.synopsis">
|
|
&reftitle.classsynopsis;
|
|
|
|
<!-- {{{ Synopsis -->
|
|
<classsynopsis>
|
|
<ooclass><classname>SessionHandlerInterface</classname></ooclass>
|
|
|
|
<!-- {{{ Class synopsis -->
|
|
<classsynopsisinfo>
|
|
<ooclass>
|
|
<classname>SessionHandlerInterface</classname>
|
|
</ooclass>
|
|
</classsynopsisinfo>
|
|
<!-- }}} -->
|
|
|
|
<classsynopsisinfo role="comment">&Methods;</classsynopsisinfo>
|
|
<xi:include xpointer="xmlns(db=http://docbook.org/ns/docbook) xpointer(id('class.sessionhandlerinterface')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[1])" />
|
|
</classsynopsis>
|
|
<!-- }}} -->
|
|
|
|
</section>
|
|
|
|
<section xml:id="sessionhandlerinterface.examples">
|
|
<example>
|
|
<title>
|
|
Ejemplo usando <classname>SessionHandlerInterface</classname>
|
|
</title>
|
|
<para>
|
|
El siguiente ejemplo proporciona almacenamiento de sesiones basado en ficheros similar al
|
|
gestor de almacenamiento de sesiones predeterminado de PHP <parameter>files</parameter>. Este
|
|
ejemplo podría fácilmente ser extendido para cubrir almacenamiento de bases de datos usando su
|
|
motor de bases de datos favorito soportado por PHP.
|
|
</para>
|
|
<para>
|
|
Observe que usamos el prototipo de POO con <function>session_set_save_handler</function> y
|
|
registramos la función de cierre usando la bandera de parámetro de la función. Esto normalmente es
|
|
aconsejable al registrar objetos como gestores de almacenamiento de sesiones.
|
|
</para>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
class MySessionHandler implements SessionHandlerInterface
|
|
{
|
|
private $savePath;
|
|
|
|
public function open($savePath, $sessionName)
|
|
{
|
|
$this->savePath = $savePath;
|
|
if (!is_dir($this->savePath)) {
|
|
mkdir($this->savePath, 0777);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function close()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public function read($id)
|
|
{
|
|
return (string)@file_get_contents("$this->savePath/sess_$id");
|
|
}
|
|
|
|
public function write($id, $data)
|
|
{
|
|
return file_put_contents("$this->savePath/sess_$id", $data) === false ? false : true;
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$file = "$this->savePath/sess_$id";
|
|
if (file_exists($file)) {
|
|
unlink($file);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function gc($maxlifetime)
|
|
{
|
|
foreach (glob("$this->savePath/sess_*") as $file) {
|
|
if (filemtime($file) + $maxlifetime < time() && file_exists($file)) {
|
|
unlink($file);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
$handler = new MySessionHandler();
|
|
session_set_save_handler($handler, true);
|
|
session_start();
|
|
|
|
// proceed to set and retrieve values by key from $_SESSION
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
</section>
|
|
|
|
</partintro>
|
|
|
|
&reference.session.entities.sessionhandlerinterface;
|
|
|
|
</phpdoc:classref>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|