Pluf Framework

Pluf Framework Git Source Tree

Root/src/Pluf/Middleware/Maintenance.php

1<?php
2/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3/*
4# ***** BEGIN LICENSE BLOCK *****
5# This file is part of Plume Framework, a simple PHP Application Framework.
6# Copyright (C) 2001-2007 Loic d'Anterroches and contributors.
7#
8# Plume Framework is free software; you can redistribute it and/or modify
9# it under the terms of the GNU Lesser General Public License as published by
10# the Free Software Foundation; either version 2.1 of the License, or
11# (at your option) any later version.
12#
13# Plume Framework is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Lesser General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21#
22# ***** END LICENSE BLOCK ***** */
23
24/**
25 * Maintenance middleware.
26 *
27 * If a file MAINTENANCE exists in the temp folder then a maintenance
28 * page is shown. If available, a template maintenance.html is used,
29 * else a simple plain text 'Server in maintenance, please retry
30 * later...' is shown.
31 *
32 * This middleware should be
33 *
34 * Only the actions starting with Pluf::f('maintenance_root') are not
35 * interrupted, that way you can access a special url to perform
36 * upgrade.
37 *
38 */
39class Pluf_Middleware_Maintenance
40{
41
42 /**
43 * Process the request.
44 *
45 * @param Pluf_HTTP_Request The request
46 * @return bool false
47 */
48 function process_request(&$request)
49 {
50 if (0 !== strpos($request->query, Pluf::f('maintenance_root')) && file_exists(Pluf::f('tmp_folder').'/MAINTENANCE')) {
51 $res = new Pluf_HTTP_Response('Server in maintenance'."\n\n".'We are upgrading the system to make it better for you, please try again later...', 'text/plain');
52 $res->status_code = 503;
53 return $res;
54 }
55 return false;
56 }
57}
58

Archive Download this file

Branches

Tags