From 0ef6d55e8ffad1f169ae661f06a1f46c1dce38ac Mon Sep 17 00:00:00 2001
From: arjunrc
Date: Fri, 22 Jan 2016 09:39:19 -0500
Subject: [PATCH 1/6] resolves #1231 - ubuntu package from source instructions
added
---
docs/installationguide/ubuntu.rst | 210 +++++++++---------------------
1 file changed, 63 insertions(+), 147 deletions(-)
diff --git a/docs/installationguide/ubuntu.rst b/docs/installationguide/ubuntu.rst
index 1d5412077..57f1a9646 100644
--- a/docs/installationguide/ubuntu.rst
+++ b/docs/installationguide/ubuntu.rst
@@ -286,192 +286,108 @@ Harder Way: Build Package From Source
-------------------------------------------
(These instructions assume installation from source on a ubuntu 15.x+ system)
-**Step 1:** First make sure you have the needed tools
+**Step 1:** Grab the package installer script
+
+::
+
+ wget https://raw.githubusercontent.com/ZoneMinder/ZoneMinder/master/utils/do_debian_package.sh
+ chmod a+x do_debian_package.sh
+
+
+**Step 2:** Install some core dependencies
::
sudo apt-get update
- sudo apt-get install cmake git
-**Step 2:** Next up make sure you have all the dependencies
+ sudo apt-get install git cmake pbuilder debhelper sphinx-common apache2-dev dh-linktree dh-systemd libavcodec-ffmpeg-dev libavformat-ffmpeg-dev libswscale-ffmpeg-dev libavutil-ffmpeg-dev libavdevice-ffmpeg-dev libbz2-dev libdate-manip-perl libdbd-mysql-perl libgcrypt-dev libcurl4-gnutls-dev libgnutls-openssl-dev libjpeg-dev libmysqlclient-dev libpcre3-dev libphp-serialization-perl libpolkit-gobject-1-dev libsys-mmap-perl libv4l-dev libvlc-dev libjs-mootools mysql-server apache2 libapache2-mod-php5 gdebi
+
+
+**Step 3** Create the package
+
+To build the latest master snapshot:
::
- sudo apt-get install apache2 mysql-server php5 php5-mysql build-essential libmysqlclient-dev libssl-dev libbz2-dev libpcre3-dev libdbi-perl libarchive-zip-perl libdate-manip-perl libdevice-serialport-perl libmime-perl libpcre3 libwww-perl libdbd-mysql-perl libsys-mmap-perl yasm automake autoconf libjpeg8-dev libjpeg8 apache2 libapache2-mod-php5 php5-cli libphp-serialization-perl libgnutls-dev libjpeg8-dev libavcodec-dev libavformat-dev libswscale-dev libavutil-dev libv4l-dev libtool ffmpeg libnetpbm10-dev libavdevice-dev libmime-lite-perl dh-autoreconf dpatch policykit-1 libpolkit-gobject-1-dev libextutils-pkgconfig-perl libcurl3 libvlc-dev libcurl4-openssl-dev curl php5-gd
+ ./do_debian_package.sh `lsb_release -a 2>/dev/null | grep Codename | awk '{print $2}'` `date +%Y%m%d`01 local master
-(you are asked for the mysql root password when installing mysql server - put in a password that you'd like).
-**Step 3:** Download ZoneMinder source code and compile+install:
+To build the latest stable release:
::
- git clone https://github.com/ZoneMinder/ZoneMinder.git
- cd ZoneMinder/
- git submodule init
- git submodule update
- cmake .
- make
- sudo make install
+ ./do_debian_package.sh `lsb_release -a 2>/dev/null | grep Codename | awk '{print $2}'` `date +%Y%m%d`01 local stable
-**Step 4:** Now make sure your symlinks to events and images are set correctly:
+
+Note that the ``lsb_release -a 2>/dev/null | grep Codename | awk '{print $2}'`` part simply extracts your distribution name - like "vivid", "trusty" etc. You can always replace it by your distro name if you know it. As far as the script goes, it checks if your distro is "trusty" in which case it pulls in pre-systemd release configurations and if its not "trusty" it assumes its based on systemd and pulls in systemd related config files.
+
+(At the end the script will ask if you want to retain the checked out version of zoneminder. If you are a developer and are making local changes, make sure you select "y" so that the next time you do the build process mentioned here, it keeps your changes. Selecting any other value than "y" or "Y" will delete the checked out code and only retain the package)
+
+This should now create a bunch of .deb files
+
+**Step 4:** Install the package
::
- sudo ./zmlinkcontent.sh
+ sudo gdebi zoneminder__.deb
+ (example sudo gdebi zoneminder_1.29.0-vivid-2016012001_amd64.deb)
-**Step 5:** Now lets make sure ZM has DB permissions to write to the DB:
+
+**This will report DB errors - ignore - you need to configure the DB and some other stuff**
+
+**Step 5:** Post install configuration
::
+ sudo mysql -uroot -p < /usr/share/zoneminder/db/zm_create.sql
mysql -uroot -p -e "grant select,insert,update,delete,create,alter,index,lock tables on zm.* to 'zmuser'@localhost identified by 'zmpass';"
-**Step 6:** Now lets create the DB & its tables that ZM needs
-
-::
-
- mysql -uroot -p
- Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
- AllowOverride All
- Require all granted
-
+ sudo chown www-data /etc/zm/zm.conf
+ sudo chown -R www-data /usr/share/zoneminder/www/api/
- Alias /zm /usr/local/share/zoneminder/www
-
- php_flag register_globals off
- Options Indexes FollowSymLinks
-
- DirectoryIndex index.php
-
-
-
- AllowOverride All
-
-
-**Step 11:** Now lets make sure ZM can read/write to the zoneminder directory:
+**Step 8:** Restart all services
::
- sudo chown -R www-data:www-data /usr/local/share/zoneminder/
+ sudo service apache2 restart
+ sudo service zoneminder restart
-
-**Step 12:** Make sure you can view Monitor View
-
-1. Open up ZM, configure your monitors and verify you can view Monitor feeds
-2. If not, open up ZM console in your browser, go to ``Options->Path`` and make sure ``PATH_ZMS`` is set to ``/zm/cgi-bin/nph-zms`` and restart ZM
-
-**Step 13**: Edit Timezone in PHP
-
-vi /etc/php5/apache2/php.ini
-Look for [Date] and inside it you will see a date.timezone
-that is commented. remove the comment and specific your timezone.
-Please make sure the timezone is valid (see http://php.net/manual/en/timezones.php)
-
-In my case:
+Check if ZM is running properly
::
- date.timezone = America/New_York
-
-**Step 14:** Finally, lets make a config change to apache (needed for htaccess overrides to work for APIs)
-Edit /etc/apache2/apache2.conf and add this:
-
-::
-
-
- AllowOverride All
- Require all granted
-
-
-Restart apache
-
-::
-
- sudo service apache2 reload
-
-You are done. Lets proceed to make sure everything works:
-
-Making sure ZM and APIs work:
-
-1. open up a browser and go to ``http://localhost/zm`` - should bring up ZM
-2. (OPTIONAL - just for peace of mind) open up a tab and go to ``http://localhost/zm/api`` - should bring up a screen showing CakePHP version with some green color boxes. Green is good. If you see red, or you don't see green, there may be a problem (should not happen). Ignore any warnings in yellow saying "DebugKit" not installed. You don't need it
-3. open up a tab in the same browser and go to ``http://localhost/zm/api/host/getVersion.json``
-
-If it responds with something like:
-
-::
-
- {
- "version": "1.28.107",
- "apiversion": "1.28.107.1"
- }
-
-Then your APIs are working
-
-Make sure ZM and APIs work with security:
-1. Enable OPT_AUTH in ZM
-2. Log out of ZM in browser
-3. Open a NEW tab in the SAME BROWSER (important) and go to ``http://localhost/zm/api/host/getVersion.json`` - should give you "Unauthorized" along with a lot more of text
-4. Go to another tab in the SAME BROWSER (important) and log into ZM
-5. Repeat step 3 and it should give you the ZM and API version
-
-**Congrats** your installation is complete
-
-Suggested changes to MySQL (Optional but recommended)
-------------------------------------------------------
-For most of you Zoneminder will run just fine with the default MySQL settings. There are a couple of settings that may, in time, provide beneficial especially if you have a number of cameras and many events with a lot of files. One setting we recommend is the "innodb_file_per_table" This will be a default setting in MySQL 5.6 but should be added in MySQL 5.5 which comes with Ubuntu 14.04. A description can be found here: http://dev.mysql.com/doc/refman/5.5/en/innodb-multiple-tablespaces.html
-
-To add "innodb_file_per_table" edit the my.cnf file:
-
-``vi /etc/mysql/my.cnf``
-Under [mysqld] add
-``innodb_file_per_table``
-
-Save and exit.
-
-Restart MySQL
-``service mysql restart``
+ sudo service zoneminder status
+
+
+**Step 9:** Make sure streaming works - set PATH_ZMS
+
+open up ZM console in your browser, go to Options->Path and make sure ``PATH_ZMS`` is set to ``/zm/cgi-bin/nph-zms`` and restart ZM
+
+
+**Step 10:** Make sure everything works
+
+* point your browser to http://yourzmip/zm - you should see ZM console running
+* point your browser to http://yourzmip/zm/api/host/getVersion.json - you should see an API version
+* Configure your monitors and make sure its all a-ok
From 680ab0236cb8523c8ff307832180a9743fd237fb Mon Sep 17 00:00:00 2001
From: arjunrc
Date: Sun, 24 Jan 2016 07:47:25 -0500
Subject: [PATCH 2/6] updated ubuntu instructions
---
docs/installationguide/ubuntu.rst | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/installationguide/ubuntu.rst b/docs/installationguide/ubuntu.rst
index 57f1a9646..54df8529a 100644
--- a/docs/installationguide/ubuntu.rst
+++ b/docs/installationguide/ubuntu.rst
@@ -1,5 +1,5 @@
-Ubuntu
-======
+Ubuntu Instruction
+===================
.. contents::
From 5b047dc74b4105b39cacc675eabb8ed9f033cee3 Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen
Date: Sat, 20 Feb 2016 23:58:07 +0200
Subject: [PATCH 3/6] zm_event: fix overlap in memcpy buffers
---
src/zm_event.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/zm_event.cpp b/src/zm_event.cpp
index 1f1fb0f0b..a34ce50a0 100644
--- a/src/zm_event.cpp
+++ b/src/zm_event.cpp
@@ -1121,7 +1121,7 @@ void EventStream::processCommand( const CmdMsg *msg )
DataMsg status_msg;
status_msg.msg_type = MSG_DATA_EVENT;
- memcpy( &status_msg.msg_data, &status_data, sizeof(status_msg.msg_data) );
+ memcpy( &status_msg.msg_data, &status_data, sizeof(status_data) );
if ( sendto( sd, &status_msg, sizeof(status_msg), MSG_DONTWAIT, (sockaddr *)&rem_addr, sizeof(rem_addr) ) < 0 )
{
//if ( errno != EAGAIN )
From 2fc1fc4380d7e4592b0175a3914776310ba03670 Mon Sep 17 00:00:00 2001
From: Andrew Bauer
Date: Mon, 22 Feb 2016 09:18:46 -0600
Subject: [PATCH 4/6] use debian control file to auto-install deps
---
docs/installationguide/ubuntu.rst | 4 +---
utils/do_debian_package.sh | 4 ++++
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/docs/installationguide/ubuntu.rst b/docs/installationguide/ubuntu.rst
index 54df8529a..bad2b651d 100644
--- a/docs/installationguide/ubuntu.rst
+++ b/docs/installationguide/ubuntu.rst
@@ -294,14 +294,12 @@ Harder Way: Build Package From Source
chmod a+x do_debian_package.sh
-**Step 2:** Install some core dependencies
+**Step 2:** Update the system
::
sudo apt-get update
- sudo apt-get install git cmake pbuilder debhelper sphinx-common apache2-dev dh-linktree dh-systemd libavcodec-ffmpeg-dev libavformat-ffmpeg-dev libswscale-ffmpeg-dev libavutil-ffmpeg-dev libavdevice-ffmpeg-dev libbz2-dev libdate-manip-perl libdbd-mysql-perl libgcrypt-dev libcurl4-gnutls-dev libgnutls-openssl-dev libjpeg-dev libmysqlclient-dev libpcre3-dev libphp-serialization-perl libpolkit-gobject-1-dev libsys-mmap-perl libv4l-dev libvlc-dev libjs-mootools mysql-server apache2 libapache2-mod-php5 gdebi
-
**Step 3** Create the package
diff --git a/utils/do_debian_package.sh b/utils/do_debian_package.sh
index 2b4e88f54..6fff59967 100755
--- a/utils/do_debian_package.sh
+++ b/utils/do_debian_package.sh
@@ -52,6 +52,10 @@ else
ln -sf distros/ubuntu1504_cmake debian
fi;
+# Auto-install all ZoneMinder's depedencies using the Debian control file
+sudo apt-get install devscripts equivs
+sudo mk-build-deps -ir ./debian/control
+
if [ -z `hostname -d` ] ; then
AUTHOR="`getent passwd $USER | cut -d ':' -f 5 | cut -d ',' -f 1` <`whoami`@`hostname`.local>"
else
From 7a42a8c3f96dfffdc360b297d6b26157b8bd5b97 Mon Sep 17 00:00:00 2001
From: Andy Bauer
Date: Wed, 24 Feb 2016 10:15:59 -0600
Subject: [PATCH 5/6] add Netcat ONVIF compatible ptz control
---
db/zm_create.sql.in | 1 +
.../lib/ZoneMinder/Control/Netcat.pm | 483 ++++++++++++++++++
2 files changed, 484 insertions(+)
create mode 100644 scripts/ZoneMinder/lib/ZoneMinder/Control/Netcat.pm
diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in
index 7b0a370ee..3614bfedd 100644
--- a/db/zm_create.sql.in
+++ b/db/zm_create.sql.in
@@ -593,6 +593,7 @@ INSERT INTO `Controls` VALUES (NULL,'SunEyes SP-P1802SWPTZ','Libvlc','SPP1802SWP
INSERT INTO `Controls` VALUES (NULL,'Wanscam HW0025','Libvlc','WanscamHW0025', 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 16, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 350, 0, 0, 1, 0, 10, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10, 0, 0, 0, 0);
INSERT INTO `Controls` VALUES (NULL,'IPCC 7210W','Libvlc','IPCC7210W', 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 16, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 350, 0, 0, 1, 0, 10, 0, 0, 1, 0, 0, 0, 0, 1, 0, 10, 0, 0, 0, 0);
INSERT INTO `Controls` VALUES (NULL,'Vivotek ePTZ','Remote','Vivotek_ePTZ',0,0,1,1,0,0,0,1,0,0,0,0,1,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,0,5,0,0,1,0,0,0,0,1,0,5,0,0,0,0);
+INSERT INTO `Controls` VALUES (NULL,'Netcat ONVIF','Ffmpeg','Netcat',0,0,1,1,0,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,100,5,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,100,5,5,0,0,0,1,255,1,1,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0);
--
-- Add some monitor preset values
diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Control/Netcat.pm b/scripts/ZoneMinder/lib/ZoneMinder/Control/Netcat.pm
new file mode 100644
index 000000000..0e273b5b7
--- /dev/null
+++ b/scripts/ZoneMinder/lib/ZoneMinder/Control/Netcat.pm
@@ -0,0 +1,483 @@
+# ==========================================================================
+#
+# ZoneMinder Netcat IP Control Protocol Module, $Date: 2009-11-25 09:20:00 +0000 (Wed, 04 Nov 2009) $, $Revision: 0001 $
+# Copyright (C) 2001-2008 Philip Coombes
+# Converted for use with Netcat IP Camera by Andrew Bauer (knnniggett@users.sourceforge.net)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# ==========================================================================
+#
+# This module contains the first implementation of the Netcat IP camera control
+# protocol
+#
+package ZoneMinder::Control::Netcat;
+
+use 5.006;
+use strict;
+use warnings;
+
+require ZoneMinder::Base;
+require ZoneMinder::Control;
+
+our @ISA = qw(ZoneMinder::Control);
+
+our %CamParams = ();
+
+# ==========================================================================
+#
+# Netcat IP Control Protocol
+# This script sends ONVIF compliant commands and may work with other cameras
+#
+# The Netcat camera gladly accepts any command with or without authentication,
+# which prevented me from developing Onvif authentication in this control script.
+#
+# Basic preset functions are supported, but more advanced features, which make
+# use of abnormally high preset numbers (ir lamp control, tours, pan speed, etc)
+# may or may not work.
+#
+#
+# Possible future improvements (for anyone to improve upon):
+# - Onvif authentication
+# - Build the SOAP commands at runtime rather than use templates
+# - Implement previously mentioned advanced features
+#
+# Implementing the first two will require additional Perl modules, and adding
+# more dependencies to ZoneMinder is always a concern.
+#
+# On ControlAddress use the format :
+# ADDRESS:PORT
+# eg : 10.1.2.1:8899
+# 10.0.100.1:8899
+#
+# Use port 8899 for the Netcat camera
+#
+# Make sure and place a value in the Auto Stop Timeout field.
+# Recommend starting with a value of 1 second, and adjust accordingly.
+#
+# ==========================================================================
+
+use ZoneMinder::Logger qw(:all);
+use ZoneMinder::Config qw(:all);
+
+use Time::HiRes qw( usleep );
+
+sub new
+{
+
+ my $class = shift;
+ my $id = shift;
+ my $self = ZoneMinder::Control->new( $id );
+ my $logindetails = "";
+ bless( $self, $class );
+ srand( time() );
+ return $self;
+}
+
+our $AUTOLOAD;
+
+sub AUTOLOAD
+{
+ my $self = shift;
+ my $class = ref( ) || croak( "$self not object" );
+ my $name = $AUTOLOAD;
+ $name =~ s/.*://;
+ if ( exists($self->{$name}) )
+ {
+ return( $self->{$name} );
+ }
+ Fatal( "Can't access $name member of object of class $class" );
+ }
+
+sub open
+{
+ my $self = shift;
+
+ $self->loadMonitor();
+
+ use LWP::UserAgent;
+ $self->{ua} = LWP::UserAgent->new;
+ $self->{ua}->agent( "ZoneMinder Control Agent/".ZoneMinder::Base::ZM_VERSION );
+
+ $self->{state} = 'open';
+}
+
+sub close
+{
+ my $self = shift;
+ $self->{state} = 'closed';
+}
+
+sub printMsg
+{
+ my $self = shift;
+ my $msg = shift;
+ my $msg_len = length($msg);
+
+ Debug( $msg."[".$msg_len."]" );
+}
+
+sub sendCmd
+{
+ my $self = shift;
+ my $cmd = shift;
+ my $msg = shift;
+ my $content_type = shift;
+ my $result = undef;
+
+ printMsg( $cmd, "Tx" );
+
+ my $server_endpoint = "http://".$self->{Monitor}->{ControlAddress}."/$cmd";
+ my $req = HTTP::Request->new( POST => $server_endpoint );
+ $req->header('content-type' => $content_type);
+ $req->header('Host' => $self->{Monitor}->{ControlAddress});
+ $req->header('content-length' => length($msg));
+ $req->header('accept-encoding' => 'gzip, deflate');
+ $req->header('connection' => 'Close');
+ $req->content($msg);
+
+ my $res = $self->{ua}->request($req);
+
+ if ( $res->is_success ) {
+ $result = !undef;
+ } else {
+ Error( "After sending PTZ command, camera returned the following error:'".$res->status_line()."'" );
+ }
+ return( $result );
+}
+
+sub getCamParams
+{
+ my $self = shift;
+ my $msg = '000';
+ my $server_endpoint = "http://".$self->{Monitor}->{ControlAddress}."/onvif/imaging";
+ my $req = HTTP::Request->new( POST => $server_endpoint );
+ $req->header('content-type' => 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/imaging/wsdl/GetImagingSettings"');
+ $req->header('Host' => $self->{Monitor}->{ControlAddress});
+ $req->header('content-length' => length($msg));
+ $req->header('accept-encoding' => 'gzip, deflate');
+ $req->header('connection' => 'Close');
+ $req->content($msg);
+
+ my $res = $self->{ua}->request($req);
+
+ if ( $res->is_success ) {
+ # We should really use an xml or soap library to parse the xml tags
+ my $content = $res->decoded_content;
+
+ if ($content =~ /.*(.+)<\/tt:Brightness>.*/) {
+ $CamParams{$1} = $2;
+ }
+ if ($content =~ /.*(.+)<\/tt:Contrast>.*/) {
+ $CamParams{$1} = $2;
+ }
+ }
+ else
+ {
+ Error( "Unable to retrieve camera image settings:'".$res->status_line()."'" );
+ }
+}
+
+#autoStop
+#This makes use of the ZoneMinder Auto Stop Timeout on the Control Tab
+sub autoStop
+{
+ my $self = shift;
+ my $autostop = shift;
+
+ if( $autostop ) {
+ Debug( "Auto Stop" );
+ my $cmd = 'onvif/PTZ';
+ my $msg = '000truefalse';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ usleep( $autostop );
+ $self->sendCmd( $cmd, $msg, $content_type );
+ }
+}
+
+# Reset the Camera
+sub reset
+{
+ Debug( "Camera Reset" );
+ my $self = shift;
+ my $cmd = "";
+ my $msg = '';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver10/device/wsdl/SystemReboot"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+}
+
+#Up Arrow
+sub moveConUp
+{
+ Debug( "Move Up" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Down Arrow
+sub moveConDown
+{
+ Debug( "Move Down" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Left Arrow
+sub moveConLeft
+{
+ Debug( "Move Left" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Right Arrow
+sub moveConRight
+{
+ Debug( "Move Right" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Zoom In
+sub zoomConTele
+{
+ Debug( "Zoom Tele" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Zoom Out
+sub zoomConWide
+{
+ Debug( "Zoom Wide" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Diagonally Up Right Arrow
+#This camera does not have builtin diagonal commands so we emulate them
+sub moveConUpRight
+{
+ Debug( "Move Diagonally Up Right" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Diagonally Down Right Arrow
+#This camera does not have builtin diagonal commands so we emulate them
+sub moveConDownRight
+{
+ Debug( "Move Diagonally Down Right" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Diagonally Up Left Arrow
+#This camera does not have builtin diagonal commands so we emulate them
+sub moveConUpLeft
+{
+ Debug( "Move Diagonally Up Left" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Diagonally Down Left Arrow
+#This camera does not have builtin diagonal commands so we emulate them
+sub moveConDownLeft
+{
+ Debug( "Move Diagonally Down Left" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+ $self->autoStop( $self->{Monitor}->{AutoStopTimeout} );
+}
+
+#Stop
+sub moveStop
+{
+ Debug( "Move Stop" );
+ my $self = shift;
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000truefalse';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/ContinuousMove"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+}
+
+#Set Camera Preset
+sub presetSet
+{
+ my $self = shift;
+ my $params = shift;
+ my $preset = $self->getParam( $params, 'preset' );
+ Debug( "Set Preset $preset" );
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000'.$preset.'';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/SetPreset"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+}
+
+#Recall Camera Preset
+sub presetGoto
+{
+ my $self = shift;
+ my $params = shift;
+ my $preset = $self->getParam( $params, 'preset' );
+ Debug( "Goto Preset $preset" );
+ my $cmd = 'onvif/PTZ';
+ my $msg ='000'.$preset.'';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/ptz/wsdl/GotoPreset"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+}
+
+#Horizontal Patrol
+#To be determined if this camera supports this feature
+sub horizontalPatrol
+{
+ Debug( "Horizontal Patrol" );
+ my $self = shift;
+ my $cmd = '';
+ my $msg ='';
+ my $content_type = '';
+# $self->sendCmd( $cmd, $msg, $content_type );
+ Error( "PTZ Command not implemented in control script." );
+}
+
+#Horizontal Patrol Stop
+#To be determined if this camera supports this feature
+sub horizontalPatrolStop
+{
+ Debug( "Horizontal Patrol Stop" );
+ my $self = shift;
+ my $cmd = '';
+ my $msg ='';
+ my $content_type = '';
+# $self->sendCmd( $cmd, $msg, $content_type );
+ Error( "PTZ Command not implemented in control script." );
+}
+
+# Increase Brightness
+sub irisAbsOpen
+{
+ Debug( "Iris $CamParams{'Brightness'}" );
+ my $self = shift;
+ my $params = shift;
+ $self->getCamParams() unless($CamParams{'Brightness'});
+ my $step = $self->getParam( $params, 'step' );
+ my $max = 100;
+
+ $CamParams{'Brightness'} += $step;
+ $CamParams{'Brightness'} = $max if ($CamParams{'Brightness'} > $max);
+
+ my $cmd = 'onvif/imaging';
+ my $msg ='000'.$CamParams{'Brightness'}.'true';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/imaging/wsdl/SetImagingSettings"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+}
+
+# Decrease Brightness
+sub irisAbsClose
+{
+ Debug( "Iris $CamParams{'Brightness'}" );
+ my $self = shift;
+ my $params = shift;
+ $self->getCamParams() unless($CamParams{'brightness'});
+ my $step = $self->getParam( $params, 'step' );
+ my $min = 0;
+
+ $CamParams{'Brightness'} -= $step;
+ $CamParams{'Brightness'} = $min if ($CamParams{'Brightness'} < $min);
+
+ my $cmd = 'onvif/imaging';
+ my $msg ='000'.$CamParams{'Brightness'}.'true';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/imaging/wsdl/SetImagingSettings"';
+ $self->sendCmd( $cmd, $msg, $content_type );
+}
+
+# Increase Contrast
+sub whiteAbsIn
+{
+ Debug( "Iris $CamParams{'Contrast'}" );
+ my $self = shift;
+ my $params = shift;
+ $self->getCamParams() unless($CamParams{'Contrast'});
+ my $step = $self->getParam( $params, 'step' );
+ my $max = 100;
+
+ $CamParams{'Contrast'} += $step;
+ $CamParams{'Contrast'} = $max if ($CamParams{'Contrast'} > $max);
+
+ my $cmd = 'onvif/imaging';
+ my $msg ='000'.$CamParams{'Contrast'}.'true';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/imaging/wsdl/SetImagingSettings"';
+}
+
+# Decrease Contrast
+sub whiteAbsOut
+{
+ Debug( "Iris $CamParams{'Contrast'}" );
+ my $self = shift;
+ my $params = shift;
+ $self->getCamParams() unless($CamParams{'Contrast'});
+ my $step = $self->getParam( $params, 'step' );
+ my $min = 0;
+
+ $CamParams{'Contrast'} -= $step;
+ $CamParams{'Contrast'} = $min if ($CamParams{'Contrast'} < $min);
+
+ my $cmd = 'onvif/imaging';
+ my $msg ='000'.$CamParams{'Contrast'}.'true';
+ my $content_type = 'application/soap+xml; charset=utf-8; action="http://www.onvif.org/ver20/imaging/wsdl/SetImagingSettings"';
+}
+
+1;
+
From b294f210dc765a6a06df5dd92614d8eb53f1ea22 Mon Sep 17 00:00:00 2001
From: SteveGilvarry
Date: Thu, 25 Feb 2016 23:25:24 +1100
Subject: [PATCH 6/6] Update to CakePHP 2.8.0 copy in lib folder
---
web/api/lib/Cake/Cache/Cache.php | 228 +--
web/api/lib/Cake/Cache/CacheEngine.php | 34 +-
web/api/lib/Cake/Cache/Engine/ApcEngine.php | 54 +-
web/api/lib/Cake/Cache/Engine/FileEngine.php | 67 +-
.../lib/Cake/Cache/Engine/MemcacheEngine.php | 48 +-
.../lib/Cake/Cache/Engine/MemcachedEngine.php | 69 +-
web/api/lib/Cake/Cache/Engine/RedisEngine.php | 73 +-
.../lib/Cake/Cache/Engine/WincacheEngine.php | 37 +-
.../lib/Cake/Cache/Engine/XcacheEngine.php | 43 +-
web/api/lib/Cake/Config/routes.php | 13 +-
.../Cake/Configure/ConfigReaderInterface.php | 4 +-
web/api/lib/Cake/Configure/IniReader.php | 13 +-
web/api/lib/Cake/Configure/PhpReader.php | 10 +-
web/api/lib/Cake/Console/Command/AclShell.php | 14 +-
.../Cake/Console/Command/CommandListShell.php | 4 +-
.../Cake/Console/Command/CompletionShell.php | 2 +-
.../lib/Cake/Console/Command/ConsoleShell.php | 28 +-
.../lib/Cake/Console/Command/SchemaShell.php | 56 +-
.../lib/Cake/Console/Command/ServerShell.php | 12 +-
.../Cake/Console/Command/Task/BakeTask.php | 2 +-
.../Cake/Console/Command/Task/CommandTask.php | 12 +-
.../Console/Command/Task/ControllerTask.php | 27 +-
.../Console/Command/Task/DbConfigTask.php | 8 +-
.../Cake/Console/Command/Task/ExtractTask.php | 173 ++-
.../Cake/Console/Command/Task/FixtureTask.php | 25 +-
.../Cake/Console/Command/Task/ModelTask.php | 42 +-
.../Cake/Console/Command/Task/PluginTask.php | 29 +-
.../Cake/Console/Command/Task/ProjectTask.php | 33 +-
.../Cake/Console/Command/Task/TestTask.php | 14 +-
.../Cake/Console/Command/Task/ViewTask.php | 16 +-
.../lib/Cake/Console/Command/TestShell.php | 13 +-
.../lib/Cake/Console/Command/UpgradeShell.php | 33 +-
.../lib/Cake/Console/ConsoleErrorHandler.php | 26 +-
web/api/lib/Cake/Console/ConsoleInput.php | 8 +-
.../lib/Cake/Console/ConsoleInputArgument.php | 12 +-
.../lib/Cake/Console/ConsoleInputOption.php | 12 +-
.../Cake/Console/ConsoleInputSubcommand.php | 2 +-
.../lib/Cake/Console/ConsoleOptionParser.php | 47 +-
web/api/lib/Cake/Console/ConsoleOutput.php | 103 +-
web/api/lib/Cake/Console/HelpFormatter.php | 26 +-
.../Cake/Console/Helper/BaseShellHelper.php | 82 +
.../Console/Helper/ProgressShellHelper.php | 122 ++
.../Cake/Console/Helper/TableShellHelper.php | 124 ++
web/api/lib/Cake/Console/Shell.php | 159 +-
web/api/lib/Cake/Console/ShellDispatcher.php | 23 +-
web/api/lib/Cake/Console/TaskCollection.php | 6 +-
.../default/actions/controller_actions.ctp | 12 +-
.../Templates/default/classes/controller.ctp | 6 +-
.../Templates/default/classes/fixture.ctp | 3 +-
.../Templates/default/classes/model.ctp | 2 +-
.../Templates/default/classes/test.ctp | 1 -
.../Console/Templates/default/views/form.ctp | 6 +-
.../Console/Templates/default/views/index.ctp | 10 +-
.../Console/Templates/default/views/view.ctp | 10 +-
.../lib/Cake/Console/Templates/skel/.htaccess | 6 +-
.../Templates/skel/Config/Schema/db_acl.php | 26 +-
.../Templates/skel/Config/Schema/db_acl.sql | 13 +-
.../Templates/skel/Config/Schema/i18n.php | 32 +-
.../Templates/skel/Config/Schema/sessions.php | 35 +-
.../Templates/skel/Config/bootstrap.php | 5 +-
.../Console/Templates/skel/Config/core.php | 5 -
.../skel/Config/database.php.default | 2 -
.../Templates/skel/Config/email.php.default | 1 -
.../Console/Templates/skel/Console/cake.php | 23 +-
.../skel/Controller/PagesController.php | 3 +-
.../Templates/skel/Test/Case/AllTestsTest.php | 5 +
.../skel/View/Elements/Flash/default.ctp | 1 +
.../skel/View/Emails/html/default.ctp | 5 +-
.../skel/View/Emails/text/default.ctp | 2 -
.../Templates/skel/View/Errors/error400.ctp | 3 -
.../Templates/skel/View/Errors/error500.ctp | 3 -
.../skel/View/Layouts/Emails/html/default.ctp | 2 -
.../skel/View/Layouts/Emails/text/default.ctp | 2 -
.../Templates/skel/View/Layouts/ajax.ctp | 2 -
.../Templates/skel/View/Layouts/default.ctp | 2 -
.../Templates/skel/View/Layouts/error.ctp | 2 -
.../Templates/skel/View/Layouts/flash.ctp | 6 +-
.../Templates/skel/View/Pages/home.ctp | 8 +-
.../lib/Cake/Console/Templates/skel/index.php | 2 -
.../Console/Templates/skel/webroot/.htaccess | 8 +-
.../skel/webroot/css/cake.generic.css | 33 +-
.../Console/Templates/skel/webroot/index.php | 34 +-
.../Console/Templates/skel/webroot/test.php | 15 +-
web/api/lib/Cake/Console/cake | 4 +-
web/api/lib/Cake/Console/cake.bat | 3 -
web/api/lib/Cake/Console/cake.php | 19 +-
.../Cake/Controller/CakeErrorController.php | 4 +-
web/api/lib/Cake/Controller/Component.php | 8 +-
.../Controller/Component/Acl/AclInterface.php | 10 +-
.../Cake/Controller/Component/Acl/DbAcl.php | 21 +-
.../Cake/Controller/Component/Acl/IniAcl.php | 10 +-
.../Cake/Controller/Component/Acl/PhpAcl.php | 30 +-
.../Controller/Component/AclComponent.php | 28 +-
.../Component/Auth/AbstractPasswordHasher.php | 6 +-
.../Component/Auth/ActionsAuthorize.php | 4 +-
.../Component/Auth/BaseAuthenticate.php | 24 +-
.../Component/Auth/BaseAuthorize.php | 22 +-
.../Component/Auth/BasicAuthenticate.php | 29 +-
.../Component/Auth/BlowfishAuthenticate.php | 8 +-
.../Component/Auth/BlowfishPasswordHasher.php | 6 +-
.../Component/Auth/ControllerAuthorize.php | 10 +-
.../Component/Auth/CrudAuthorize.php | 4 +-
.../Component/Auth/DigestAuthenticate.php | 12 +-
.../Component/Auth/FormAuthenticate.php | 10 +-
.../Component/Auth/SimplePasswordHasher.php | 6 +-
.../Controller/Component/AuthComponent.php | 125 +-
.../Controller/Component/CookieComponent.php | 25 +-
.../Controller/Component/EmailComponent.php | 13 +-
.../Controller/Component/FlashComponent.php | 118 ++
.../Component/PaginatorComponent.php | 41 +-
.../Component/RequestHandlerComponent.php | 76 +-
.../Component/SecurityComponent.php | 77 +-
.../Controller/Component/SessionComponent.php | 33 +-
.../Cake/Controller/ComponentCollection.php | 4 +-
web/api/lib/Cake/Controller/Controller.php | 143 +-
web/api/lib/Cake/Controller/Scaffold.php | 25 +-
web/api/lib/Cake/Core/App.php | 231 +--
web/api/lib/Cake/Core/CakePlugin.php | 123 +-
web/api/lib/Cake/Core/Configure.php | 149 +-
web/api/lib/Cake/Core/Object.php | 13 +-
web/api/lib/Cake/Error/ErrorHandler.php | 72 +-
web/api/lib/Cake/Error/ExceptionRenderer.php | 36 +-
web/api/lib/Cake/Error/exceptions.php | 34 +-
web/api/lib/Cake/Event/CakeEvent.php | 21 +-
web/api/lib/Cake/Event/CakeEventListener.php | 6 +-
web/api/lib/Cake/Event/CakeEventManager.php | 31 +-
web/api/lib/Cake/I18n/I18n.php | 102 +-
web/api/lib/Cake/I18n/L10n.php | 6 +-
web/api/lib/Cake/I18n/Multibyte.php | 87 +-
web/api/lib/Cake/LICENSE.txt | 2 +-
web/api/lib/Cake/Log/CakeLog.php | 172 +--
web/api/lib/Cake/Log/CakeLogInterface.php | 4 +-
web/api/lib/Cake/Log/Engine/ConsoleLog.php | 6 +-
web/api/lib/Cake/Log/Engine/FileLog.php | 13 +-
web/api/lib/Cake/Log/Engine/SyslogLog.php | 22 +-
web/api/lib/Cake/Model/AclNode.php | 21 +-
web/api/lib/Cake/Model/Aco.php | 2 -
web/api/lib/Cake/Model/AcoAction.php | 2 -
web/api/lib/Cake/Model/Aro.php | 2 -
.../lib/Cake/Model/Behavior/AclBehavior.php | 16 +-
.../Model/Behavior/ContainableBehavior.php | 12 +-
.../Cake/Model/Behavior/TranslateBehavior.php | 45 +-
.../lib/Cake/Model/Behavior/TreeBehavior.php | 541 ++++---
web/api/lib/Cake/Model/BehaviorCollection.php | 24 +-
web/api/lib/Cake/Model/CakeSchema.php | 145 +-
web/api/lib/Cake/Model/ConnectionManager.php | 92 +-
.../lib/Cake/Model/Datasource/CakeSession.php | 319 ++--
.../lib/Cake/Model/Datasource/DataSource.php | 50 +-
.../Cake/Model/Datasource/Database/Mysql.php | 66 +-
.../Model/Datasource/Database/Postgres.php | 81 +-
.../Cake/Model/Datasource/Database/Sqlite.php | 63 +-
.../Model/Datasource/Database/Sqlserver.php | 77 +-
.../lib/Cake/Model/Datasource/DboSource.php | 400 ++---
.../Model/Datasource/Session/CacheSession.php | 29 +-
.../Session/CakeSessionHandlerInterface.php | 16 +-
.../Datasource/Session/DatabaseSession.php | 53 +-
web/api/lib/Cake/Model/Model.php | 808 ++++++----
web/api/lib/Cake/Model/ModelBehavior.php | 18 +-
web/api/lib/Cake/Model/ModelValidator.php | 48 +-
web/api/lib/Cake/Model/Permission.php | 10 +-
.../Model/Validator/CakeValidationRule.php | 40 +-
.../Model/Validator/CakeValidationSet.php | 53 +-
web/api/lib/Cake/Network/CakeRequest.php | 203 ++-
web/api/lib/Cake/Network/CakeResponse.php | 145 +-
web/api/lib/Cake/Network/CakeSocket.php | 147 +-
.../Cake/Network/Email/AbstractTransport.php | 6 +-
web/api/lib/Cake/Network/Email/CakeEmail.php | 312 ++--
.../lib/Cake/Network/Email/SmtpTransport.php | 37 +-
.../Cake/Network/Http/BasicAuthentication.php | 16 +-
.../Network/Http/DigestAuthentication.php | 18 +-
.../lib/Cake/Network/Http/HttpResponse.php | 2 +-
web/api/lib/Cake/Network/Http/HttpSocket.php | 141 +-
.../Cake/Network/Http/HttpSocketResponse.php | 63 +-
web/api/lib/Cake/Routing/Dispatcher.php | 14 +-
web/api/lib/Cake/Routing/DispatcherFilter.php | 8 +-
.../Cake/Routing/Filter/AssetDispatcher.php | 23 +-
.../Cake/Routing/Filter/CacheDispatcher.php | 4 +-
web/api/lib/Cake/Routing/Route/CakeRoute.php | 30 +-
.../lib/Cake/Routing/Route/RedirectRoute.php | 6 +-
web/api/lib/Cake/Routing/Router.php | 262 ++--
web/api/lib/Cake/Test/Case/BasicsTest.php | 37 +-
.../lib/Cake/Test/Case/Cache/CacheTest.php | 19 +
.../Test/Case/Cache/Engine/ApcEngineTest.php | 21 +-
.../Test/Case/Cache/Engine/FileEngineTest.php | 18 +
.../Case/Cache/Engine/MemcacheEngineTest.php | 30 +
.../Case/Cache/Engine/MemcachedEngineTest.php | 64 +-
.../Case/Cache/Engine/RedisEngineTest.php | 19 +
.../Case/Cache/Engine/WincacheEngineTest.php | 19 +
.../Case/Cache/Engine/XcacheEngineTest.php | 20 +
.../Console/Command/CompletionShellTest.php | 2 +-
.../Case/Console/Command/SchemaShellTest.php | 12 +-
.../Console/Command/Task/CommandTaskTest.php | 6 +-
.../Command/Task/ControllerTaskTest.php | 6 +-
.../Console/Command/Task/ExtractTaskTest.php | 59 +-
.../Console/Command/Task/FixtureTaskTest.php | 11 +-
.../Console/Command/Task/ModelTaskTest.php | 34 +-
.../Console/Command/Task/PluginTaskTest.php | 35 +-
.../Console/Command/Task/ProjectTaskTest.php | 1 -
.../Console/Command/Task/ViewTaskTest.php | 3 +-
.../Case/Console/Command/TestShellTest.php | 18 +
.../Case/Console/ConsoleErrorHandlerTest.php | 27 +
.../Case/Console/ConsoleOptionParserTest.php | 25 +-
.../Test/Case/Console/ConsoleOutputTest.php | 32 +
.../Helper/ProgressShellHelperTest.php | 223 +++
.../Console/Helper/TableShellHelperTest.php | 201 +++
.../Test/Case/Console/ShellDispatcherTest.php | 8 +
.../lib/Cake/Test/Case/Console/ShellTest.php | 101 +-
.../Controller/Component/Acl/DbAclTest.php | 11 +-
.../Controller/Component/AclComponentTest.php | 2 +-
.../Component/Auth/BasicAuthenticateTest.php | 107 +-
.../Auth/BlowfishAuthenticateTest.php | 2 +-
.../Auth/ControllerAuthorizeTest.php | 11 +-
.../Component/Auth/DigestAuthenticateTest.php | 27 +-
.../Component/Auth/FormAuthenticateTest.php | 35 +-
.../Component/AuthComponentTest.php | 280 +++-
.../Component/EmailComponentTest.php | 53 +-
.../Component/FlashComponentTest.php | 181 +++
.../Component/PaginatorComponentTest.php | 43 +-
.../Component/RequestHandlerComponentTest.php | 19 +-
.../Component/SecurityComponentTest.php | 160 +-
.../Component/SessionComponentTest.php | 5 +-
.../Test/Case/Controller/ComponentTest.php | 2 +-
.../Test/Case/Controller/ControllerTest.php | 50 +-
.../Test/Case/Controller/ScaffoldTest.php | 75 +-
web/api/lib/Cake/Test/Case/Core/AppTest.php | 53 +-
.../Cake/Test/Case/Core/CakePluginTest.php | 1 -
.../lib/Cake/Test/Case/Core/ConfigureTest.php | 53 +-
.../lib/Cake/Test/Case/Core/ObjectTest.php | 9 +-
.../Cake/Test/Case/Error/ErrorHandlerTest.php | 66 +
.../Test/Case/Error/ExceptionRendererTest.php | 67 +
.../Test/Case/Event/CakeEventManagerTest.php | 15 +-
.../Cake/Test/Case/Event/CakeEventTest.php | 7 +-
web/api/lib/Cake/Test/Case/I18n/I18nTest.php | 202 ++-
.../Test/Case/Log/Engine/ConsoleLogTest.php | 6 +-
.../Test/Case/Log/Engine/SyslogLogTest.php | 2 -
.../lib/Cake/Test/Case/Model/AclNodeTest.php | 7 +-
.../Model/Behavior/TranslateBehaviorTest.php | 52 +-
.../Model/Behavior/TreeBehaviorAfterTest.php | 2 +-
.../Model/Behavior/TreeBehaviorNumberTest.php | 176 ++-
.../Model/Behavior/TreeBehaviorScopedTest.php | 12 +-
.../Model/Behavior/TreeBehaviorUuidTest.php | 6 +-
.../Case/Model/BehaviorCollectionTest.php | 12 +-
.../Cake/Test/Case/Model/CakeSchemaTest.php | 20 +-
.../Case/Model/Datasource/CakeSessionTest.php | 78 +-
.../Case/Model/Datasource/DataSourceTest.php | 2 +-
.../Model/Datasource/Database/MysqlTest.php | 177 ++-
.../Datasource/Database/PostgresTest.php | 120 +-
.../Model/Datasource/Database/SqliteTest.php | 69 +-
.../Datasource/Database/SqlserverTest.php | 21 +-
.../Case/Model/Datasource/DboSourceTest.php | 401 ++++-
.../Datasource/Session/CacheSessionTest.php | 6 +-
.../Session/DatabaseSessionTest.php | 86 +-
.../Case/Model/ModelCrossSchemaHabtmTest.php | 6 +-
.../Test/Case/Model/ModelIntegrationTest.php | 48 +-
.../Cake/Test/Case/Model/ModelReadTest.php | 314 +++-
.../Cake/Test/Case/Model/ModelTestBase.php | 4 +-
.../Test/Case/Model/ModelValidationTest.php | 244 ++-
.../Cake/Test/Case/Model/ModelWriteTest.php | 1317 ++++++++++++++---
.../Validator/CakeValidationRuleTest.php | 18 +-
.../Model/Validator/CakeValidationSetTest.php | 78 +-
web/api/lib/Cake/Test/Case/Model/models.php | 207 ++-
.../Test/Case/Network/CakeRequestTest.php | 256 +++-
.../Test/Case/Network/CakeResponseTest.php | 229 ++-
.../Cake/Test/Case/Network/CakeSocketTest.php | 54 +-
.../Test/Case/Network/Email/CakeEmailTest.php | 361 +++--
.../Case/Network/Email/DebugTransportTest.php | 1 -
.../Case/Network/Email/MailTransportTest.php | 1 -
.../Case/Network/Email/SmtpTransportTest.php | 97 +-
.../Network/Http/BasicAuthenticationTest.php | 41 +
.../Network/Http/DigestAuthenticationTest.php | 2 +-
.../Case/Network/Http/HttpResponseTest.php | 10 +-
.../Test/Case/Network/Http/HttpSocketTest.php | 243 ++-
.../Cake/Test/Case/Routing/DispatcherTest.php | 28 +-
.../Routing/Filter/AssetDispatcherTest.php | 90 +-
.../Test/Case/Routing/Route/CakeRouteTest.php | 47 +
.../Case/Routing/Route/RedirectRouteTest.php | 20 +-
.../lib/Cake/Test/Case/Routing/RouterTest.php | 23 +-
.../Test/Case/TestSuite/CakeTestCaseTest.php | 72 +-
.../Case/TestSuite/CakeTestFixtureTest.php | 4 +-
.../Case/TestSuite/ControllerTestCaseTest.php | 30 +-
.../Case/TestSuite/HtmlCoverageReportTest.php | 8 +-
.../TestSuite/Stub/ConsoleOutputStubTest.php | 62 +
.../Cake/Test/Case/Utility/CakeTextTest.php | 874 +++++++++++
.../Cake/Test/Case/Utility/CakeTimeTest.php | 86 +-
.../Test/Case/Utility/ClassRegistryTest.php | 2 +-
.../Cake/Test/Case/Utility/DebuggerTest.php | 13 +-
.../lib/Cake/Test/Case/Utility/FileTest.php | 70 +-
.../lib/Cake/Test/Case/Utility/FolderTest.php | 49 +-
.../lib/Cake/Test/Case/Utility/HashTest.php | 295 +++-
.../Cake/Test/Case/Utility/InflectorTest.php | 191 ++-
.../Case/Utility/ObjectCollectionTest.php | 35 +-
.../Cake/Test/Case/Utility/SanitizeTest.php | 4 +-
.../Cake/Test/Case/Utility/SecurityTest.php | 40 +-
.../lib/Cake/Test/Case/Utility/SetTest.php | 1 -
.../Cake/Test/Case/Utility/ValidationTest.php | 300 ++--
.../lib/Cake/Test/Case/Utility/XmlTest.php | 26 +-
.../Test/Case/View/Helper/FlashHelperTest.php | 157 ++
.../Test/Case/View/Helper/FormHelperTest.php | 575 ++++++-
.../Test/Case/View/Helper/HtmlHelperTest.php | 62 +-
.../Case/View/Helper/PaginatorHelperTest.php | 489 ++++--
.../Test/Case/View/Helper/TextHelperTest.php | 173 ++-
.../Test/Case/View/Helper/TimeHelperTest.php | 2 +-
.../lib/Cake/Test/Case/View/HelperTest.php | 8 +-
.../lib/Cake/Test/Case/View/JsonViewTest.php | 98 ++
.../lib/Cake/Test/Case/View/MediaViewTest.php | 10 -
web/api/lib/Cake/Test/Case/View/ViewTest.php | 118 +-
.../lib/Cake/Test/Case/View/XmlViewTest.php | 70 +
.../Cake/Test/Fixture/AfterTreeFixture.php | 2 +-
.../lib/Cake/Test/Fixture/ArmorFixture.php | 2 +-
.../Cake/Test/Fixture/ArmorsPlayerFixture.php | 2 +-
.../Cake/Test/Fixture/DependencyFixture.php | 3 +-
.../lib/Cake/Test/Fixture/JoinABFixture.php | 2 +-
.../lib/Cake/Test/Fixture/JoinACFixture.php | 2 +-
.../Cake/Test/Fixture/NumberTreeFixture.php | 3 +-
web/api/lib/Cake/Test/Fixture/TagFixture.php | 4 +-
.../Test/Fixture/TranslateArticleFixture.php | 2 +-
.../Cake/Test/Fixture/TranslateFixture.php | 2 +-
.../Test/Fixture/TranslateTableFixture.php | 2 +-
.../Fixture/TranslateWithPrefixFixture.php | 5 +-
.../Controller/ActionsUsingSessions.ctp | 12 +-
.../Test/bake_compare/Controller/Scaffold.ctp | 1 -
.../lib/Cake/Test/bake_compare/View/index.ctp | 58 +
.../Controller/TestsAppsController.php | 4 +
.../Lib/Cache/Engine/TestAppCacheEngine.php | 3 +
.../Locale/nld/LC_MESSAGES/default.po | 32 +
.../Locale/nld_mo/LC_MESSAGES/default.mo | Bin 0 -> 392 bytes
.../Locale/po/LC_MESSAGES/test_plugin.po | 21 +
.../Locale/rule_15_mo/LC_MESSAGES/core.mo | Bin 0 -> 875 bytes
.../Locale/rule_15_mo/LC_MESSAGES/default.mo | Bin 0 -> 769 bytes
.../Locale/rule_15_po/LC_MESSAGES/core.po | 25 +
.../Locale/rule_15_po/LC_MESSAGES/default.po | 25 +
.../Datasource/Session/TestAppLibSession.php | 6 +-
.../lib/Cake/Test/test_app/Model/Extract.php | 2 +-
.../Cake/Test/test_app/Model/PersisterOne.php | 2 +-
.../Console/Command/TestPluginShell.php | 31 +
.../Cache/Engine/TestPluginCacheEngine.php | 3 +
.../Routing/Filter/Test2DispatcherFilter.php | 2 -
.../Routing/Filter/TestDispatcherFilter.php | 2 -
.../TestPluginPersisterOneBehavior.php | 3 -
.../TestPluginPersisterTwoBehavior.php | 3 -
.../Datasource/Session/TestPluginSession.php | 5 +
.../TestPlugin/Model/TestPluginAuthUser.php | 2 +-
.../TestPlugin/Model/TestPluginAuthors.php | 7 +-
.../TestPlugin/Model/TestPluginComment.php | 3 -
.../TestPlugin/View/Errors/error500.ctp | 10 +
.../test_app/View/Elements/Flash/default.ctp | 1 +
.../test_app/View/Elements/flash_classy.ctp | 1 +
.../test_app/View/Elements/flash_helper.ctp | 5 +
.../Test/test_app/View/Elements/html_call.ctp | 3 +-
.../test_app/View/Emails/html/default.ctp | 3 +-
.../test_app/View/Emails/html/long_line.ctp | 14 +
.../Cake/Test/test_app/View/Layouts/ajax2.ctp | 3 +-
.../Cake/Test/test_app/View/Layouts/flash.ctp | 4 +-
.../test_app/View/Layouts/rss/default.ctp | 4 +-
.../Cake/Test/test_app/View/Pages/extract.ctp | 10 +
.../test_app/View/Posts/helper_overwrite.ctp | 3 +-
.../Test/test_app/View/Posts/parent_view.ctp | 2 +-
.../test_app/View/Posts/test_nocache_tags.ctp | 2 +-
.../Themed/TestTheme/Emails/text/themed.ctp | 2 +-
.../View/Themed/TestTheme/Layouts/default.ctp | 2 +-
web/api/lib/Cake/TestSuite/CakeTestCase.php | 156 +-
web/api/lib/Cake/TestSuite/CakeTestLoader.php | 18 +-
web/api/lib/Cake/TestSuite/CakeTestRunner.php | 14 +-
.../Cake/TestSuite/CakeTestSuiteCommand.php | 12 +-
.../TestSuite/CakeTestSuiteDispatcher.php | 34 +-
.../lib/Cake/TestSuite/ControllerTestCase.php | 28 +-
.../TestSuite/Coverage/BaseCoverageReport.php | 9 +-
.../TestSuite/Coverage/HtmlCoverageReport.php | 23 +-
.../TestSuite/Fixture/CakeFixtureManager.php | 6 +-
.../TestSuite/Fixture/CakeTestFixture.php | 26 +-
.../Cake/TestSuite/Fixture/CakeTestModel.php | 10 +-
.../TestSuite/Reporter/CakeBaseReporter.php | 44 +-
.../TestSuite/Reporter/CakeHtmlReporter.php | 55 +-
.../Cake/TestSuite/Stub/ConsoleOutputStub.php | 89 ++
.../lib/Cake/TestSuite/templates/header.php | 2 +-
.../lib/Cake/TestSuite/templates/phpunit.php | 7 +-
web/api/lib/Cake/Utility/CakeNumber.php | 68 +-
web/api/lib/Cake/Utility/CakeText.php | 710 +++++++++
web/api/lib/Cake/Utility/CakeTime.php | 490 +++---
web/api/lib/Cake/Utility/ClassRegistry.php | 29 +-
web/api/lib/Cake/Utility/Debugger.php | 88 +-
web/api/lib/Cake/Utility/File.php | 67 +-
web/api/lib/Cake/Utility/Folder.php | 119 +-
web/api/lib/Cake/Utility/Hash.php | 259 ++--
web/api/lib/Cake/Utility/Inflector.php | 289 ++--
web/api/lib/Cake/Utility/ObjectCollection.php | 23 +-
web/api/lib/Cake/Utility/Sanitize.php | 4 +-
web/api/lib/Cake/Utility/Security.php | 47 +-
web/api/lib/Cake/Utility/Set.php | 53 +-
web/api/lib/Cake/Utility/String.php | 671 +--------
web/api/lib/Cake/Utility/Validation.php | 394 ++---
web/api/lib/Cake/Utility/Xml.php | 48 +-
web/api/lib/Cake/VERSION.txt | 2 +-
.../lib/Cake/View/Elements/Flash/default.ctp | 7 +
.../lib/Cake/View/Elements/Flash/error.ctp | 1 +
.../lib/Cake/View/Elements/Flash/success.ctp | 1 +
.../View/Elements/exception_stack_trace.ctp | 2 +-
web/api/lib/Cake/View/Errors/fatal_error.ctp | 7 +-
.../lib/Cake/View/Errors/missing_action.ctp | 6 +-
.../lib/Cake/View/Errors/missing_behavior.ctp | 6 +-
.../Cake/View/Errors/missing_component.ctp | 8 +-
.../Cake/View/Errors/missing_connection.ctp | 2 -
.../Cake/View/Errors/missing_controller.ctp | 6 +-
.../lib/Cake/View/Errors/missing_database.ctp | 6 +-
.../Cake/View/Errors/missing_datasource.ctp | 8 +-
.../View/Errors/missing_datasource_config.ctp | 6 +-
.../lib/Cake/View/Errors/missing_helper.ctp | 6 +-
.../lib/Cake/View/Errors/missing_layout.ctp | 25 +-
.../lib/Cake/View/Errors/missing_plugin.ctp | 6 +-
.../lib/Cake/View/Errors/missing_table.ctp | 8 +-
web/api/lib/Cake/View/Errors/missing_view.ctp | 23 +-
web/api/lib/Cake/View/Errors/pdo_error.ctp | 6 +-
.../lib/Cake/View/Errors/private_action.ctp | 6 +-
.../lib/Cake/View/Errors/scaffold_error.ctp | 8 +-
web/api/lib/Cake/View/Helper.php | 86 +-
web/api/lib/Cake/View/Helper/CacheHelper.php | 28 +-
web/api/lib/Cake/View/Helper/FlashHelper.php | 91 ++
web/api/lib/Cake/View/Helper/FormHelper.php | 333 +++--
web/api/lib/Cake/View/Helper/HtmlHelper.php | 131 +-
.../Cake/View/Helper/JqueryEngineHelper.php | 4 +-
.../Cake/View/Helper/JsBaseEngineHelper.php | 7 +-
web/api/lib/Cake/View/Helper/JsHelper.php | 13 +-
.../Cake/View/Helper/MootoolsEngineHelper.php | 8 +-
web/api/lib/Cake/View/Helper/NumberHelper.php | 39 +-
.../lib/Cake/View/Helper/PaginatorHelper.php | 139 +-
.../View/Helper/PrototypeEngineHelper.php | 8 +-
web/api/lib/Cake/View/Helper/RssHelper.php | 6 +-
.../lib/Cake/View/Helper/SessionHelper.php | 42 +-
web/api/lib/Cake/View/Helper/TextHelper.php | 75 +-
web/api/lib/Cake/View/Helper/TimeHelper.php | 168 +--
web/api/lib/Cake/View/HelperCollection.php | 11 +-
web/api/lib/Cake/View/JsonView.php | 31 +-
web/api/lib/Cake/View/MediaView.php | 16 +-
web/api/lib/Cake/View/ScaffoldView.php | 2 +-
web/api/lib/Cake/View/Scaffolds/form.ctp | 14 +-
web/api/lib/Cake/View/Scaffolds/index.ctp | 24 +-
web/api/lib/Cake/View/Scaffolds/view.ctp | 6 +-
web/api/lib/Cake/View/ThemeView.php | 2 +-
web/api/lib/Cake/View/View.php | 130 +-
web/api/lib/Cake/View/ViewBlock.php | 18 +-
web/api/lib/Cake/View/XmlView.php | 16 +-
web/api/lib/Cake/basics.php | 485 ++++--
web/api/lib/Cake/bootstrap.php | 71 +-
443 files changed, 19245 insertions(+), 7546 deletions(-)
mode change 100755 => 100644 web/api/lib/Cake/Cache/Engine/MemcachedEngine.php
create mode 100644 web/api/lib/Cake/Console/Helper/BaseShellHelper.php
create mode 100644 web/api/lib/Cake/Console/Helper/ProgressShellHelper.php
create mode 100644 web/api/lib/Cake/Console/Helper/TableShellHelper.php
create mode 100644 web/api/lib/Cake/Console/Templates/skel/View/Elements/Flash/default.ctp
create mode 100644 web/api/lib/Cake/Controller/Component/FlashComponent.php
mode change 100755 => 100644 web/api/lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php
create mode 100644 web/api/lib/Cake/Test/Case/Console/Helper/ProgressShellHelperTest.php
create mode 100644 web/api/lib/Cake/Test/Case/Console/Helper/TableShellHelperTest.php
create mode 100644 web/api/lib/Cake/Test/Case/Controller/Component/FlashComponentTest.php
create mode 100644 web/api/lib/Cake/Test/Case/TestSuite/Stub/ConsoleOutputStubTest.php
create mode 100644 web/api/lib/Cake/Test/Case/Utility/CakeTextTest.php
create mode 100644 web/api/lib/Cake/Test/Case/View/Helper/FlashHelperTest.php
mode change 100755 => 100644 web/api/lib/Cake/Test/Case/View/Helper/FormHelperTest.php
create mode 100644 web/api/lib/Cake/Test/bake_compare/View/index.ctp
create mode 100644 web/api/lib/Cake/Test/test_app/Locale/nld/LC_MESSAGES/default.po
create mode 100644 web/api/lib/Cake/Test/test_app/Locale/nld_mo/LC_MESSAGES/default.mo
create mode 100644 web/api/lib/Cake/Test/test_app/Locale/po/LC_MESSAGES/test_plugin.po
create mode 100644 web/api/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/core.mo
create mode 100644 web/api/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/default.mo
create mode 100644 web/api/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po
create mode 100644 web/api/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/default.po
create mode 100644 web/api/lib/Cake/Test/test_app/Plugin/TestPlugin/Console/Command/TestPluginShell.php
create mode 100644 web/api/lib/Cake/Test/test_app/Plugin/TestPlugin/View/Errors/error500.ctp
create mode 100644 web/api/lib/Cake/Test/test_app/View/Elements/Flash/default.ctp
create mode 100644 web/api/lib/Cake/Test/test_app/View/Elements/flash_classy.ctp
create mode 100644 web/api/lib/Cake/Test/test_app/View/Elements/flash_helper.ctp
create mode 100644 web/api/lib/Cake/Test/test_app/View/Emails/html/long_line.ctp
create mode 100644 web/api/lib/Cake/TestSuite/Stub/ConsoleOutputStub.php
create mode 100644 web/api/lib/Cake/Utility/CakeText.php
create mode 100644 web/api/lib/Cake/View/Elements/Flash/default.ctp
create mode 100644 web/api/lib/Cake/View/Elements/Flash/error.ctp
create mode 100644 web/api/lib/Cake/View/Elements/Flash/success.ctp
create mode 100644 web/api/lib/Cake/View/Helper/FlashHelper.php
mode change 100755 => 100644 web/api/lib/Cake/View/Helper/FormHelper.php
diff --git a/web/api/lib/Cake/Cache/Cache.php b/web/api/lib/Cake/Cache/Cache.php
index a75f0acfd..a7a01d0a1 100644
--- a/web/api/lib/Cake/Cache/Cache.php
+++ b/web/api/lib/Cake/Cache/Cache.php
@@ -26,12 +26,12 @@ App::uses('CacheEngine', 'Cache');
* You can configure Cache engines in your application's `bootstrap.php` file. A sample configuration would
* be
*
- * {{{
+ * ```
* Cache::config('shared', array(
* 'engine' => 'Apc',
* 'prefix' => 'my_app_'
* ));
- * }}}
+ * ```
*
* This would configure an APC cache engine to the 'shared' alias. You could then read and write
* to that cache alias by using it for the `$config` parameter in the various Cache methods. In
@@ -113,11 +113,11 @@ class Cache {
* - `user` Used by Xcache. Username for XCache
* - `password` Used by Xcache/Redis. Password for XCache/Redis
*
- * @see app/Config/core.php for configuration settings
* @param string $name Name of the configuration
* @param array $settings Optional associative array of settings passed to the engine
* @return array array(engine, settings) on success, false on failure
* @throws CacheException
+ * @see app/Config/core.php for configuration settings
*/
public static function config($name = null, $settings = array()) {
if (is_array($name)) {
@@ -125,33 +125,33 @@ class Cache {
}
$current = array();
- if (isset(self::$_config[$name])) {
- $current = self::$_config[$name];
+ if (isset(static::$_config[$name])) {
+ $current = static::$_config[$name];
}
if (!empty($settings)) {
- self::$_config[$name] = $settings + $current;
+ static::$_config[$name] = $settings + $current;
}
- if (empty(self::$_config[$name]['engine'])) {
+ if (empty(static::$_config[$name]['engine'])) {
return false;
}
- if (!empty(self::$_config[$name]['groups'])) {
- foreach (self::$_config[$name]['groups'] as $group) {
- self::$_groups[$group][] = $name;
- sort(self::$_groups[$group]);
- self::$_groups[$group] = array_unique(self::$_groups[$group]);
+ if (!empty(static::$_config[$name]['groups'])) {
+ foreach (static::$_config[$name]['groups'] as $group) {
+ static::$_groups[$group][] = $name;
+ sort(static::$_groups[$group]);
+ static::$_groups[$group] = array_unique(static::$_groups[$group]);
}
}
- $engine = self::$_config[$name]['engine'];
+ $engine = static::$_config[$name]['engine'];
- if (!isset(self::$_engines[$name])) {
- self::_buildEngine($name);
- $settings = self::$_config[$name] = self::settings($name);
- } elseif ($settings = self::set(self::$_config[$name], null, $name)) {
- self::$_config[$name] = $settings;
+ if (!isset(static::$_engines[$name])) {
+ static::_buildEngine($name);
+ $settings = static::$_config[$name] = static::settings($name);
+ } elseif ($settings = static::set(static::$_config[$name], null, $name)) {
+ static::$_config[$name] = $settings;
}
return compact('engine', 'settings');
}
@@ -160,11 +160,11 @@ class Cache {
* Finds and builds the instance of the required engine class.
*
* @param string $name Name of the config array that needs an engine instance built
- * @return boolean
+ * @return bool
* @throws CacheException
*/
protected static function _buildEngine($name) {
- $config = self::$_config[$name];
+ $config = static::$_config[$name];
list($plugin, $class) = pluginSplit($config['engine'], true);
$cacheClass = $class . 'Engine';
@@ -176,12 +176,17 @@ class Cache {
if (!is_subclass_of($cacheClass, 'CacheEngine')) {
throw new CacheException(__d('cake_dev', 'Cache engines must use %s as a base class.', 'CacheEngine'));
}
- self::$_engines[$name] = new $cacheClass();
- if (!self::$_engines[$name]->init($config)) {
- throw new CacheException(__d('cake_dev', 'Cache engine %s is not properly configured.', $name));
+ static::$_engines[$name] = new $cacheClass();
+ if (!static::$_engines[$name]->init($config)) {
+ $msg = __d(
+ 'cake_dev',
+ 'Cache engine "%s" is not properly configured. Ensure required extensions are installed, and credentials/permissions are correct',
+ $name
+ );
+ throw new CacheException($msg);
}
- if (self::$_engines[$name]->settings['probability'] && time() % self::$_engines[$name]->settings['probability'] === 0) {
- self::$_engines[$name]->gc();
+ if (static::$_engines[$name]->settings['probability'] && time() % static::$_engines[$name]->settings['probability'] === 0) {
+ static::$_engines[$name]->gc();
}
return true;
}
@@ -192,22 +197,22 @@ class Cache {
* @return array Array of configured Cache config names.
*/
public static function configured() {
- return array_keys(self::$_config);
+ return array_keys(static::$_config);
}
/**
* Drops a cache engine. Deletes the cache configuration information
- * If the deleted configuration is the last configuration using an certain engine,
+ * If the deleted configuration is the last configuration using a certain engine,
* the Engine instance is also unset.
*
* @param string $name A currently configured cache config you wish to remove.
- * @return boolean success of the removal, returns false when the config does not exist.
+ * @return bool success of the removal, returns false when the config does not exist.
*/
public static function drop($name) {
- if (!isset(self::$_config[$name])) {
+ if (!isset(static::$_config[$name])) {
return false;
}
- unset(self::$_config[$name], self::$_engines[$name]);
+ unset(static::$_config[$name], static::$_engines[$name]);
return true;
}
@@ -238,29 +243,29 @@ class Cache {
if (is_array($settings) && $value !== null) {
$config = $value;
}
- if (!isset(self::$_config[$config]) || !isset(self::$_engines[$config])) {
+ if (!isset(static::$_config[$config]) || !isset(static::$_engines[$config])) {
return false;
}
if (!empty($settings)) {
- self::$_reset = true;
+ static::$_reset = true;
}
- if (self::$_reset === true) {
+ if (static::$_reset === true) {
if (empty($settings)) {
- self::$_reset = false;
- $settings = self::$_config[$config];
+ static::$_reset = false;
+ $settings = static::$_config[$config];
} else {
if (is_string($settings) && $value !== null) {
$settings = array($settings => $value);
}
- $settings += self::$_config[$config];
+ $settings += static::$_config[$config];
if (isset($settings['duration']) && !is_numeric($settings['duration'])) {
$settings['duration'] = strtotime($settings['duration']) - time();
}
}
- self::$_engines[$config]->settings = $settings;
+ static::$_engines[$config]->settings = $settings;
}
- return self::settings($config);
+ return static::settings($config);
}
/**
@@ -269,11 +274,11 @@ class Cache {
* Permanently remove all expired and deleted data
*
* @param string $config [optional] The config name you wish to have garbage collected. Defaults to 'default'
- * @param integer $expires [optional] An expires timestamp. Defaults to NULL
- * @return void
+ * @param int $expires [optional] An expires timestamp. Defaults to NULL
+ * @return bool
*/
public static function gc($config = 'default', $expires = null) {
- self::$_engines[$config]->gc($expires);
+ return static::$_engines[$config]->gc($expires);
}
/**
@@ -292,32 +297,32 @@ class Cache {
* @param string $key Identifier for the data
* @param mixed $value Data to be cached - anything except a resource
* @param string $config Optional string configuration name to write to. Defaults to 'default'
- * @return boolean True if the data was successfully cached, false on failure
+ * @return bool True if the data was successfully cached, false on failure
*/
public static function write($key, $value, $config = 'default') {
- $settings = self::settings($config);
+ $settings = static::settings($config);
if (empty($settings)) {
return false;
}
- if (!self::isInitialized($config)) {
+ if (!static::isInitialized($config)) {
return false;
}
- $key = self::$_engines[$config]->key($key);
+ $key = static::$_engines[$config]->key($key);
if (!$key || is_resource($value)) {
return false;
}
- $success = self::$_engines[$config]->write($settings['prefix'] . $key, $value, $settings['duration']);
- self::set(null, $config);
+ $success = static::$_engines[$config]->write($settings['prefix'] . $key, $value, $settings['duration']);
+ static::set(null, $config);
if ($success === false && $value !== '') {
trigger_error(
__d('cake_dev',
"%s cache was unable to write '%s' to %s cache",
$config,
$key,
- self::$_engines[$config]->settings['engine']
+ static::$_engines[$config]->settings['engine']
),
E_USER_WARNING
);
@@ -343,46 +348,46 @@ class Cache {
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
*/
public static function read($key, $config = 'default') {
- $settings = self::settings($config);
+ $settings = static::settings($config);
if (empty($settings)) {
return false;
}
- if (!self::isInitialized($config)) {
+ if (!static::isInitialized($config)) {
return false;
}
- $key = self::$_engines[$config]->key($key);
+ $key = static::$_engines[$config]->key($key);
if (!$key) {
return false;
}
- return self::$_engines[$config]->read($settings['prefix'] . $key);
+ return static::$_engines[$config]->read($settings['prefix'] . $key);
}
/**
* Increment a number under the key and return incremented value.
*
* @param string $key Identifier for the data
- * @param integer $offset How much to add
+ * @param int $offset How much to add
* @param string $config Optional string configuration name. Defaults to 'default'
* @return mixed new value, or false if the data doesn't exist, is not integer,
* or if there was an error fetching it.
*/
public static function increment($key, $offset = 1, $config = 'default') {
- $settings = self::settings($config);
+ $settings = static::settings($config);
if (empty($settings)) {
return false;
}
- if (!self::isInitialized($config)) {
+ if (!static::isInitialized($config)) {
return false;
}
- $key = self::$_engines[$config]->key($key);
+ $key = static::$_engines[$config]->key($key);
if (!$key || !is_int($offset) || $offset < 0) {
return false;
}
- $success = self::$_engines[$config]->increment($settings['prefix'] . $key, $offset);
- self::set(null, $config);
+ $success = static::$_engines[$config]->increment($settings['prefix'] . $key, $offset);
+ static::set(null, $config);
return $success;
}
@@ -390,27 +395,27 @@ class Cache {
* Decrement a number under the key and return decremented value.
*
* @param string $key Identifier for the data
- * @param integer $offset How much to subtract
+ * @param int $offset How much to subtract
* @param string $config Optional string configuration name. Defaults to 'default'
* @return mixed new value, or false if the data doesn't exist, is not integer,
* or if there was an error fetching it
*/
public static function decrement($key, $offset = 1, $config = 'default') {
- $settings = self::settings($config);
+ $settings = static::settings($config);
if (empty($settings)) {
return false;
}
- if (!self::isInitialized($config)) {
+ if (!static::isInitialized($config)) {
return false;
}
- $key = self::$_engines[$config]->key($key);
+ $key = static::$_engines[$config]->key($key);
if (!$key || !is_int($offset) || $offset < 0) {
return false;
}
- $success = self::$_engines[$config]->decrement($settings['prefix'] . $key, $offset);
- self::set(null, $config);
+ $success = static::$_engines[$config]->decrement($settings['prefix'] . $key, $offset);
+ static::set(null, $config);
return $success;
}
@@ -429,40 +434,40 @@ class Cache {
*
* @param string $key Identifier for the data
* @param string $config name of the configuration to use. Defaults to 'default'
- * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
+ * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public static function delete($key, $config = 'default') {
- $settings = self::settings($config);
+ $settings = static::settings($config);
if (empty($settings)) {
return false;
}
- if (!self::isInitialized($config)) {
+ if (!static::isInitialized($config)) {
return false;
}
- $key = self::$_engines[$config]->key($key);
+ $key = static::$_engines[$config]->key($key);
if (!$key) {
return false;
}
- $success = self::$_engines[$config]->delete($settings['prefix'] . $key);
- self::set(null, $config);
+ $success = static::$_engines[$config]->delete($settings['prefix'] . $key);
+ static::set(null, $config);
return $success;
}
/**
* Delete all keys from the cache.
*
- * @param boolean $check if true will check expiration, otherwise delete all
+ * @param bool $check if true will check expiration, otherwise delete all
* @param string $config name of the configuration to use. Defaults to 'default'
- * @return boolean True if the cache was successfully cleared, false otherwise
+ * @return bool True if the cache was successfully cleared, false otherwise
*/
public static function clear($check = false, $config = 'default') {
- if (!self::isInitialized($config)) {
+ if (!static::isInitialized($config)) {
return false;
}
- $success = self::$_engines[$config]->clear($check);
- self::set(null, $config);
+ $success = static::$_engines[$config]->clear($check);
+ static::set(null, $config);
return $success;
}
@@ -471,14 +476,14 @@ class Cache {
*
* @param string $group name of the group to be cleared
* @param string $config name of the configuration to use. Defaults to 'default'
- * @return boolean True if the cache group was successfully cleared, false otherwise
+ * @return bool True if the cache group was successfully cleared, false otherwise
*/
public static function clearGroup($group, $config = 'default') {
- if (!self::isInitialized($config)) {
+ if (!static::isInitialized($config)) {
return false;
}
- $success = self::$_engines[$config]->clearGroup($group);
- self::set(null, $config);
+ $success = static::$_engines[$config]->clearGroup($group);
+ static::set(null, $config);
return $success;
}
@@ -486,13 +491,13 @@ class Cache {
* Check if Cache has initialized a working config for the given name.
*
* @param string $config name of the configuration to use. Defaults to 'default'
- * @return boolean Whether or not the config name has been initialized.
+ * @return bool Whether or not the config name has been initialized.
*/
public static function isInitialized($config = 'default') {
if (Configure::read('Cache.disable')) {
return false;
}
- return isset(self::$_engines[$config]);
+ return isset(static::$_engines[$config]);
}
/**
@@ -503,8 +508,8 @@ class Cache {
* @see Cache::config()
*/
public static function settings($name = 'default') {
- if (!empty(self::$_engines[$name])) {
- return self::$_engines[$name]->settings();
+ if (!empty(static::$_engines[$name])) {
+ return static::$_engines[$name]->settings();
}
return array();
}
@@ -512,7 +517,7 @@ class Cache {
/**
* Retrieve group names to config mapping.
*
- * {{{
+ * ```
* Cache::config('daily', array(
* 'duration' => '1 day', 'groups' => array('posts')
* ));
@@ -520,7 +525,7 @@ class Cache {
* 'duration' => '1 week', 'groups' => array('posts', 'archive')
* ));
* $configs = Cache::groupConfigs('posts');
- * }}}
+ * ```
*
* $config will equal to `array('posts' => array('daily', 'weekly'))`
*
@@ -530,10 +535,10 @@ class Cache {
*/
public static function groupConfigs($group = null) {
if ($group === null) {
- return self::$_groups;
+ return static::$_groups;
}
- if (isset(self::$_groups[$group])) {
- return array($group => self::$_groups[$group]);
+ if (isset(static::$_groups[$group])) {
+ return array($group => static::$_groups[$group]);
}
throw new CacheException(__d('cake_dev', 'Invalid cache group %s', $group));
}
@@ -549,27 +554,66 @@ class Cache {
*
* Using a Closure to provide data, assume $this is a Model:
*
- * {{{
+ * ```
* $model = $this;
* $results = Cache::remember('all_articles', function() use ($model) {
* return $model->find('all');
* });
- * }}}
+ * ```
*
* @param string $key The cache key to read/store data at.
* @param callable $callable The callable that provides data in the case when
* the cache key is empty. Can be any callable type supported by your PHP.
* @param string $config The cache configuration to use for this operation.
* Defaults to default.
+ * @return mixed The results of the callable or unserialized results.
*/
public static function remember($key, $callable, $config = 'default') {
- $existing = self::read($key, $config);
+ $existing = static::read($key, $config);
if ($existing !== false) {
return $existing;
}
$results = call_user_func($callable);
- self::write($key, $results, $config);
+ static::write($key, $results, $config);
return $results;
}
+/**
+ * Write data for key into a cache engine if it doesn't exist already.
+ *
+ * ### Usage:
+ *
+ * Writing to the active cache config:
+ *
+ * `Cache::add('cached_data', $data);`
+ *
+ * Writing to a specific cache config:
+ *
+ * `Cache::add('cached_data', $data, 'long_term');`
+ *
+ * @param string $key Identifier for the data.
+ * @param mixed $value Data to be cached - anything except a resource.
+ * @param string $config Optional string configuration name to write to. Defaults to 'default'.
+ * @return bool True if the data was successfully cached, false on failure.
+ * Or if the key existed already.
+ */
+ public static function add($key, $value, $config = 'default') {
+ $settings = self::settings($config);
+
+ if (empty($settings)) {
+ return false;
+ }
+ if (!self::isInitialized($config)) {
+ return false;
+ }
+ $key = self::$_engines[$config]->key($key);
+
+ if (!$key || is_resource($value)) {
+ return false;
+ }
+
+ $success = self::$_engines[$config]->add($settings['prefix'] . $key, $value, $settings['duration']);
+ self::set(null, $config);
+ return $success;
+ }
}
diff --git a/web/api/lib/Cake/Cache/CacheEngine.php b/web/api/lib/Cake/Cache/CacheEngine.php
index 5d19bdeaf..6bad9f7ad 100644
--- a/web/api/lib/Cake/Cache/CacheEngine.php
+++ b/web/api/lib/Cake/Cache/CacheEngine.php
@@ -42,7 +42,7 @@ abstract class CacheEngine {
* Called automatically by the cache frontend
*
* @param array $settings Associative array of parameters for the engine
- * @return boolean True if the engine has been successfully initialized, false if not
+ * @return bool True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
$settings += $this->settings + array(
@@ -67,7 +67,7 @@ abstract class CacheEngine {
*
* Permanently remove all expired and deleted data
*
- * @param integer $expires [optional] An expires timestamp, invalidating all data before.
+ * @param int $expires [optional] An expires timestamp, invalidating all data before.
* @return void
*/
public function gc($expires = null) {
@@ -78,11 +78,22 @@ abstract class CacheEngine {
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
- * @param integer $duration How long to cache for.
- * @return boolean True if the data was successfully cached, false on failure
+ * @param int $duration How long to cache for.
+ * @return bool True if the data was successfully cached, false on failure
*/
abstract public function write($key, $value, $duration);
+/**
+ * Write value for a key into cache if it doesn't already exist
+ *
+ * @param string $key Identifier for the data
+ * @param mixed $value Data to be cached
+ * @param int $duration How long to cache for.
+ * @return bool True if the data was successfully cached, false on failure
+ */
+ public function add($key, $value, $duration) {
+ }
+
/**
* Read a key from the cache
*
@@ -95,7 +106,7 @@ abstract class CacheEngine {
* Increment a number under the key and return incremented value
*
* @param string $key Identifier for the data
- * @param integer $offset How much to add
+ * @param int $offset How much to add
* @return New incremented value, false otherwise
*/
abstract public function increment($key, $offset = 1);
@@ -104,7 +115,7 @@ abstract class CacheEngine {
* Decrement a number under the key and return decremented value
*
* @param string $key Identifier for the data
- * @param integer $offset How much to subtract
+ * @param int $offset How much to subtract
* @return New incremented value, false otherwise
*/
abstract public function decrement($key, $offset = 1);
@@ -113,15 +124,15 @@ abstract class CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
- * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
+ * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
abstract public function delete($key);
/**
* Delete all keys from the cache
*
- * @param boolean $check if true will check expiration, otherwise delete all
- * @return boolean True if the cache was successfully cleared, false otherwise
+ * @param bool $check if true will check expiration, otherwise delete all
+ * @return bool True if the cache was successfully cleared, false otherwise
*/
abstract public function clear($check);
@@ -130,8 +141,8 @@ abstract class CacheEngine {
* to decide whether actually delete the keys or just simulate it to achieve
* the same result.
*
- * @param string $groups name of the group to be cleared
- * @return boolean
+ * @param string $group name of the group to be cleared
+ * @return bool
*/
public function clearGroup($group) {
return false;
@@ -176,5 +187,4 @@ abstract class CacheEngine {
$key = preg_replace('/[\s]+/', '_', strtolower(trim(str_replace(array(DS, '/', '.'), '_', strval($key)))));
return $prefix . $key;
}
-
}
diff --git a/web/api/lib/Cake/Cache/Engine/ApcEngine.php b/web/api/lib/Cake/Cache/Engine/ApcEngine.php
index 8fd0ff1ad..da31651e3 100644
--- a/web/api/lib/Cake/Cache/Engine/ApcEngine.php
+++ b/web/api/lib/Cake/Cache/Engine/ApcEngine.php
@@ -38,7 +38,7 @@ class ApcEngine extends CacheEngine {
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
- * @return boolean True if the engine has been successfully initialized, false if not
+ * @return bool True if the engine has been successfully initialized, false if not
* @see CacheEngine::__defaults
*/
public function init($settings = array()) {
@@ -55,8 +55,8 @@ class ApcEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
- * @param integer $duration How long to cache the data, in seconds
- * @return boolean True if the data was successfully cached, false on failure
+ * @param int $duration How long to cache the data, in seconds
+ * @return bool True if the data was successfully cached, false on failure
*/
public function write($key, $value, $duration) {
$expires = 0;
@@ -75,7 +75,7 @@ class ApcEngine extends CacheEngine {
*/
public function read($key) {
$time = time();
- $cachetime = intval(apc_fetch($key . '_expires'));
+ $cachetime = (int)apc_fetch($key . '_expires');
if ($cachetime !== 0 && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
return false;
}
@@ -86,7 +86,7 @@ class ApcEngine extends CacheEngine {
* Increments the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to increment
+ * @param int $offset How much to increment
* @return New incremented value, false otherwise
*/
public function increment($key, $offset = 1) {
@@ -97,7 +97,7 @@ class ApcEngine extends CacheEngine {
* Decrements the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to subtract
+ * @param int $offset How much to subtract
* @return New decremented value, false otherwise
*/
public function decrement($key, $offset = 1) {
@@ -108,7 +108,7 @@ class ApcEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
- * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
+ * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return apc_delete($key);
@@ -117,18 +117,25 @@ class ApcEngine extends CacheEngine {
/**
* Delete all keys from the cache. This will clear every cache config using APC.
*
- * @param boolean $check If true, nothing will be cleared, as entries are removed
+ * @param bool $check If true, nothing will be cleared, as entries are removed
* from APC as they expired. This flag is really only used by FileEngine.
- * @return boolean True Returns true.
+ * @return bool True Returns true.
*/
public function clear($check) {
if ($check) {
return true;
}
- $info = apc_cache_info('user');
- $cacheKeys = $info['cache_list'];
- unset($info);
- foreach ($cacheKeys as $key) {
+ if (class_exists('APCIterator', false)) {
+ $iterator = new APCIterator(
+ 'user',
+ '/^' . preg_quote($this->settings['prefix'], '/') . '/',
+ APC_ITER_NONE
+ );
+ apc_delete($iterator);
+ return true;
+ }
+ $cache = apc_cache_info('user');
+ foreach ($cache['cache_list'] as $key) {
if (strpos($key['info'], $this->settings['prefix']) === 0) {
apc_delete($key['info']);
}
@@ -173,11 +180,30 @@ class ApcEngine extends CacheEngine {
* Increments the group value to simulate deletion of all keys under a group
* old values will remain in storage until they expire.
*
- * @return boolean success
+ * @param string $group The group to clear.
+ * @return bool success
*/
public function clearGroup($group) {
apc_inc($this->settings['prefix'] . $group, 1, $success);
return $success;
}
+/**
+ * Write data for key into cache if it doesn't exist already.
+ * If it already exists, it fails and returns false.
+ *
+ * @param string $key Identifier for the data.
+ * @param mixed $value Data to be cached.
+ * @param int $duration How long to cache the data, in seconds.
+ * @return bool True if the data was successfully cached, false on failure.
+ * @link http://php.net/manual/en/function.apc-add.php
+ */
+ public function add($key, $value, $duration) {
+ $expires = 0;
+ if ($duration) {
+ $expires = time() + $duration;
+ }
+ apc_add($key . '_expires', $expires, $duration);
+ return apc_add($key, $value, $duration);
+ }
}
diff --git a/web/api/lib/Cake/Cache/Engine/FileEngine.php b/web/api/lib/Cake/Cache/Engine/FileEngine.php
index b93d6c1a8..d650e60ee 100644
--- a/web/api/lib/Cake/Cache/Engine/FileEngine.php
+++ b/web/api/lib/Cake/Cache/Engine/FileEngine.php
@@ -53,7 +53,7 @@ class FileEngine extends CacheEngine {
/**
* True unless FileEngine::__active(); fails
*
- * @var boolean
+ * @var bool
*/
protected $_init = true;
@@ -64,7 +64,7 @@ class FileEngine extends CacheEngine {
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
- * @return boolean True if the engine has been successfully initialized, false if not
+ * @return bool True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
$settings += array(
@@ -93,8 +93,8 @@ class FileEngine extends CacheEngine {
/**
* Garbage collection. Permanently remove all expired and deleted data
*
- * @param integer $expires [optional] An expires timestamp, invalidating all data before.
- * @return boolean True if garbage collection was successful, false on failure
+ * @param int $expires [optional] An expires timestamp, invalidating all data before.
+ * @return bool True if garbage collection was successful, false on failure
*/
public function gc($expires = null) {
return $this->clear(true);
@@ -105,11 +105,11 @@ class FileEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @param mixed $data Data to be cached
- * @param integer $duration How long to cache the data, in seconds
- * @return boolean True if the data was successfully cached, false on failure
+ * @param int $duration How long to cache the data, in seconds
+ * @return bool True if the data was successfully cached, false on failure
*/
public function write($key, $data, $duration) {
- if ($data === '' || !$this->_init) {
+ if (!$this->_init) {
return false;
}
@@ -165,7 +165,7 @@ class FileEngine extends CacheEngine {
$this->_File->rewind();
$time = time();
- $cachetime = intval($this->_File->current());
+ $cachetime = (int)$this->_File->current();
if ($cachetime !== false && ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime)) {
if ($this->settings['lock']) {
@@ -200,7 +200,7 @@ class FileEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
- * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
+ * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
if ($this->_setKey($key) === false || !$this->_init) {
@@ -217,8 +217,8 @@ class FileEngine extends CacheEngine {
/**
* Delete all values from the cache
*
- * @param boolean $check Optional - only delete expired cache items
- * @return boolean True if the cache was successfully cleared, false otherwise
+ * @param bool $check Optional - only delete expired cache items
+ * @return bool True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
if (!$this->_init) {
@@ -255,8 +255,8 @@ class FileEngine extends CacheEngine {
* Used to clear a directory of matching files.
*
* @param string $path The path to search.
- * @param integer $now The current timestamp
- * @param integer $threshold Any file not modified after this value will be deleted.
+ * @param int $now The current timestamp
+ * @param int $threshold Any file not modified after this value will be deleted.
* @return void
*/
protected function _clearDirectory($path, $now, $threshold) {
@@ -271,11 +271,12 @@ class FileEngine extends CacheEngine {
if (substr($entry, 0, $prefixLength) !== $this->settings['prefix']) {
continue;
}
- $filePath = $path . $entry;
- if (!file_exists($filePath) || is_dir($filePath)) {
+
+ try {
+ $file = new SplFileObject($path . $entry, 'r');
+ } catch (Exception $e) {
continue;
}
- $file = new SplFileObject($path . $entry, 'r');
if ($threshold) {
$mtime = $file->getMTime();
@@ -303,8 +304,8 @@ class FileEngine extends CacheEngine {
/**
* Not implemented
*
- * @param string $key
- * @param integer $offset
+ * @param string $key The key to decrement
+ * @param int $offset The number to offset
* @return void
* @throws CacheException
*/
@@ -315,8 +316,8 @@ class FileEngine extends CacheEngine {
/**
* Not implemented
*
- * @param string $key
- * @param integer $offset
+ * @param string $key The key to decrement
+ * @param int $offset The number to offset
* @return void
* @throws CacheException
*/
@@ -329,8 +330,8 @@ class FileEngine extends CacheEngine {
* for the cache file the key is referring to.
*
* @param string $key The key
- * @param boolean $createKey Whether the key should be created if it doesn't exists, or not
- * @return boolean true if the cache key could be set, false otherwise
+ * @param bool $createKey Whether the key should be created if it doesn't exists, or not
+ * @return bool true if the cache key could be set, false otherwise
*/
protected function _setKey($key, $createKey = false) {
$groups = null;
@@ -369,7 +370,7 @@ class FileEngine extends CacheEngine {
/**
* Determine is cache directory is writable
*
- * @return boolean
+ * @return bool
*/
protected function _active() {
$dir = new SplFileInfo($this->settings['path']);
@@ -405,7 +406,8 @@ class FileEngine extends CacheEngine {
/**
* Recursively deletes all files under any directory named as $group
*
- * @return boolean success
+ * @param string $group The group to clear.
+ * @return bool success
*/
public function clearGroup($group) {
$this->_File = null;
@@ -427,4 +429,21 @@ class FileEngine extends CacheEngine {
}
return true;
}
+
+/**
+ * Write data for key into cache if it doesn't exist already.
+ * If it already exists, it fails and returns false.
+ *
+ * @param string $key Identifier for the data.
+ * @param mixed $value Data to be cached.
+ * @param int $duration How long to cache the data, in seconds.
+ * @return bool True if the data was successfully cached, false on failure.
+ */
+ public function add($key, $value, $duration) {
+ $cachedValue = $this->read($key);
+ if ($cachedValue === false) {
+ return $this->write($key, $value, $duration);
+ }
+ return false;
+ }
}
diff --git a/web/api/lib/Cake/Cache/Engine/MemcacheEngine.php b/web/api/lib/Cake/Cache/Engine/MemcacheEngine.php
index facaedf0e..eba2ec451 100644
--- a/web/api/lib/Cake/Cache/Engine/MemcacheEngine.php
+++ b/web/api/lib/Cake/Cache/Engine/MemcacheEngine.php
@@ -22,7 +22,7 @@
* more information.
*
* @package Cake.Cache.Engine
- * @deprecated You should use the Memcached adapter instead.
+ * @deprecated 3.0.0 You should use the Memcached adapter instead.
*/
class MemcacheEngine extends CacheEngine {
@@ -59,7 +59,7 @@ class MemcacheEngine extends CacheEngine {
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
- * @return boolean True if the engine has been successfully initialized, false if not
+ * @return bool True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
if (!class_exists('Memcache')) {
@@ -104,7 +104,7 @@ class MemcacheEngine extends CacheEngine {
* @return array Array containing host, port
*/
protected function _parseServerString($server) {
- if ($server[0] === 'u') {
+ if (strpos($server, 'unix://') === 0) {
return array($server, 0);
}
if (substr($server, 0, 1) === '[') {
@@ -131,8 +131,8 @@ class MemcacheEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
- * @param integer $duration How long to cache the data, in seconds
- * @return boolean True if the data was successfully cached, false on failure
+ * @param int $duration How long to cache the data, in seconds
+ * @return bool True if the data was successfully cached, false on failure
* @see http://php.net/manual/en/memcache.set.php
*/
public function write($key, $value, $duration) {
@@ -156,7 +156,7 @@ class MemcacheEngine extends CacheEngine {
* Increments the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to increment
+ * @param int $offset How much to increment
* @return New incremented value, false otherwise
* @throws CacheException when you try to increment with compress = true
*/
@@ -173,7 +173,7 @@ class MemcacheEngine extends CacheEngine {
* Decrements the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to subtract
+ * @param int $offset How much to subtract
* @return New decremented value, false otherwise
* @throws CacheException when you try to decrement with compress = true
*/
@@ -190,7 +190,7 @@ class MemcacheEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
- * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
+ * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return $this->_Memcache->delete($key);
@@ -199,8 +199,9 @@ class MemcacheEngine extends CacheEngine {
/**
* Delete all keys from the cache
*
- * @param boolean $check
- * @return boolean True if the cache was successfully cleared, false otherwise
+ * @param bool $check If true no deletes will occur and instead CakePHP will rely
+ * on key TTL values.
+ * @return bool True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
if ($check) {
@@ -231,8 +232,8 @@ class MemcacheEngine extends CacheEngine {
* Connects to a server in connection pool
*
* @param string $host host ip address or name
- * @param integer $port Server port
- * @return boolean True if memcache server was connected
+ * @param int $port Server port
+ * @return bool True if memcache server was connected
*/
public function connect($host, $port = 11211) {
if ($this->_Memcache->getServerStatus($host, $port) === 0) {
@@ -282,9 +283,30 @@ class MemcacheEngine extends CacheEngine {
* Increments the group value to simulate deletion of all keys under a group
* old values will remain in storage until they expire.
*
- * @return boolean success
+ * @param string $group The group to clear.
+ * @return bool success
*/
public function clearGroup($group) {
return (bool)$this->_Memcache->increment($this->settings['prefix'] . $group);
}
+
+/**
+ * Write data for key into cache if it doesn't exist already. When using memcached as your cache engine
+ * remember that the Memcached PECL extension does not support cache expiry times greater
+ * than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
+ * If it already exists, it fails and returns false.
+ *
+ * @param string $key Identifier for the data.
+ * @param mixed $value Data to be cached.
+ * @param int $duration How long to cache the data, in seconds.
+ * @return bool True if the data was successfully cached, false on failure.
+ * @link http://php.net/manual/en/memcache.add.php
+ */
+ public function add($key, $value, $duration) {
+ if ($duration > 30 * DAY) {
+ $duration = 0;
+ }
+
+ return $this->_Memcache->add($key, $value, $this->settings['compress'], $duration);
+ }
}
diff --git a/web/api/lib/Cake/Cache/Engine/MemcachedEngine.php b/web/api/lib/Cake/Cache/Engine/MemcachedEngine.php
old mode 100755
new mode 100644
index 9c50186fe..cc101a2bf
--- a/web/api/lib/Cake/Cache/Engine/MemcachedEngine.php
+++ b/web/api/lib/Cake/Cache/Engine/MemcachedEngine.php
@@ -45,6 +45,8 @@ class MemcachedEngine extends CacheEngine {
* - serialize = string, default => php. The serializer engine used to serialize data.
* Available engines are php, igbinary and json. Beside php, the memcached extension
* must be compiled with the appropriate serializer support.
+ * - options - Additional options for the memcached client. Should be an array of option => value.
+ * Use the Memcached::OPT_* constants as keys.
*
* @var array
*/
@@ -70,7 +72,7 @@ class MemcachedEngine extends CacheEngine {
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
- * @return boolean True if the engine has been successfully initialized, false if not
+ * @return bool True if the engine has been successfully initialized, false if not
* @throws CacheException when you try use authentication without Memcached compiled with SASL support
*/
public function init($settings = array()) {
@@ -92,7 +94,8 @@ class MemcachedEngine extends CacheEngine {
'persistent' => false,
'login' => null,
'password' => null,
- 'serialize' => 'php'
+ 'serialize' => 'php',
+ 'options' => array()
);
parent::init($settings);
@@ -104,7 +107,11 @@ class MemcachedEngine extends CacheEngine {
return true;
}
- $this->_Memcached = new Memcached($this->settings['persistent'] ? (string)$this->settings['persistent'] : null);
+ if (!$this->settings['persistent']) {
+ $this->_Memcached = new Memcached();
+ } else {
+ $this->_Memcached = new Memcached((string)$this->settings['persistent']);
+ }
$this->_setOptions();
if (count($this->_Memcached->getServerList())) {
@@ -126,8 +133,14 @@ class MemcachedEngine extends CacheEngine {
__d('cake_dev', 'Memcached extension is not build with SASL support')
);
}
+ $this->_Memcached->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$this->_Memcached->setSaslAuthData($this->settings['login'], $this->settings['password']);
}
+ if (is_array($this->settings['options'])) {
+ foreach ($this->settings['options'] as $opt => $value) {
+ $this->_Memcached->setOption($opt, $value);
+ }
+ }
return true;
}
@@ -136,6 +149,7 @@ class MemcachedEngine extends CacheEngine {
* Settings the memcached instance
*
* @throws CacheException when the Memcached extension is not built with the desired serializer engine
+ * @return void
*/
protected function _setOptions() {
$this->_Memcached->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
@@ -171,8 +185,9 @@ class MemcachedEngine extends CacheEngine {
* @return array Array containing host, port
*/
protected function _parseServerString($server) {
- if ($server[0] === 'u') {
- return array($server, 0);
+ $socketTransport = 'unix://';
+ if (strpos($server, $socketTransport) === 0) {
+ return array(substr($server, strlen($socketTransport)), 0);
}
if (substr($server, 0, 1) === '[') {
$position = strpos($server, ']:');
@@ -193,13 +208,13 @@ class MemcachedEngine extends CacheEngine {
/**
* Write data for key into cache. When using memcached as your cache engine
- * remember that the Memcached pecl extension does not support cache expiry times greater
+ * remember that the Memcached PECL extension does not support cache expiry times greater
* than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
- * @param integer $duration How long to cache the data, in seconds
- * @return boolean True if the data was successfully cached, false on failure
+ * @param int $duration How long to cache the data, in seconds
+ * @return bool True if the data was successfully cached, false on failure
* @see http://php.net/manual/en/memcache.set.php
*/
public function write($key, $value, $duration) {
@@ -224,7 +239,7 @@ class MemcachedEngine extends CacheEngine {
* Increments the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to increment
+ * @param int $offset How much to increment
* @return New incremented value, false otherwise
* @throws CacheException when you try to increment with compress = true
*/
@@ -236,7 +251,7 @@ class MemcachedEngine extends CacheEngine {
* Decrements the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to subtract
+ * @param int $offset How much to subtract
* @return New decremented value, false otherwise
* @throws CacheException when you try to decrement with compress = true
*/
@@ -248,7 +263,7 @@ class MemcachedEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
- * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
+ * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return $this->_Memcached->delete($key);
@@ -257,8 +272,10 @@ class MemcachedEngine extends CacheEngine {
/**
* Delete all keys from the cache
*
- * @param boolean $check
- * @return boolean True if the cache was successfully cleared, false otherwise
+ * @param bool $check If true no deletes will occur and instead CakePHP will rely
+ * on key TTL values.
+ * @return bool True if the cache was successfully cleared, false otherwise. Will
+ * also return false if you are using a binary protocol.
*/
public function clear($check) {
if ($check) {
@@ -266,6 +283,9 @@ class MemcachedEngine extends CacheEngine {
}
$keys = $this->_Memcached->getAllKeys();
+ if ($keys === false) {
+ return false;
+ }
foreach ($keys as $key) {
if (strpos($key, $this->settings['prefix']) === 0) {
@@ -314,9 +334,30 @@ class MemcachedEngine extends CacheEngine {
* Increments the group value to simulate deletion of all keys under a group
* old values will remain in storage until they expire.
*
- * @return boolean success
+ * @param string $group The group to clear.
+ * @return bool success
*/
public function clearGroup($group) {
return (bool)$this->_Memcached->increment($this->settings['prefix'] . $group);
}
+
+/**
+ * Write data for key into cache if it doesn't exist already. When using memcached as your cache engine
+ * remember that the Memcached pecl extension does not support cache expiry times greater
+ * than 30 days in the future. Any duration greater than 30 days will be treated as never expiring.
+ * If it already exists, it fails and returns false.
+ *
+ * @param string $key Identifier for the data.
+ * @param mixed $value Data to be cached.
+ * @param int $duration How long to cache the data, in seconds.
+ * @return bool True if the data was successfully cached, false on failure.
+ * @link http://php.net/manual/en/memcached.add.php
+ */
+ public function add($key, $value, $duration) {
+ if ($duration > 30 * DAY) {
+ $duration = 0;
+ }
+
+ return $this->_Memcached->add($key, $value, $duration);
+ }
}
diff --git a/web/api/lib/Cake/Cache/Engine/RedisEngine.php b/web/api/lib/Cake/Cache/Engine/RedisEngine.php
index 09415c95d..8dd98fb99 100644
--- a/web/api/lib/Cake/Cache/Engine/RedisEngine.php
+++ b/web/api/lib/Cake/Cache/Engine/RedisEngine.php
@@ -38,6 +38,7 @@ class RedisEngine extends CacheEngine {
* - port = integer port number to the Redis server (default: 6379)
* - timeout = float timeout in seconds (default: 0)
* - persistent = boolean Connects to the Redis server with a persistent connection (default: true)
+ * - unix_socket = path to the unix socket file (default: false)
*
* @var array
*/
@@ -50,7 +51,7 @@ class RedisEngine extends CacheEngine {
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
- * @return boolean True if the engine has been successfully initialized, false if not
+ * @return bool True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
if (!class_exists('Redis')) {
@@ -58,13 +59,14 @@ class RedisEngine extends CacheEngine {
}
parent::init(array_merge(array(
'engine' => 'Redis',
- 'prefix' => null,
+ 'prefix' => Inflector::slug(APP_DIR) . '_',
'server' => '127.0.0.1',
'database' => 0,
'port' => 6379,
'password' => false,
'timeout' => 0,
- 'persistent' => true
+ 'persistent' => true,
+ 'unix_socket' => false
), $settings)
);
@@ -74,28 +76,29 @@ class RedisEngine extends CacheEngine {
/**
* Connects to a Redis server
*
- * @return boolean True if Redis server was connected
+ * @return bool True if Redis server was connected
*/
protected function _connect() {
- $return = false;
try {
$this->_Redis = new Redis();
- if (empty($this->settings['persistent'])) {
+ if (!empty($this->settings['unix_socket'])) {
+ $return = $this->_Redis->connect($this->settings['unix_socket']);
+ } elseif (empty($this->settings['persistent'])) {
$return = $this->_Redis->connect($this->settings['server'], $this->settings['port'], $this->settings['timeout']);
} else {
$persistentId = $this->settings['port'] . $this->settings['timeout'] . $this->settings['database'];
$return = $this->_Redis->pconnect($this->settings['server'], $this->settings['port'], $this->settings['timeout'], $persistentId);
}
} catch (RedisException $e) {
+ $return = false;
+ }
+ if (!$return) {
return false;
}
- if ($return && $this->settings['password']) {
- $return = $this->_Redis->auth($this->settings['password']);
+ if ($this->settings['password'] && !$this->_Redis->auth($this->settings['password'])) {
+ return false;
}
- if ($return) {
- $return = $this->_Redis->select($this->settings['database']);
- }
- return $return;
+ return $this->_Redis->select($this->settings['database']);
}
/**
@@ -103,13 +106,18 @@ class RedisEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
- * @param integer $duration How long to cache the data, in seconds
- * @return boolean True if the data was successfully cached, false on failure
+ * @param int $duration How long to cache the data, in seconds
+ * @return bool True if the data was successfully cached, false on failure
*/
public function write($key, $value, $duration) {
if (!is_int($value)) {
$value = serialize($value);
}
+
+ if (!$this->_Redis->isConnected()) {
+ $this->_connect();
+ }
+
if ($duration === 0) {
return $this->_Redis->set($key, $value);
}
@@ -138,7 +146,7 @@ class RedisEngine extends CacheEngine {
* Increments the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to increment
+ * @param int $offset How much to increment
* @return New incremented value, false otherwise
* @throws CacheException when you try to increment with compress = true
*/
@@ -150,7 +158,7 @@ class RedisEngine extends CacheEngine {
* Decrements the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to subtract
+ * @param int $offset How much to subtract
* @return New decremented value, false otherwise
* @throws CacheException when you try to decrement with compress = true
*/
@@ -162,7 +170,7 @@ class RedisEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
- * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
+ * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return $this->_Redis->delete($key) > 0;
@@ -171,8 +179,9 @@ class RedisEngine extends CacheEngine {
/**
* Delete all keys from the cache
*
- * @param boolean $check
- * @return boolean True if the cache was successfully cleared, false otherwise
+ * @param bool $check Whether or not expiration keys should be checked. If
+ * true, no keys will be removed as cache will rely on redis TTL's.
+ * @return bool True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
if ($check) {
@@ -208,7 +217,8 @@ class RedisEngine extends CacheEngine {
* Increments the group value to simulate deletion of all keys under a group
* old values will remain in storage until they expire.
*
- * @return boolean success
+ * @param string $group The group name to clear.
+ * @return bool success
*/
public function clearGroup($group) {
return (bool)$this->_Redis->incr($this->settings['prefix'] . $group);
@@ -222,4 +232,27 @@ class RedisEngine extends CacheEngine {
$this->_Redis->close();
}
}
+
+/**
+ * Write data for key into cache if it doesn't exist already.
+ * If it already exists, it fails and returns false.
+ *
+ * @param string $key Identifier for the data.
+ * @param mixed $value Data to be cached.
+ * @param int $duration How long to cache the data, in seconds.
+ * @return bool True if the data was successfully cached, false on failure.
+ * @link https://github.com/phpredis/phpredis#setnx
+ */
+ public function add($key, $value, $duration) {
+ if (!is_int($value)) {
+ $value = serialize($value);
+ }
+
+ $result = $this->_Redis->setnx($key, $value);
+ // setnx() doesn't have an expiry option, so overwrite the key with one
+ if ($result) {
+ return $this->_Redis->setex($key, $duration, $value);
+ }
+ return false;
+ }
}
diff --git a/web/api/lib/Cake/Cache/Engine/WincacheEngine.php b/web/api/lib/Cake/Cache/Engine/WincacheEngine.php
index bfba803d2..e5c9d7bd7 100644
--- a/web/api/lib/Cake/Cache/Engine/WincacheEngine.php
+++ b/web/api/lib/Cake/Cache/Engine/WincacheEngine.php
@@ -40,7 +40,7 @@ class WincacheEngine extends CacheEngine {
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
- * @return boolean True if the engine has been successfully initialized, false if not
+ * @return bool True if the engine has been successfully initialized, false if not
* @see CacheEngine::__defaults
*/
public function init($settings = array()) {
@@ -57,8 +57,8 @@ class WincacheEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
- * @param integer $duration How long to cache the data, in seconds
- * @return boolean True if the data was successfully cached, false on failure
+ * @param int $duration How long to cache the data, in seconds
+ * @return bool True if the data was successfully cached, false on failure
*/
public function write($key, $value, $duration) {
$expires = time() + $duration;
@@ -80,7 +80,7 @@ class WincacheEngine extends CacheEngine {
*/
public function read($key) {
$time = time();
- $cachetime = intval(wincache_ucache_get($key . '_expires'));
+ $cachetime = (int)wincache_ucache_get($key . '_expires');
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false;
}
@@ -91,7 +91,7 @@ class WincacheEngine extends CacheEngine {
* Increments the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to increment
+ * @param int $offset How much to increment
* @return New incremented value, false otherwise
*/
public function increment($key, $offset = 1) {
@@ -102,7 +102,7 @@ class WincacheEngine extends CacheEngine {
* Decrements the value of an integer cached key
*
* @param string $key Identifier for the data
- * @param integer $offset How much to subtract
+ * @param int $offset How much to subtract
* @return New decremented value, false otherwise
*/
public function decrement($key, $offset = 1) {
@@ -113,7 +113,7 @@ class WincacheEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
- * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
+ * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return wincache_ucache_delete($key);
@@ -123,9 +123,9 @@ class WincacheEngine extends CacheEngine {
* Delete all keys from the cache. This will clear every
* item in the cache matching the cache config prefix.
*
- * @param boolean $check If true, nothing will be cleared, as entries will
+ * @param bool $check If true, nothing will be cleared, as entries will
* naturally expire in wincache..
- * @return boolean True Returns true.
+ * @return bool True Returns true.
*/
public function clear($check) {
if ($check) {
@@ -179,7 +179,8 @@ class WincacheEngine extends CacheEngine {
* Increments the group value to simulate deletion of all keys under a group
* old values will remain in storage until they expire.
*
- * @return boolean success
+ * @param string $group The group to clear.
+ * @return bool success
*/
public function clearGroup($group) {
$success = null;
@@ -187,4 +188,20 @@ class WincacheEngine extends CacheEngine {
return $success;
}
+/**
+ * Write data for key into cache if it doesn't exist already.
+ * If it already exists, it fails and returns false.
+ *
+ * @param string $key Identifier for the data.
+ * @param mixed $value Data to be cached.
+ * @param int $duration How long to cache the data, in seconds.
+ * @return bool True if the data was successfully cached, false on failure.
+ */
+ public function add($key, $value, $duration) {
+ $cachedValue = $this->read($key);
+ if ($cachedValue === false) {
+ return $this->write($key, $value, $duration);
+ }
+ return false;
+ }
}
diff --git a/web/api/lib/Cake/Cache/Engine/XcacheEngine.php b/web/api/lib/Cake/Cache/Engine/XcacheEngine.php
index 12e19c786..c46a7b9c5 100644
--- a/web/api/lib/Cake/Cache/Engine/XcacheEngine.php
+++ b/web/api/lib/Cake/Cache/Engine/XcacheEngine.php
@@ -41,10 +41,10 @@ class XcacheEngine extends CacheEngine {
* To reinitialize the settings call Cache::engine('EngineName', [optional] settings = array());
*
* @param array $settings array of setting for the engine
- * @return boolean True if the engine has been successfully initialized, false if not
+ * @return bool True if the engine has been successfully initialized, false if not
*/
public function init($settings = array()) {
- if (php_sapi_name() !== 'cli') {
+ if (PHP_SAPI !== 'cli') {
parent::init(array_merge(array(
'engine' => 'Xcache',
'prefix' => Inflector::slug(APP_DIR) . '_',
@@ -62,8 +62,8 @@ class XcacheEngine extends CacheEngine {
*
* @param string $key Identifier for the data
* @param mixed $value Data to be cached
- * @param integer $duration How long to cache the data, in seconds
- * @return boolean True if the data was successfully cached, false on failure
+ * @param int $duration How long to cache the data, in seconds
+ * @return bool True if the data was successfully cached, false on failure
*/
public function write($key, $value, $duration) {
$expires = time() + $duration;
@@ -80,7 +80,7 @@ class XcacheEngine extends CacheEngine {
public function read($key) {
if (xcache_isset($key)) {
$time = time();
- $cachetime = intval(xcache_get($key . '_expires'));
+ $cachetime = (int)xcache_get($key . '_expires');
if ($cachetime < $time || ($time + $this->settings['duration']) < $cachetime) {
return false;
}
@@ -94,7 +94,7 @@ class XcacheEngine extends CacheEngine {
* If the cache key is not an integer it will be treated as 0
*
* @param string $key Identifier for the data
- * @param integer $offset How much to increment
+ * @param int $offset How much to increment
* @return New incremented value, false otherwise
*/
public function increment($key, $offset = 1) {
@@ -106,7 +106,7 @@ class XcacheEngine extends CacheEngine {
* If the cache key is not an integer it will be treated as 0
*
* @param string $key Identifier for the data
- * @param integer $offset How much to subtract
+ * @param int $offset How much to subtract
* @return New decremented value, false otherwise
*/
public function decrement($key, $offset = 1) {
@@ -117,7 +117,7 @@ class XcacheEngine extends CacheEngine {
* Delete a key from the cache
*
* @param string $key Identifier for the data
- * @return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
+ * @return bool True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
return xcache_unset($key);
@@ -126,8 +126,9 @@ class XcacheEngine extends CacheEngine {
/**
* Delete all keys from the cache
*
- * @param boolean $check
- * @return boolean True if the cache was successfully cleared, false otherwise
+ * @param bool $check If true no deletes will occur and instead CakePHP will rely
+ * on key TTL values.
+ * @return bool True if the cache was successfully cleared, false otherwise
*/
public function clear($check) {
$this->_auth();
@@ -163,7 +164,8 @@ class XcacheEngine extends CacheEngine {
* Increments the group value to simulate deletion of all keys under a group
* old values will remain in storage until they expire.
*
- * @return boolean success
+ * @param string $group The group to clear.
+ * @return bool success
*/
public function clearGroup($group) {
return (bool)xcache_inc($this->settings['prefix'] . $group, 1);
@@ -176,7 +178,7 @@ class XcacheEngine extends CacheEngine {
* This has to be done because xcache_clear_cache() needs to pass Basic Http Auth
* (see xcache.admin configuration settings)
*
- * @param boolean $reverse Revert changes
+ * @param bool $reverse Revert changes
* @return void
*/
protected function _auth($reverse = false) {
@@ -205,4 +207,21 @@ class XcacheEngine extends CacheEngine {
}
}
}
+
+/**
+ * Write data for key into cache if it doesn't exist already.
+ * If it already exists, it fails and returns false.
+ *
+ * @param string $key Identifier for the data.
+ * @param mixed $value Data to be cached.
+ * @param int $duration How long to cache the data, in seconds.
+ * @return bool True if the data was successfully cached, false on failure.
+ */
+ public function add($key, $value, $duration) {
+ $cachedValue = $this->read($key);
+ if ($cachedValue === false) {
+ return $this->write($key, $value, $duration);
+ }
+ return false;
+ }
}
diff --git a/web/api/lib/Cake/Config/routes.php b/web/api/lib/Cake/Config/routes.php
index e27ba3a40..7bcc0c06b 100644
--- a/web/api/lib/Cake/Config/routes.php
+++ b/web/api/lib/Cake/Config/routes.php
@@ -48,8 +48,8 @@ if ($plugins = CakePlugin::loaded()) {
$plugins[$key] = Inflector::underscore($value);
}
$pluginPattern = implode('|', $plugins);
- $match = array('plugin' => $pluginPattern);
- $shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern);
+ $match = array('plugin' => $pluginPattern, 'defaultRoute' => true);
+ $shortParams = array('routeClass' => 'PluginShortRoute', 'plugin' => $pluginPattern, 'defaultRoute' => true);
foreach ($prefixes as $prefix) {
$params = array('prefix' => $prefix, $prefix => true);
@@ -66,11 +66,11 @@ if ($plugins = CakePlugin::loaded()) {
foreach ($prefixes as $prefix) {
$params = array('prefix' => $prefix, $prefix => true);
$indexParams = $params + array('action' => 'index');
- Router::connect("/{$prefix}/:controller", $indexParams);
- Router::connect("/{$prefix}/:controller/:action/*", $params);
+ Router::connect("/{$prefix}/:controller", $indexParams, array('defaultRoute' => true));
+ Router::connect("/{$prefix}/:controller/:action/*", $params, array('defaultRoute' => true));
}
-Router::connect('/:controller', array('action' => 'index'));
-Router::connect('/:controller/:action/*');
+Router::connect('/:controller', array('action' => 'index'), array('defaultRoute' => true));
+Router::connect('/:controller/:action/*', array(), array('defaultRoute' => true));
$namedConfig = Router::namedConfig();
if ($namedConfig['rules'] === false) {
@@ -79,3 +79,4 @@ if ($namedConfig['rules'] === false) {
unset($namedConfig, $params, $indexParams, $prefix, $prefixes, $shortParams, $match,
$pluginPattern, $plugins, $key, $value);
+
diff --git a/web/api/lib/Cake/Configure/ConfigReaderInterface.php b/web/api/lib/Cake/Configure/ConfigReaderInterface.php
index e36f05697..ddea4e2d3 100644
--- a/web/api/lib/Cake/Configure/ConfigReaderInterface.php
+++ b/web/api/lib/Cake/Configure/ConfigReaderInterface.php
@@ -26,7 +26,7 @@ interface ConfigReaderInterface {
* These sources can either be static resources like files, or dynamic ones like
* a database, or other datasource.
*
- * @param string $key
+ * @param string $key Key to read.
* @return array An array of data to merge into the runtime configuration
*/
public function read($key);
@@ -36,7 +36,7 @@ interface ConfigReaderInterface {
*
* @param string $key The identifier to write to.
* @param array $data The data to dump.
- * @return boolean True on success or false on failure.
+ * @return bool True on success or false on failure.
*/
public function dump($key, $data);
diff --git a/web/api/lib/Cake/Configure/IniReader.php b/web/api/lib/Cake/Configure/IniReader.php
index 886ab1779..ad3b88145 100644
--- a/web/api/lib/Cake/Configure/IniReader.php
+++ b/web/api/lib/Cake/Configure/IniReader.php
@@ -17,6 +17,7 @@
*/
App::uses('Hash', 'Utility');
+App::uses('CakePlugin', 'Core');
/**
* Ini file configuration engine.
@@ -33,10 +34,10 @@ App::uses('Hash', 'Utility');
* You can nest properties as deeply as needed using `.`'s. In addition to using `.` you
* can use standard ini section notation to create nested structures:
*
- * {{{
+ * ```
* [section]
* key = value
- * }}}
+ * ```
*
* Once loaded into Configure, the above would be accessed using:
*
@@ -101,7 +102,7 @@ class IniReader implements ConfigReaderInterface {
}
$file = $this->_getFilePath($key);
- if (!is_file($file)) {
+ if (!is_file(realpath($file))) {
throw new ConfigureException(__d('cake_dev', 'Could not load configuration file: %s', $file));
}
@@ -152,7 +153,7 @@ class IniReader implements ConfigReaderInterface {
* @param string $key The identifier to write to. If the key has a . it will be treated
* as a plugin prefix.
* @param array $data The data to convert to ini file.
- * @return integer Bytes saved.
+ * @return int Bytes saved.
*/
public function dump($key, $data) {
$result = array();
@@ -181,7 +182,7 @@ class IniReader implements ConfigReaderInterface {
/**
* Converts a value into the ini equivalent
*
- * @param mixed $value to export.
+ * @param mixed $val Value to export.
* @return string String value for ini file.
*/
protected function _value($val) {
@@ -218,7 +219,7 @@ class IniReader implements ConfigReaderInterface {
}
if ($plugin) {
- $file = App::pluginPath($plugin) . 'Config' . DS . $key;
+ $file = CakePlugin::path($plugin) . 'Config' . DS . $key;
} else {
$file = $this->_path . $key;
}
diff --git a/web/api/lib/Cake/Configure/PhpReader.php b/web/api/lib/Cake/Configure/PhpReader.php
index 175168a39..d15a41b83 100644
--- a/web/api/lib/Cake/Configure/PhpReader.php
+++ b/web/api/lib/Cake/Configure/PhpReader.php
@@ -15,6 +15,8 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
+App::uses('CakePlugin', 'Core');
+
/**
* PHP Reader allows Configure to load configuration values from
* files containing simple PHP arrays.
@@ -49,7 +51,7 @@ class PhpReader implements ConfigReaderInterface {
* Read a config file and return its contents.
*
* Files with `.` in the name will be treated as values in plugins. Instead of reading from
- * the initialized path, plugin keys will be located using App::pluginPath().
+ * the initialized path, plugin keys will be located using CakePlugin::path().
*
* @param string $key The identifier to read from. If the key has a . it will be treated
* as a plugin prefix.
@@ -63,7 +65,7 @@ class PhpReader implements ConfigReaderInterface {
}
$file = $this->_getFilePath($key);
- if (!is_file($file)) {
+ if (!is_file(realpath($file))) {
throw new ConfigureException(__d('cake_dev', 'Could not load configuration file: %s', $file));
}
@@ -81,7 +83,7 @@ class PhpReader implements ConfigReaderInterface {
* @param string $key The identifier to write to. If the key has a . it will be treated
* as a plugin prefix.
* @param array $data Data to dump.
- * @return integer Bytes saved.
+ * @return int Bytes saved.
*/
public function dump($key, $data) {
$contents = '_path . $key;
}
diff --git a/web/api/lib/Cake/Console/Command/AclShell.php b/web/api/lib/Cake/Console/Command/AclShell.php
index ac5b3cdfe..15536ebb6 100644
--- a/web/api/lib/Cake/Console/Command/AclShell.php
+++ b/web/api/lib/Cake/Console/Command/AclShell.php
@@ -220,7 +220,7 @@ class AclShell extends AppShell {
*
* @param string $class Class name that is being used.
* @param array $node Array of node information.
- * @param integer $indent indent level.
+ * @param int $indent indent level.
* @return void
*/
protected function _outputNode($class, $node, $indent) {
@@ -519,7 +519,7 @@ class AclShell extends AppShell {
/**
* Checks that given node exists
*
- * @return boolean Success
+ * @return bool Success
*/
public function nodeExists() {
if (!isset($this->args[0]) || !isset($this->args[1])) {
@@ -558,8 +558,8 @@ class AclShell extends AppShell {
* or an array of properties to use in AcoNode::node()
*
* @param string $class Class type you want (Aro/Aco)
- * @param string|array $identifier A mixed identifier for finding the node.
- * @return integer Integer of NodeId. Will trigger an error if nothing is found.
+ * @param string|array|null $identifier A mixed identifier for finding the node, otherwise null.
+ * @return int Integer of NodeId. Will trigger an error if nothing is found.
*/
protected function _getNodeId($class, $identifier) {
$node = $this->Acl->{$class}->node($identifier);
@@ -568,7 +568,7 @@ class AclShell extends AppShell {
$identifier = var_export($identifier, true);
}
$this->error(__d('cake_console', 'Could not find node using reference "%s"', $identifier));
- return;
+ return null;
}
return Hash::get($node, "0.{$class}.id");
}
@@ -579,8 +579,8 @@ class AclShell extends AppShell {
* @return array aro, aco, action
*/
protected function _getParams() {
- $aro = is_numeric($this->args[0]) ? intval($this->args[0]) : $this->args[0];
- $aco = is_numeric($this->args[1]) ? intval($this->args[1]) : $this->args[1];
+ $aro = is_numeric($this->args[0]) ? (int)$this->args[0] : $this->args[0];
+ $aco = is_numeric($this->args[1]) ? (int)$this->args[1] : $this->args[1];
$aroName = $aro;
$acoName = $aco;
diff --git a/web/api/lib/Cake/Console/Command/CommandListShell.php b/web/api/lib/Cake/Console/Command/CommandListShell.php
index 755166f41..ca6620a5b 100644
--- a/web/api/lib/Cake/Console/Command/CommandListShell.php
+++ b/web/api/lib/Cake/Console/Command/CommandListShell.php
@@ -77,7 +77,7 @@ class CommandListShell extends AppShell {
/**
* Output text.
*
- * @param array $shellList
+ * @param array $shellList The shell list.
* @return void
*/
protected function _asText($shellList) {
@@ -95,7 +95,7 @@ class CommandListShell extends AppShell {
/**
* Output as XML
*
- * @param array $shellList
+ * @param array $shellList The shell list.
* @return void
*/
protected function _asXml($shellList) {
diff --git a/web/api/lib/Cake/Console/Command/CompletionShell.php b/web/api/lib/Cake/Console/Command/CompletionShell.php
index b57c84145..57e86f949 100644
--- a/web/api/lib/Cake/Console/Command/CompletionShell.php
+++ b/web/api/lib/Cake/Console/Command/CompletionShell.php
@@ -144,7 +144,7 @@ class CompletionShell extends AppShell {
/**
* Emit results as a string, space delimited
*
- * @param array $options
+ * @param array $options The options to output
* @return void
*/
protected function _output($options = array()) {
diff --git a/web/api/lib/Cake/Console/Command/ConsoleShell.php b/web/api/lib/Cake/Console/Command/ConsoleShell.php
index 917015a9f..ac270e19b 100644
--- a/web/api/lib/Cake/Console/Command/ConsoleShell.php
+++ b/web/api/lib/Cake/Console/Command/ConsoleShell.php
@@ -19,7 +19,7 @@ App::uses('AppShell', 'Console/Command');
* Provides a very basic 'interactive' console for CakePHP apps.
*
* @package Cake.Console.Command
- * @deprecated Deprecated since version 2.4, will be removed in 3.0
+ * @deprecated 3.0.0 Deprecated since version 2.4, will be removed in 3.0
*/
class ConsoleShell extends AppShell {
@@ -193,7 +193,7 @@ class ConsoleShell extends AppShell {
/**
* Override main() to handle action
*
- * @param string $command
+ * @param string $command The command to run.
* @return void
*/
public function main($command = null) {
@@ -218,7 +218,7 @@ class ConsoleShell extends AppShell {
/**
* Determine the method to process the current command
*
- * @param string $command
+ * @param string $command The command to run.
* @return string or false
*/
protected function _method($command) {
@@ -256,7 +256,7 @@ class ConsoleShell extends AppShell {
/**
* Bind an association
*
- * @param mixed $command
+ * @param mixed $command The command to run.
* @return void
*/
protected function _bind($command) {
@@ -283,7 +283,7 @@ class ConsoleShell extends AppShell {
/**
* Unbind an association
*
- * @param mixed $command
+ * @param mixed $command The command to run.
* @return void
*/
protected function _unbind($command) {
@@ -303,7 +303,7 @@ class ConsoleShell extends AppShell {
$validCurrentAssociation = false;
foreach ($currentAssociations as $model => $currentAssociation) {
- if ($model == $modelB && $association == $currentAssociation) {
+ if ($model === $modelB && $association === $currentAssociation) {
$validCurrentAssociation = true;
}
}
@@ -320,7 +320,7 @@ class ConsoleShell extends AppShell {
/**
* Perform a find
*
- * @param mixed $command
+ * @param mixed $command The command to run.
* @return void
*/
protected function _find($command) {
@@ -382,7 +382,7 @@ class ConsoleShell extends AppShell {
/**
* Save a record
*
- * @param mixed $command
+ * @param mixed $command The command to run.
* @return void
*/
protected function _save($command) {
@@ -406,7 +406,7 @@ class ConsoleShell extends AppShell {
/**
* Show the columns for a model
*
- * @param mixed $command
+ * @param mixed $command The command to run.
* @return void
*/
protected function _columns($command) {
@@ -455,7 +455,7 @@ class ConsoleShell extends AppShell {
/**
* Parse an array URL and show the equivalent URL as a string
*
- * @param mixed $command
+ * @param mixed $command The command to run.
* @return void
*/
protected function _routeToString($command) {
@@ -471,7 +471,7 @@ class ConsoleShell extends AppShell {
/**
* Parse a string URL and show as an array
*
- * @param mixed $command
+ * @param mixed $command The command to run.
* @return void
*/
protected function _routeToArray($command) {
@@ -483,8 +483,8 @@ class ConsoleShell extends AppShell {
/**
* Tells if the specified model is included in the list of available models
*
- * @param string $modelToCheck
- * @return boolean true if is an available model, false otherwise
+ * @param string $modelToCheck The model to check.
+ * @return bool true if is an available model, false otherwise
*/
protected function _isValidModel($modelToCheck) {
return in_array($modelToCheck, $this->models);
@@ -494,7 +494,7 @@ class ConsoleShell extends AppShell {
* Reloads the routes configuration from app/Config/routes.php, and compiles
* all routes found
*
- * @return boolean True if config reload was a success, otherwise false
+ * @return bool True if config reload was a success, otherwise false
*/
protected function _loadRoutes() {
Router::reload();
diff --git a/web/api/lib/Cake/Console/Command/SchemaShell.php b/web/api/lib/Cake/Console/Command/SchemaShell.php
index 6df8a32ea..a2ddfcc0a 100644
--- a/web/api/lib/Cake/Console/Command/SchemaShell.php
+++ b/web/api/lib/Cake/Console/Command/SchemaShell.php
@@ -39,7 +39,7 @@ class SchemaShell extends AppShell {
/**
* is this a dry run?
*
- * @var boolean
+ * @var bool
*/
protected $_dry = null;
@@ -66,13 +66,10 @@ class SchemaShell extends AppShell {
list($this->params['plugin'], $splitName) = pluginSplit($name);
$name = $this->params['name'] = $splitName;
}
-
- $defaultFile = 'schema.php';
- if (empty($this->params['file'])) {
- $this->params['file'] = $defaultFile;
- }
- if ($name && $this->params['file'] === $defaultFile) {
+ if ($name && empty($this->params['file'])) {
$this->params['file'] = Inflector::underscore($name);
+ } elseif (empty($this->params['file'])) {
+ $this->params['file'] = 'schema.php';
}
if (strpos($this->params['file'], '.php') === false) {
$this->params['file'] .= '.php';
@@ -92,7 +89,7 @@ class SchemaShell extends AppShell {
$name = $plugin;
}
}
- $name = Inflector::classify($name);
+ $name = Inflector::camelize($name);
$this->Schema = new CakeSchema(compact('name', 'path', 'file', 'connection', 'plugin'));
}
@@ -125,7 +122,7 @@ class SchemaShell extends AppShell {
if ($this->params['force']) {
$options['models'] = false;
} elseif (!empty($this->params['models'])) {
- $options['models'] = String::tokenize($this->params['models']);
+ $options['models'] = CakeText::tokenize($this->params['models']);
}
$snapshot = false;
@@ -154,14 +151,14 @@ class SchemaShell extends AppShell {
Configure::write('Cache.disable', $cacheDisable);
if (!empty($this->params['exclude']) && !empty($content)) {
- $excluded = String::tokenize($this->params['exclude']);
+ $excluded = CakeText::tokenize($this->params['exclude']);
foreach ($excluded as $table) {
unset($content['tables'][$table]);
}
}
if ($snapshot === true) {
- $fileName = rtrim($this->params['file'], '.php');
+ $fileName = basename($this->params['file'], '.php');
$Folder = new Folder($this->Schema->path);
$result = $Folder->read();
@@ -288,17 +285,17 @@ class SchemaShell extends AppShell {
'connection' => $this->params['connection'],
);
if (!empty($this->params['snapshot'])) {
- $fileName = rtrim($this->Schema->file, '.php');
+ $fileName = basename($this->Schema->file, '.php');
$options['file'] = $fileName . '_' . $this->params['snapshot'] . '.php';
}
$Schema = $this->Schema->load($options);
if (!$Schema) {
- $this->err(__d('cake_console', 'The chosen schema could not be loaded. Attempted to load:'));
- $this->err(__d('cake_console', 'File: %s', $this->Schema->path . DS . $this->Schema->file));
- $this->err(__d('cake_console', 'Name: %s', $this->Schema->name));
- return $this->_stop();
+ $this->err(__d('cake_console', 'Error: The chosen schema could not be loaded. Attempted to load:'));
+ $this->err(__d('cake_console', '- file: %s', $this->Schema->path . DS . $this->Schema->file));
+ $this->err(__d('cake_console', '- name: %s', $this->Schema->name));
+ return $this->_stop(2);
}
$table = null;
if (isset($this->args[1])) {
@@ -311,8 +308,8 @@ class SchemaShell extends AppShell {
* Create database from Schema object
* Should be called via the run method
*
- * @param CakeSchema $Schema
- * @param string $table
+ * @param CakeSchema $Schema The schema instance to create.
+ * @param string $table The table name.
* @return void
*/
protected function _create(CakeSchema $Schema, $table = null) {
@@ -337,8 +334,7 @@ class SchemaShell extends AppShell {
$this->out("\n" . __d('cake_console', 'The following table(s) will be dropped.'));
$this->out(array_keys($drop));
- if (
- !empty($this->params['yes']) ||
+ if (!empty($this->params['yes']) ||
$this->in(__d('cake_console', 'Are you sure you want to drop the table(s)?'), array('y', 'n'), 'n') === 'y'
) {
$this->out(__d('cake_console', 'Dropping table(s).'));
@@ -348,8 +344,7 @@ class SchemaShell extends AppShell {
$this->out("\n" . __d('cake_console', 'The following table(s) will be created.'));
$this->out(array_keys($create));
- if (
- !empty($this->params['yes']) ||
+ if (!empty($this->params['yes']) ||
$this->in(__d('cake_console', 'Are you sure you want to create the table(s)?'), array('y', 'n'), 'y') === 'y'
) {
$this->out(__d('cake_console', 'Creating table(s).'));
@@ -362,8 +357,8 @@ class SchemaShell extends AppShell {
* Update database with Schema object
* Should be called via the run method
*
- * @param CakeSchema $Schema
- * @param string $table
+ * @param CakeSchema &$Schema The schema instance
+ * @param string $table The table name.
* @return void
*/
protected function _update(&$Schema, $table = null) {
@@ -402,13 +397,15 @@ class SchemaShell extends AppShell {
$this->out("\n" . __d('cake_console', 'The following statements will run.'));
$this->out(array_map('trim', $contents));
- if (
- !empty($this->params['yes']) ||
+ if (!empty($this->params['yes']) ||
$this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n') === 'y'
) {
$this->out();
$this->out(__d('cake_console', 'Updating Database...'));
$this->_run($contents, 'update', $Schema);
+
+ Configure::write('Cache.disable', false);
+ Cache::clear(false, '_cake_model_');
}
$this->out(__d('cake_console', 'End update.'));
@@ -417,9 +414,9 @@ class SchemaShell extends AppShell {
/**
* Runs sql from _create() or _update()
*
- * @param array $contents
- * @param string $event
- * @param CakeSchema $Schema
+ * @param array $contents The contents to execute.
+ * @param string $event The event to fire
+ * @param CakeSchema $Schema The schema instance.
* @return void
*/
protected function _run($contents, $event, CakeSchema $Schema) {
@@ -483,7 +480,6 @@ class SchemaShell extends AppShell {
);
$file = array(
'help' => __d('cake_console', 'File name to read and write.'),
- 'default' => 'schema.php'
);
$name = array(
'help' => __d('cake_console',
diff --git a/web/api/lib/Cake/Console/Command/ServerShell.php b/web/api/lib/Cake/Console/Command/ServerShell.php
index ae46f6ef8..8c7d5e5e3 100644
--- a/web/api/lib/Cake/Console/Command/ServerShell.php
+++ b/web/api/lib/Cake/Console/Command/ServerShell.php
@@ -34,7 +34,7 @@ class ServerShell extends AppShell {
/**
* Default ListenPort
*
- * @var integer
+ * @var int
*/
const DEFAULT_PORT = 80;
@@ -65,8 +65,8 @@ class ServerShell extends AppShell {
* @return void
*/
public function initialize() {
- $this->_host = self::DEFAULT_HOST;
- $this->_port = self::DEFAULT_PORT;
+ $this->_host = static::DEFAULT_HOST;
+ $this->_port = static::DEFAULT_PORT;
$this->_documentRoot = WWW_ROOT;
}
@@ -91,8 +91,8 @@ class ServerShell extends AppShell {
$this->_documentRoot = $this->params['document_root'];
}
- // for windows
- if (substr($this->_documentRoot, -1, 1) == DIRECTORY_SEPARATOR) {
+ // for Windows
+ if (substr($this->_documentRoot, -1, 1) === DIRECTORY_SEPARATOR) {
$this->_documentRoot = substr($this->_documentRoot, 0, strlen($this->_documentRoot) - 1);
}
if (preg_match("/^([a-z]:)[\\\]+(.+)$/i", $this->_documentRoot, $m)) {
@@ -135,7 +135,7 @@ class ServerShell extends AppShell {
escapeshellarg($this->_documentRoot . '/index.php')
);
- $port = ($this->_port == self::DEFAULT_PORT) ? '' : ':' . $this->_port;
+ $port = ($this->_port == static::DEFAULT_PORT) ? '' : ':' . $this->_port;
$this->out(__d('cake_console', 'built-in server is running in http://%s%s/', $this->_host, $port));
system($command);
}
diff --git a/web/api/lib/Cake/Console/Command/Task/BakeTask.php b/web/api/lib/Cake/Console/Command/Task/BakeTask.php
index 6b534f365..8298e112a 100644
--- a/web/api/lib/Cake/Console/Command/Task/BakeTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/BakeTask.php
@@ -41,7 +41,7 @@ class BakeTask extends AppShell {
/**
* Flag for interactive mode
*
- * @var boolean
+ * @var bool
*/
public $interactive = false;
diff --git a/web/api/lib/Cake/Console/Command/Task/CommandTask.php b/web/api/lib/Cake/Console/Command/Task/CommandTask.php
index 9c90fc6be..fca006a72 100644
--- a/web/api/lib/Cake/Console/Command/Task/CommandTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/CommandTask.php
@@ -53,9 +53,9 @@ class CommandTask extends AppShell {
/**
* Scan the provided paths for shells, and append them into $shellList
*
- * @param string $type
- * @param array $shells
- * @param array $shellList
+ * @param string $type The type of object.
+ * @param array $shells The shell name.
+ * @param array &$shellList List of shells.
* @return void
*/
protected function _appendShells($type, $shells, &$shellList) {
@@ -90,7 +90,7 @@ class CommandTask extends AppShell {
/**
* Return a list of subcommands for a given command
*
- * @param string $commandName
+ * @param string $commandName The command you want subcommands from.
* @return array
*/
public function subCommands($commandName) {
@@ -127,7 +127,7 @@ class CommandTask extends AppShell {
/**
* Get Shell instance for the given command
*
- * @param mixed $commandName
+ * @param mixed $commandName The command you want.
* @return mixed
*/
public function getShell($commandName) {
@@ -157,7 +157,7 @@ class CommandTask extends AppShell {
/**
* Get Shell instance for the given command
*
- * @param mixed $commandName
+ * @param mixed $commandName The command to get options for.
* @return array
*/
public function options($commandName) {
diff --git a/web/api/lib/Cake/Console/Command/Task/ControllerTask.php b/web/api/lib/Cake/Console/Command/Task/ControllerTask.php
index 5a4553466..fc2d91343 100644
--- a/web/api/lib/Cake/Console/Command/Task/ControllerTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/ControllerTask.php
@@ -188,6 +188,7 @@ class ControllerTask extends BakeTask {
if (strtolower($wannaUseSession) === 'y') {
array_push($components, 'Session');
}
+ array_unique($components);
}
} else {
list($wannaBakeCrud, $wannaBakeAdminCrud) = $this->_askAboutMethods();
@@ -224,10 +225,10 @@ class ControllerTask extends BakeTask {
/**
* Confirm a to be baked controller with the user
*
- * @param string $controllerName
- * @param string $useDynamicScaffold
- * @param array $helpers
- * @param array $components
+ * @param string $controllerName The name of the controller.
+ * @param string $useDynamicScaffold Whether or not to use dynamic scaffolds.
+ * @param array $helpers The list of helpers to include.
+ * @param array $components The list of components to include.
* @return void
*/
public function confirmController($controllerName, $useDynamicScaffold, $helpers, $components) {
@@ -247,10 +248,10 @@ class ControllerTask extends BakeTask {
);
foreach ($properties as $var => $title) {
- if (count($$var)) {
+ if (count(${$var})) {
$output = '';
- $length = count($$var);
- foreach ($$var as $i => $propElement) {
+ $length = count(${$var});
+ foreach (${$var} as $i => $propElement) {
if ($i != $length - 1) {
$output .= ucfirst($propElement) . ', ';
} else {
@@ -285,7 +286,7 @@ class ControllerTask extends BakeTask {
*
* @param string $controllerName Controller name
* @param string $admin Admin route to use
- * @param boolean $wannaUseSession Set to true to use sessions, false otherwise
+ * @param bool $wannaUseSession Set to true to use sessions, false otherwise
* @return string Baked actions
*/
public function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
@@ -383,9 +384,9 @@ class ControllerTask extends BakeTask {
* @return array Components the user wants to use.
*/
public function doComponents() {
- $components = array('Paginator');
+ $components = array('Paginator', 'Flash');
return array_merge($components, $this->_doPropertyChoices(
- __d('cake_console', "Would you like this controller to use other components\nbesides PaginatorComponent?"),
+ __d('cake_console', "Would you like this controller to use other components\nbesides PaginatorComponent and FlashComponent?"),
__d('cake_console', "Please provide a comma separated list of the component names you'd like to use.\nExample: 'Acl, Security, RequestHandler'")
));
}
@@ -451,14 +452,14 @@ class ControllerTask extends BakeTask {
return $this->_stop();
}
- if (!$enteredController || intval($enteredController) > count($controllers)) {
+ if (!$enteredController || (int)$enteredController > count($controllers)) {
$this->err(__d('cake_console', "The Controller name you supplied was empty,\nor the number you selected was not an option. Please try again."));
$enteredController = '';
}
}
- if (intval($enteredController) > 0 && intval($enteredController) <= count($controllers)) {
- $controllerName = $controllers[intval($enteredController) - 1];
+ if ((int)$enteredController > 0 && (int)$enteredController <= count($controllers)) {
+ $controllerName = $controllers[(int)$enteredController - 1];
} else {
$controllerName = Inflector::camelize($enteredController);
}
diff --git a/web/api/lib/Cake/Console/Command/Task/DbConfigTask.php b/web/api/lib/Cake/Console/Command/Task/DbConfigTask.php
index 75c0c13b6..ee1aa6c99 100644
--- a/web/api/lib/Cake/Console/Command/Task/DbConfigTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/DbConfigTask.php
@@ -199,8 +199,8 @@ class DbConfigTask extends AppShell {
/**
* Output verification message and bake if it looks good
*
- * @param array $config
- * @return boolean True if user says it looks good, false otherwise
+ * @param array $config The config data.
+ * @return bool True if user says it looks good, false otherwise
*/
protected function _verify($config) {
$config += $this->_defaultConfig;
@@ -247,7 +247,7 @@ class DbConfigTask extends AppShell {
* Assembles and writes database.php
*
* @param array $configs Configuration settings to use
- * @return boolean Success
+ * @return bool Success
*/
public function bake($configs) {
if (!is_dir($this->path)) {
@@ -296,7 +296,7 @@ class DbConfigTask extends AppShell {
foreach ($oldConfigs as $key => $oldConfig) {
foreach ($configs as $config) {
- if ($oldConfig['name'] == $config['name']) {
+ if ($oldConfig['name'] === $config['name']) {
unset($oldConfigs[$key]);
}
}
diff --git a/web/api/lib/Cake/Console/Command/Task/ExtractTask.php b/web/api/lib/Cake/Console/Command/Task/ExtractTask.php
index d60bc0e5c..740528f70 100644
--- a/web/api/lib/Cake/Console/Command/Task/ExtractTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/ExtractTask.php
@@ -44,7 +44,7 @@ class ExtractTask extends AppShell {
/**
* Merge all domain and category strings into the default.pot file
*
- * @var boolean
+ * @var bool
*/
protected $_merge = false;
@@ -70,7 +70,7 @@ class ExtractTask extends AppShell {
protected $_tokens = array();
/**
- * Extracted strings indexed by category and domain.
+ * Extracted strings indexed by category, domain, msgid and context.
*
* @var array
*/
@@ -93,21 +93,21 @@ class ExtractTask extends AppShell {
/**
* Holds whether this call should extract model validation messages
*
- * @var boolean
+ * @var bool
*/
protected $_extractValidation = true;
/**
* Holds the validation string domain to use for validation messages when extracting
*
- * @var boolean
+ * @var bool
*/
protected $_validationDomain = 'default';
/**
* Holds whether this call should extract the CakePHP Lib messages
*
- * @var boolean
+ * @var bool
*/
protected $_extractCore = false;
@@ -127,7 +127,7 @@ class ExtractTask extends AppShell {
);
$response = $this->in($message, null, $defaultPath);
if (strtoupper($response) === 'Q') {
- $this->out(__d('cake_console', 'Extract Aborted'));
+ $this->err(__d('cake_console', 'Extract Aborted'));
return $this->_stop();
} elseif (strtoupper($response) === 'D' && count($this->_paths)) {
$this->out();
@@ -151,7 +151,7 @@ class ExtractTask extends AppShell {
*/
public function execute() {
if (!empty($this->params['exclude'])) {
- $this->_exclude = explode(',', $this->params['exclude']);
+ $this->_exclude = explode(',', str_replace('/', DS, $this->params['exclude']));
}
if (isset($this->params['files']) && !is_array($this->params['files'])) {
$this->_files = explode(',', $this->params['files']);
@@ -204,7 +204,7 @@ class ExtractTask extends AppShell {
while (true) {
$response = $this->in($message, null, rtrim($this->_paths[0], DS) . DS . 'Locale');
if (strtoupper($response) === 'Q') {
- $this->out(__d('cake_console', 'Extract Aborted'));
+ $this->err(__d('cake_console', 'Extract Aborted'));
return $this->_stop();
} elseif ($this->_isPathUsable($response)) {
$this->_output = $response . DS;
@@ -242,29 +242,33 @@ class ExtractTask extends AppShell {
*
* Takes care of duplicate translations
*
- * @param string $category
- * @param string $domain
- * @param string $msgid
- * @param array $details
+ * @param string $category The category
+ * @param string $domain The domain
+ * @param string $msgid The message string
+ * @param array $details The file and line references
* @return void
*/
protected function _addTranslation($category, $domain, $msgid, $details = array()) {
- if (empty($this->_translations[$category][$domain][$msgid])) {
- $this->_translations[$category][$domain][$msgid] = array(
- 'msgid_plural' => false
+ $context = '';
+ if (isset($details['msgctxt'])) {
+ $context = $details['msgctxt'];
+ }
+
+ if (empty($this->_translations[$category][$domain][$msgid][$context])) {
+ $this->_translations[$category][$domain][$msgid][$context] = array(
+ 'msgid_plural' => false,
);
}
if (isset($details['msgid_plural'])) {
- $this->_translations[$category][$domain][$msgid]['msgid_plural'] = $details['msgid_plural'];
+ $this->_translations[$category][$domain][$msgid][$context]['msgid_plural'] = $details['msgid_plural'];
}
-
if (isset($details['file'])) {
$line = 0;
if (isset($details['line'])) {
$line = $details['line'];
}
- $this->_translations[$category][$domain][$msgid]['references'][$details['file']][] = $line;
+ $this->_translations[$category][$domain][$msgid][$context]['references'][$details['file']][] = $line;
}
}
@@ -312,6 +316,10 @@ class ExtractTask extends AppShell {
))->addOption('merge', array(
'help' => __d('cake_console', 'Merge all domain and category strings into the default.po file.'),
'choices' => array('yes', 'no')
+ ))->addOption('no-location', array(
+ 'boolean' => true,
+ 'default' => false,
+ 'help' => __d('cake_console', 'Do not write lines with locations'),
))->addOption('output', array(
'help' => __d('cake_console', 'Full path to output directory.')
))->addOption('files', array(
@@ -355,14 +363,14 @@ class ExtractTask extends AppShell {
protected function _extractTokens() {
foreach ($this->_files as $file) {
$this->_file = $file;
- $this->out(__d('cake_console', 'Processing %s...', $file));
+ $this->out(__d('cake_console', 'Processing %s...', $file), 1, Shell::VERBOSE);
$code = file_get_contents($file);
$allTokens = token_get_all($code);
$this->_tokens = array();
foreach ($allTokens as $token) {
- if (!is_array($token) || ($token[0] != T_WHITESPACE && $token[0] != T_INLINE_HTML)) {
+ if (!is_array($token) || ($token[0] !== T_WHITESPACE && $token[0] !== T_INLINE_HTML)) {
$this->_tokens[] = $token;
}
}
@@ -374,6 +382,15 @@ class ExtractTask extends AppShell {
$this->_parse('__dc', array('domain', 'singular', 'category'));
$this->_parse('__dn', array('domain', 'singular', 'plural'));
$this->_parse('__dcn', array('domain', 'singular', 'plural', 'count', 'category'));
+
+ $this->_parse('__x', array('context', 'singular'));
+ $this->_parse('__xn', array('context', 'singular', 'plural'));
+ $this->_parse('__dx', array('domain', 'context', 'singular'));
+ $this->_parse('__dxc', array('domain', 'context', 'singular', 'category'));
+ $this->_parse('__dxn', array('domain', 'context', 'singular', 'plural'));
+ $this->_parse('__dxcn', array('domain', 'context', 'singular', 'plural', 'count', 'category'));
+ $this->_parse('__xc', array('context', 'singular', 'category'));
+
}
}
@@ -398,7 +415,7 @@ class ExtractTask extends AppShell {
}
list($type, $string, $line) = $countToken;
- if (($type == T_STRING) && ($string == $functionName) && ($firstParenthesis === '(')) {
+ if (($type == T_STRING) && ($string === $functionName) && ($firstParenthesis === '(')) {
$position = $count;
$depth = 0;
@@ -414,11 +431,12 @@ class ExtractTask extends AppShell {
$mapCount = count($map);
$strings = $this->_getStrings($position, $mapCount);
- if ($mapCount == count($strings)) {
+ if ($mapCount === count($strings)) {
extract(array_combine($map, $strings));
$category = isset($category) ? $category : 6;
- $category = intval($category);
+ $category = (int)$category;
$categoryName = $categories[$category];
+
$domain = isset($domain) ? $domain : 'default';
$details = array(
'file' => $this->_file,
@@ -427,8 +445,14 @@ class ExtractTask extends AppShell {
if (isset($plural)) {
$details['msgid_plural'] = $plural;
}
- $this->_addTranslation($categoryName, $domain, $singular, $details);
- } else {
+ if (isset($context)) {
+ $details['msgctxt'] = $context;
+ }
+ // Skip LC_TIME files as we use a special file format for them.
+ if ($categoryName !== 'LC_TIME') {
+ $this->_addTranslation($categoryName, $domain, $singular, $details);
+ }
+ } elseif (!is_array($this->_tokens[$count - 1]) || $this->_tokens[$count - 1][0] != T_FUNCTION) {
$this->_markerError($this->_file, $line, $functionName, $count);
}
}
@@ -547,32 +571,46 @@ class ExtractTask extends AppShell {
protected function _buildFiles() {
$paths = $this->_paths;
$paths[] = realpath(APP) . DS;
+
+ usort($paths, function ($a, $b) {
+ return strlen($b) - strlen($a);
+ });
+
foreach ($this->_translations as $category => $domains) {
foreach ($domains as $domain => $translations) {
- foreach ($translations as $msgid => $details) {
- $plural = $details['msgid_plural'];
- $files = $details['references'];
- $occurrences = array();
- foreach ($files as $file => $lines) {
- $lines = array_unique($lines);
- $occurrences[] = $file . ':' . implode(';', $lines);
- }
- $occurrences = implode("\n#: ", $occurrences);
- $header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
+ foreach ($translations as $msgid => $contexts) {
+ foreach ($contexts as $context => $details) {
+ $plural = $details['msgid_plural'];
+ $header = '';
+ if (empty($this->params['no-location'])) {
+ $files = $details['references'];
+ $occurrences = array();
+ foreach ($files as $file => $lines) {
+ $lines = array_unique($lines);
+ $occurrences[] = $file . ':' . implode(';', $lines);
+ }
+ $occurrences = implode("\n#: ", $occurrences);
+ $header = '#: ' . str_replace(DS, '/', str_replace($paths, '', $occurrences)) . "\n";
+ }
- if ($plural === false) {
- $sentence = "msgid \"{$msgid}\"\n";
- $sentence .= "msgstr \"\"\n\n";
- } else {
- $sentence = "msgid \"{$msgid}\"\n";
- $sentence .= "msgid_plural \"{$plural}\"\n";
- $sentence .= "msgstr[0] \"\"\n";
- $sentence .= "msgstr[1] \"\"\n\n";
- }
+ $sentence = '';
+ if ($context) {
+ $sentence .= "msgctxt \"{$context}\"\n";
+ }
+ if ($plural === false) {
+ $sentence .= "msgid \"{$msgid}\"\n";
+ $sentence .= "msgstr \"\"\n\n";
+ } else {
+ $sentence .= "msgid \"{$msgid}\"\n";
+ $sentence .= "msgid_plural \"{$plural}\"\n";
+ $sentence .= "msgstr[0] \"\"\n";
+ $sentence .= "msgstr[1] \"\"\n\n";
+ }
- $this->_store($category, $domain, $header, $sentence);
- if (($category !== 'LC_MESSAGES' || $domain !== 'default') && $this->_merge) {
- $this->_store('LC_MESSAGES', 'default', $header, $sentence);
+ $this->_store($category, $domain, $header, $sentence);
+ if (($category !== 'LC_MESSAGES' || $domain !== 'default') && $this->_merge) {
+ $this->_store('LC_MESSAGES', 'default', $header, $sentence);
+ }
}
}
}
@@ -582,10 +620,10 @@ class ExtractTask extends AppShell {
/**
* Prepare a file to be stored
*
- * @param string $category
- * @param string $domain
- * @param string $header
- * @param string $sentence
+ * @param string $category The category
+ * @param string $domain The domain
+ * @param string $header The header content.
+ * @param string $sentence The sentence to store.
* @return void
*/
protected function _store($category, $domain, $header, $sentence) {
@@ -664,7 +702,6 @@ class ExtractTask extends AppShell {
$output .= "msgid \"\"\n";
$output .= "msgstr \"\"\n";
$output .= "\"Project-Id-Version: PROJECT VERSION\\n\"\n";
- $output .= "\"POT-Creation-Date: " . date("Y-m-d H:iO") . "\\n\"\n";
$output .= "\"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\\n\"\n";
$output .= "\"Last-Translator: NAME \\n\"\n";
$output .= "\"Language-Team: LANGUAGE \\n\"\n";
@@ -678,8 +715,8 @@ class ExtractTask extends AppShell {
/**
* Get the strings from the position forward
*
- * @param integer $position Actual position on tokens array
- * @param integer $target Number of strings to extract
+ * @param int &$position Actual position on tokens array
+ * @param int $target Number of strings to extract
* @return array Strings extracted
*/
protected function _getStrings(&$position, $target) {
@@ -728,22 +765,22 @@ class ExtractTask extends AppShell {
* Indicate an invalid marker on a processed file
*
* @param string $file File where invalid marker resides
- * @param integer $line Line number
+ * @param int $line Line number
* @param string $marker Marker found
- * @param integer $count Count
+ * @param int $count Count
* @return void
*/
protected function _markerError($file, $line, $marker, $count) {
- $this->out(__d('cake_console', "Invalid marker content in %s:%s\n* %s(", $file, $line, $marker));
+ $this->err(__d('cake_console', "Invalid marker content in %s:%s\n* %s(", $file, $line, $marker));
$count += 2;
$tokenCount = count($this->_tokens);
$parenthesis = 1;
while ((($tokenCount - $count) > 0) && $parenthesis) {
if (is_array($this->_tokens[$count])) {
- $this->out($this->_tokens[$count][1], false);
+ $this->err($this->_tokens[$count][1], false);
} else {
- $this->out($this->_tokens[$count], false);
+ $this->err($this->_tokens[$count], false);
if ($this->_tokens[$count] === '(') {
$parenthesis++;
}
@@ -754,7 +791,7 @@ class ExtractTask extends AppShell {
}
$count++;
}
- $this->out("\n", true);
+ $this->err("\n", true);
}
/**
@@ -774,26 +811,24 @@ class ExtractTask extends AppShell {
}
$pattern = '/' . implode('|', $exclude) . '/';
}
- foreach ($this->_paths as $path) {
- $Folder = new Folder($path);
+ foreach ($this->_paths as $i => $path) {
+ $this->_paths[$i] = realpath($path) . DS;
+ $Folder = new Folder($this->_paths[$i]);
$files = $Folder->findRecursive('.*\.(php|ctp|thtml|inc|tpl)', true);
if (!empty($pattern)) {
- foreach ($files as $i => $file) {
- if (preg_match($pattern, $file)) {
- unset($files[$i]);
- }
- }
+ $files = preg_grep($pattern, $files, PREG_GREP_INVERT);
$files = array_values($files);
}
$this->_files = array_merge($this->_files, $files);
}
+ $this->_files = array_unique($this->_files);
}
/**
* Returns whether this execution is meant to extract string only from directories in folder represented by the
* APP constant, i.e. this task is extracting strings from same application.
*
- * @return boolean
+ * @return bool
*/
protected function _isExtractingApp() {
return $this->_paths === array(APP);
@@ -803,7 +838,7 @@ class ExtractTask extends AppShell {
* Checks whether or not a given path is usable for writing.
*
* @param string $path Path to folder
- * @return boolean true if it exists and is writable, false otherwise
+ * @return bool true if it exists and is writable, false otherwise
*/
protected function _isPathUsable($path) {
return is_dir($path) && is_writable($path);
diff --git a/web/api/lib/Cake/Console/Command/Task/FixtureTask.php b/web/api/lib/Cake/Console/Command/Task/FixtureTask.php
index 0be6d36dd..1f578d083 100644
--- a/web/api/lib/Cake/Console/Command/Task/FixtureTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/FixtureTask.php
@@ -74,7 +74,7 @@ class FixtureTask extends BakeTask {
))->addOption('count', array(
'help' => __d('cake_console', 'When using generated data, the number of records to include in the fixture(s).'),
'short' => 'n',
- 'default' => 10
+ 'default' => 1
))->addOption('connection', array(
'help' => __d('cake_console', 'Which database configuration to use for baking.'),
'short' => 'c',
@@ -210,7 +210,7 @@ class FixtureTask extends BakeTask {
* @param string $model Name of model to bake.
* @param string $useTable Name of table to use.
* @param array $importOptions Options for public $import
- * @return string Baked fixture content
+ * @return string|null Baked fixture content, otherwise null.
*/
public function bake($model, $useTable = false, $importOptions = array()) {
App::uses('CakeSchema', 'Model');
@@ -242,8 +242,8 @@ class FixtureTask extends BakeTask {
$this->_Schema = new CakeSchema();
$data = $this->_Schema->read(array('models' => false, 'connection' => $this->connection));
if (!isset($data['tables'][$useTable])) {
- $this->error('Could not find your selected table ' . $useTable);
- return false;
+ $this->err("Warning: Could not find the '${useTable}' table for ${model}.");
+ return null;
}
$tableInfo = $data['tables'][$useTable];
@@ -316,7 +316,7 @@ class FixtureTask extends BakeTask {
* Generate String representation of Records
*
* @param array $tableInfo Table schema array
- * @param integer $recordCount
+ * @param int $recordCount The number of records to generate.
* @return array Array of records to use in the fixture.
*/
protected function _generateRecords($tableInfo, $recordCount = 1) {
@@ -340,7 +340,7 @@ class FixtureTask extends BakeTask {
isset($fieldInfo['length']) && $fieldInfo['length'] == 36
);
if ($isPrimaryUuid) {
- $insert = String::uuid();
+ $insert = CakeText::uuid();
} else {
$insert = "Lorem ipsum dolor sit amet";
if (!empty($fieldInfo['length'])) {
@@ -381,7 +381,7 @@ class FixtureTask extends BakeTask {
}
/**
- * Convert a $records array into a a string.
+ * Convert a $records array into a string.
*
* @param array $records Array of records to be converted to string
* @return string A string value of the $records array.
@@ -414,19 +414,26 @@ class FixtureTask extends BakeTask {
* @return array Array of records.
*/
protected function _getRecordsFromTable($modelName, $useTable = null) {
+ $modelObject = new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
if ($this->interactive) {
$condition = null;
$prompt = __d('cake_console', "Please provide a SQL fragment to use as conditions\nExample: WHERE 1=1");
while (!$condition) {
$condition = $this->in($prompt, null, 'WHERE 1=1');
}
+
+ $recordsFound = $modelObject->find('count', array(
+ 'conditions' => $condition,
+ 'recursive' => -1,
+ ));
+
$prompt = __d('cake_console', "How many records do you want to import?");
- $recordCount = $this->in($prompt, null, 10);
+ $recordCount = $this->in($prompt, null, ($recordsFound < 10 ) ? $recordsFound : 10);
} else {
$condition = 'WHERE 1=1';
$recordCount = (isset($this->params['count']) ? $this->params['count'] : 10);
}
- $modelObject = new Model(array('name' => $modelName, 'table' => $useTable, 'ds' => $this->connection));
+
$records = $modelObject->find('all', array(
'conditions' => $condition,
'recursive' => -1,
diff --git a/web/api/lib/Cake/Console/Command/Task/ModelTask.php b/web/api/lib/Cake/Console/Command/Task/ModelTask.php
index 128674b5b..2dc03a5c3 100644
--- a/web/api/lib/Cake/Console/Command/Task/ModelTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/ModelTask.php
@@ -161,8 +161,8 @@ class ModelTask extends BakeTask {
*
* @param array $options Array of options to use for the selections. indexes must start at 0
* @param string $prompt Prompt to use for options list.
- * @param integer $default The default option for the given prompt.
- * @return integer Result of user choice.
+ * @param int $default The default option for the given prompt.
+ * @return int Result of user choice.
*/
public function inOptions($options, $prompt = null, $default = null) {
$valid = false;
@@ -176,7 +176,7 @@ class ModelTask extends BakeTask {
$prompt = __d('cake_console', 'Make a selection from the choices above');
}
$choice = $this->in($prompt, null, $default);
- if (intval($choice) > 0 && intval($choice) <= $max) {
+ if ((int)$choice > 0 && (int)$choice <= $max) {
$valid = true;
}
}
@@ -186,7 +186,7 @@ class ModelTask extends BakeTask {
/**
* Handles interactive baking
*
- * @return boolean
+ * @return bool
*/
protected function _interactive() {
$this->hr();
@@ -342,7 +342,7 @@ class ModelTask extends BakeTask {
* Handles Generation and user interaction for creating validation.
*
* @param Model $model Model to have validations generated for.
- * @return array $validate Array of user selected validations.
+ * @return array validate Array of user selected validations.
*/
public function doValidation($model) {
if (!$model instanceof Model) {
@@ -383,6 +383,8 @@ class ModelTask extends BakeTask {
if (class_exists('Validation')) {
$options = get_class_methods('Validation');
}
+ $deprecatedOptions = array('notEmpty', 'between', 'ssn');
+ $options = array_diff($options, $deprecatedOptions);
sort($options);
$default = 1;
foreach ($options as $option) {
@@ -401,7 +403,7 @@ class ModelTask extends BakeTask {
*
* @param string $fieldName Name of field to be validated.
* @param array $metaData metadata for field
- * @param string $primaryKey
+ * @param string $primaryKey The primary key field.
* @return array Array of validation for the field.
*/
public function fieldValidation($fieldName, $metaData, $primaryKey = 'id') {
@@ -443,9 +445,9 @@ class ModelTask extends BakeTask {
} elseif ($metaData['type'] === 'string' && $metaData['length'] == 36) {
$guess = $methods['uuid'];
} elseif ($metaData['type'] === 'string') {
- $guess = $methods['notEmpty'];
+ $guess = $methods['notBlank'];
} elseif ($metaData['type'] === 'text') {
- $guess = $methods['notEmpty'];
+ $guess = $methods['notBlank'];
} elseif ($metaData['type'] === 'integer') {
$guess = $methods['numeric'];
} elseif ($metaData['type'] === 'float') {
@@ -460,6 +462,8 @@ class ModelTask extends BakeTask {
$guess = $methods['datetime'];
} elseif ($metaData['type'] === 'inet') {
$guess = $methods['ip'];
+ } elseif ($metaData['type'] === 'decimal') {
+ $guess = $methods['decimal'];
}
}
@@ -510,7 +514,7 @@ class ModelTask extends BakeTask {
/**
* Handles associations
*
- * @param Model $model
+ * @param Model $model The model object
* @return array Associations
*/
public function doAssociations($model) {
@@ -562,7 +566,7 @@ class ModelTask extends BakeTask {
/**
* Handles behaviors
*
- * @param Model $model
+ * @param Model $model The model object.
* @return array Behaviors
*/
public function doActsAs($model) {
@@ -632,13 +636,13 @@ class ModelTask extends BakeTask {
}
foreach ($tempFieldNames as $fieldName) {
$assoc = false;
- if ($fieldName != $model->primaryKey && $fieldName == $foreignKey) {
+ if ($fieldName !== $model->primaryKey && $fieldName === $foreignKey) {
$assoc = array(
'alias' => $tempOtherModel->name,
'className' => $tempOtherModel->name,
'foreignKey' => $fieldName
);
- } elseif ($otherTable == $model->table && $fieldName === 'parent_id') {
+ } elseif ($otherTable === $model->table && $fieldName === 'parent_id') {
$assoc = array(
'alias' => 'Child' . $model->name,
'className' => $model->name,
@@ -728,7 +732,7 @@ class ModelTask extends BakeTask {
while (strtolower($wannaDoMoreAssoc) === 'y') {
$assocs = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
$this->out(__d('cake_console', 'What is the association type?'));
- $assocType = intval($this->inOptions($assocs, __d('cake_console', 'Enter a number')));
+ $assocType = (int)$this->inOptions($assocs, __d('cake_console', 'Enter a number'));
$this->out(__d('cake_console', "For the following options be very careful to match your setup exactly.\n" .
"Any spelling mistakes will cause errors."));
@@ -765,7 +769,7 @@ class ModelTask extends BakeTask {
if (!empty($showKeys)) {
$this->out(__d('cake_console', 'A helpful List of possible keys'));
$foreignKey = $this->inOptions($showKeys, __d('cake_console', 'What is the foreignKey?'));
- $foreignKey = $showKeys[intval($foreignKey)];
+ $foreignKey = $showKeys[(int)$foreignKey];
}
if (!isset($foreignKey)) {
$foreignKey = $this->in(__d('cake_console', 'What is the foreignKey? Specify your own.'), null, $suggestedForeignKey);
@@ -812,7 +816,7 @@ class ModelTask extends BakeTask {
* Assembles and writes a Model file.
*
* @param string|object $name Model name or object
- * @param array|boolean $data if array and $name is not an object assume bake data, otherwise boolean.
+ * @param array|bool $data if array and $name is not an object assume bake data, otherwise boolean.
* @return string
*/
public function bake($name, $data = array()) {
@@ -926,7 +930,7 @@ class ModelTask extends BakeTask {
$tableIsGood = $this->in(__d('cake_console', 'Do you want to use this table?'), array('y', 'n'), 'y');
}
if (strtolower($tableIsGood) === 'n') {
- $useTable = $this->in(__d('cake_console', 'What is the name of the table?'));
+ $useTable = $this->in(__d('cake_console', 'What is the name of the table (without prefix)?'));
}
}
return $useTable;
@@ -985,14 +989,14 @@ class ModelTask extends BakeTask {
return $this->_stop();
}
- if (!$enteredModel || intval($enteredModel) > count($this->_modelNames)) {
+ if (!$enteredModel || (int)$enteredModel > count($this->_modelNames)) {
$this->err(__d('cake_console', "The model name you supplied was empty,\n" .
"or the number you selected was not an option. Please try again."));
$enteredModel = '';
}
}
- if (intval($enteredModel) > 0 && intval($enteredModel) <= count($this->_modelNames)) {
- return $this->_modelNames[intval($enteredModel) - 1];
+ if ((int)$enteredModel > 0 && (int)$enteredModel <= count($this->_modelNames)) {
+ return $this->_modelNames[(int)$enteredModel - 1];
}
return $enteredModel;
diff --git a/web/api/lib/Cake/Console/Command/Task/PluginTask.php b/web/api/lib/Cake/Console/Command/Task/PluginTask.php
index e37e437c3..7cd507942 100644
--- a/web/api/lib/Cake/Console/Command/Task/PluginTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/PluginTask.php
@@ -1,7 +1,5 @@
path . $plugin);
$directories = array(
'Config' . DS . 'Schema',
- 'Model' . DS . 'Behavior',
- 'Model' . DS . 'Datasource',
'Console' . DS . 'Command' . DS . 'Task',
+ 'Console' . DS . 'Templates',
'Controller' . DS . 'Component',
'Lib',
- 'View' . DS . 'Helper',
+ 'Locale' . DS . 'eng' . DS . 'LC_MESSAGES',
+ 'Model' . DS . 'Behavior',
+ 'Model' . DS . 'Datasource',
'Test' . DS . 'Case' . DS . 'Controller' . DS . 'Component',
- 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper',
+ 'Test' . DS . 'Case' . DS . 'Lib',
'Test' . DS . 'Case' . DS . 'Model' . DS . 'Behavior',
+ 'Test' . DS . 'Case' . DS . 'Model' . DS . 'Datasource',
+ 'Test' . DS . 'Case' . DS . 'View' . DS . 'Helper',
'Test' . DS . 'Fixture',
- 'Vendor',
- 'webroot'
+ 'View' . DS . 'Elements',
+ 'View' . DS . 'Helper',
+ 'View' . DS . 'Layouts',
+ 'webroot' . DS . 'css',
+ 'webroot' . DS . 'js',
+ 'webroot' . DS . 'img',
);
foreach ($directories as $directory) {
@@ -184,7 +189,7 @@ class PluginTask extends AppShell {
/**
* find and change $this->path to the user selection
*
- * @param array $pathOptions
+ * @param array $pathOptions The list of paths to look in.
* @return void
*/
public function findPath($pathOptions) {
@@ -203,7 +208,7 @@ class PluginTask extends AppShell {
}
$prompt = __d('cake_console', 'Choose a plugin path from the paths above.');
$choice = $this->in($prompt, null, 1);
- if (intval($choice) > 0 && intval($choice) <= $max) {
+ if ((int)$choice > 0 && (int)$choice <= $max) {
$valid = true;
}
}
diff --git a/web/api/lib/Cake/Console/Command/Task/ProjectTask.php b/web/api/lib/Cake/Console/Command/Task/ProjectTask.php
index c3225a99f..df1ab19db 100644
--- a/web/api/lib/Cake/Console/Command/Task/ProjectTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/ProjectTask.php
@@ -18,7 +18,7 @@
App::uses('AppShell', 'Console/Command');
App::uses('File', 'Utility');
App::uses('Folder', 'Utility');
-App::uses('String', 'Utility');
+App::uses('CakeText', 'Utility');
App::uses('Security', 'Utility');
/**
@@ -142,7 +142,7 @@ class ProjectTask extends AppShell {
/**
* Checks PHP's include_path for CakePHP.
*
- * @return boolean Indicates whether or not CakePHP exists on include_path
+ * @return bool Indicates whether or not CakePHP exists on include_path
*/
public function cakeOnIncludePath() {
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
@@ -212,7 +212,7 @@ class ProjectTask extends AppShell {
}
foreach ($Folder->messages() as $message) {
- $this->out(String::wrap(' * ' . $message), 1, Shell::VERBOSE);
+ $this->out(CakeText::wrap(' * ' . $message), 1, Shell::VERBOSE);
}
return true;
@@ -231,14 +231,14 @@ class ProjectTask extends AppShell {
* and points app/console/cake.php to the right place
*
* @param string $path Project path.
- * @return boolean success
+ * @return bool success
*/
public function consolePath($path) {
$File = new File($path . 'Console' . DS . 'cake.php');
$contents = $File->read();
if (preg_match('/(__CAKE_PATH__)/', $contents, $match)) {
- $root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " \$ds . '" : "'";
- $replacement = $root . str_replace(DS, "' . \$ds . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "'";
+ $root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " DS . '" : "'";
+ $replacement = $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "'";
$result = str_replace($match[0], $replacement, $contents);
if ($File->write($result)) {
return true;
@@ -252,7 +252,7 @@ class ProjectTask extends AppShell {
* Generates and writes 'Security.salt'
*
* @param string $path Project path
- * @return boolean Success
+ * @return bool Success
*/
public function securitySalt($path) {
$File = new File($path . 'Config' . DS . 'core.php');
@@ -272,7 +272,7 @@ class ProjectTask extends AppShell {
* Generates and writes 'Security.cipherSeed'
*
* @param string $path Project path
- * @return boolean Success
+ * @return bool Success
*/
public function securityCipherSeed($path) {
$File = new File($path . 'Config' . DS . 'core.php');
@@ -293,7 +293,7 @@ class ProjectTask extends AppShell {
* Writes cache prefix using app's name
*
* @param string $dir Path to project
- * @return boolean Success
+ * @return bool Success
*/
public function cachePrefix($dir) {
$app = basename($dir);
@@ -310,8 +310,8 @@ class ProjectTask extends AppShell {
* Generates and writes CAKE_CORE_INCLUDE_PATH
*
* @param string $path Project path
- * @param boolean $hardCode Whether or not define calls should be hardcoded.
- * @return boolean Success
+ * @param bool $hardCode Whether or not define calls should be hardcoded.
+ * @return bool Success
*/
public function corePath($path, $hardCode = true) {
if (dirname($path) !== CAKE_CORE_INCLUDE_PATH) {
@@ -331,8 +331,8 @@ class ProjectTask extends AppShell {
* Replaces the __CAKE_PATH__ placeholder in the template files.
*
* @param string $filename The filename to operate on.
- * @param boolean $hardCode Whether or not the define should be uncommented.
- * @return boolean Success
+ * @param bool $hardCode Whether or not the define should be uncommented.
+ * @return bool Success
*/
protected function _replaceCorePath($filename, $hardCode) {
$contents = file_get_contents($filename);
@@ -340,6 +340,11 @@ class ProjectTask extends AppShell {
$root = strpos(CAKE_CORE_INCLUDE_PATH, '/') === 0 ? " DS . '" : "'";
$corePath = $root . str_replace(DS, "' . DS . '", trim(CAKE_CORE_INCLUDE_PATH, DS)) . "'";
+ $composer = ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib';
+ if (file_exists($composer)) {
+ $corePath = " ROOT . DS . APP_DIR . DS . 'Vendor' . DS . 'cakephp' . DS . 'cakephp' . DS . 'lib'";
+ }
+
$result = str_replace('__CAKE_PATH__', $corePath, $contents, $count);
if ($hardCode) {
$result = str_replace('//define(\'CAKE_CORE', 'define(\'CAKE_CORE', $result);
@@ -354,7 +359,7 @@ class ProjectTask extends AppShell {
* Enables Configure::read('Routing.prefixes') in /app/Config/core.php
*
* @param string $name Name to use as admin routing
- * @return boolean Success
+ * @return bool Success
*/
public function cakeAdmin($name) {
$path = (empty($this->configPath)) ? APP . 'Config' . DS : $this->configPath;
diff --git a/web/api/lib/Cake/Console/Command/Task/TestTask.php b/web/api/lib/Cake/Console/Command/Task/TestTask.php
index f85d57cd0..a147951c2 100644
--- a/web/api/lib/Cake/Console/Command/Task/TestTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/TestTask.php
@@ -102,8 +102,8 @@ class TestTask extends BakeTask {
/**
* Handles interactive baking
*
- * @param string $type
- * @return string|boolean
+ * @param string $type The type of object to bake a test for.
+ * @return string|bool
*/
protected function _interactive($type = null) {
$this->interactive = true;
@@ -129,7 +129,7 @@ class TestTask extends BakeTask {
*
* @param string $type Type of object to bake test case for ie. Model, Controller
* @param string $className the 'cake name' for the class ie. Posts for the PostsController
- * @return string|boolean
+ * @return string|bool
*/
public function bake($type, $className) {
$plugin = null;
@@ -242,7 +242,7 @@ class TestTask extends BakeTask {
* Currently only model, and controller are supported
*
* @param string $type The Type of object you are generating tests for eg. controller
- * @return boolean
+ * @return bool
*/
public function typeCanDetectFixtures($type) {
$type = strtolower($type);
@@ -254,7 +254,7 @@ class TestTask extends BakeTask {
*
* @param string $package The package of object you are generating tests for eg. controller
* @param string $class the Classname of the class the test is being generated for.
- * @return boolean
+ * @return bool
*/
public function isLoadableClass($package, $class) {
App::uses($class, $package);
@@ -302,7 +302,7 @@ class TestTask extends BakeTask {
$position = strpos($class, $type);
- if ($position !== false && strlen($class) - $position == strlen($type)) {
+ if ($position !== false && (strlen($class) - $position) === strlen($type)) {
return $class;
}
return $class . $type;
@@ -466,7 +466,7 @@ class TestTask extends BakeTask {
* Controllers require a mock class.
*
* @param string $type The type of object tests are being generated for eg. controller.
- * @return boolean
+ * @return bool
*/
public function hasMockClass($type) {
$type = strtolower($type);
diff --git a/web/api/lib/Cake/Console/Command/Task/ViewTask.php b/web/api/lib/Cake/Console/Command/Task/ViewTask.php
index 8fc387aba..06ecf0013 100644
--- a/web/api/lib/Cake/Console/Command/Task/ViewTask.php
+++ b/web/api/lib/Cake/Console/Command/Task/ViewTask.php
@@ -89,7 +89,7 @@ class ViewTask extends BakeTask {
$this->_interactive();
}
if (empty($this->args[0])) {
- return;
+ return null;
}
if (!isset($this->connection)) {
$this->connection = 'default';
@@ -151,7 +151,7 @@ class ViewTask extends BakeTask {
unset($methods[$i]);
}
}
- if ($method[0] === '_' || $method == strtolower($this->controllerName . 'Controller')) {
+ if ($method[0] === '_' || $method === strtolower($this->controllerName . 'Controller')) {
unset($methods[$i]);
}
}
@@ -206,7 +206,7 @@ class ViewTask extends BakeTask {
$this->Controller->connection = $this->connection;
$this->controllerName = $this->Controller->getName();
- $prompt = __d('cake_console', "Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if it exist.", $this->controllerName);
+ $prompt = __d('cake_console', "Would you like bake to build your views interactively?\nWarning: Choosing no will overwrite %s views if they exist.", $this->controllerName);
$interactive = $this->in($prompt, array('y', 'n'), 'n');
if (strtolower($interactive) === 'n') {
@@ -248,7 +248,7 @@ class ViewTask extends BakeTask {
* 'singularHumanName', 'pluralHumanName', 'fields', 'foreignKeys',
* 'belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'
*
- * @return array Returns an variables to be made available to a view template
+ * @return array Returns a variables to be made available to a view template
*/
protected function _loadController() {
if (!$this->controllerName) {
@@ -298,7 +298,7 @@ class ViewTask extends BakeTask {
* Bake a view file for each of the supplied actions
*
* @param array $actions Array of actions to make files for.
- * @param array $vars
+ * @param array $vars The template variables.
* @return void
*/
public function bakeActions($actions, $vars) {
@@ -342,7 +342,7 @@ class ViewTask extends BakeTask {
*
* @param string $action Action to bake
* @param string $content Content to write
- * @return boolean Success
+ * @return bool Success
*/
public function bake($action, $content = '') {
if ($content === true) {
@@ -454,8 +454,8 @@ class ViewTask extends BakeTask {
/**
* Returns associations for controllers models.
*
- * @param Model $model
- * @return array $associations
+ * @param Model $model The Model instance.
+ * @return array associations
*/
protected function _associations(Model $model) {
$keys = array('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany');
diff --git a/web/api/lib/Cake/Console/Command/TestShell.php b/web/api/lib/Cake/Console/Command/TestShell.php
index bd7e9d277..4dfacfdfc 100644
--- a/web/api/lib/Cake/Console/Command/TestShell.php
+++ b/web/api/lib/Cake/Console/Command/TestShell.php
@@ -179,11 +179,11 @@ class TestShell extends Shell {
/**
* Parse the CLI options into an array CakeTestDispatcher can use.
*
- * @return array Array of params for CakeTestDispatcher
+ * @return array|null Array of params for CakeTestDispatcher or null.
*/
protected function _parseArgs() {
if (empty($this->args)) {
- return;
+ return null;
}
$params = array(
'core' => false,
@@ -222,6 +222,7 @@ class TestShell extends Shell {
$options = array();
$params = $this->params;
unset($params['help']);
+ unset($params['quiet']);
if (!empty($params['no-colors'])) {
unset($params['no-colors'], $params['colors']);
@@ -334,9 +335,9 @@ class TestShell extends Shell {
/**
* Find the test case for the passed file. The file could itself be a test.
*
- * @param string $file
- * @param string $category
- * @param boolean $throwOnMissingFile
+ * @param string $file The file to map.
+ * @param string $category The test file category.
+ * @param bool $throwOnMissingFile Whether or not to throw an exception.
* @return array array(type, case)
* @throws Exception
*/
@@ -411,7 +412,7 @@ class TestShell extends Shell {
/**
* For the given file, what category of test is it? returns app, core or the name of the plugin
*
- * @param string $file
+ * @param string $file The file to map.
* @return string
*/
protected function _mapFileToCategory($file) {
diff --git a/web/api/lib/Cake/Console/Command/UpgradeShell.php b/web/api/lib/Cake/Console/Command/UpgradeShell.php
index 27d7561fe..12b3fbc9d 100644
--- a/web/api/lib/Cake/Console/Command/UpgradeShell.php
+++ b/web/api/lib/Cake/Console/Command/UpgradeShell.php
@@ -18,6 +18,7 @@
App::uses('AppShell', 'Console/Command');
App::uses('Folder', 'Utility');
+App::uses('CakePlugin', 'Core');
/**
* A shell class to help developers upgrade applications to CakePHP 2.0
@@ -102,7 +103,7 @@ class UpgradeShell extends AppShell {
public function tests() {
$this->_paths = array(APP . 'tests' . DS);
if (!empty($this->params['plugin'])) {
- $this->_paths = array(App::pluginPath($this->params['plugin']) . 'tests' . DS);
+ $this->_paths = array(CakePlugin::path($this->params['plugin']) . 'tests' . DS);
}
$patterns = array(
array(
@@ -128,7 +129,7 @@ class UpgradeShell extends AppShell {
$cwd = getcwd();
if (!empty($this->params['plugin'])) {
- chdir(App::pluginPath($this->params['plugin']));
+ chdir(CakePlugin::path($this->params['plugin']));
}
if (is_dir('plugins')) {
@@ -215,7 +216,7 @@ class UpgradeShell extends AppShell {
$this->_paths = array_diff(App::path('views'), App::core('views'));
if (!empty($this->params['plugin'])) {
- $this->_paths = array(App::pluginPath($this->params['plugin']) . 'views' . DS);
+ $this->_paths = array(CakePlugin::path($this->params['plugin']) . 'views' . DS);
}
$patterns = array();
@@ -229,7 +230,7 @@ class UpgradeShell extends AppShell {
CakePlugin::load($plugin);
$pluginHelpers = array_merge(
$pluginHelpers,
- App::objects('helper', App::pluginPath($plugin) . DS . 'views' . DS . 'helpers' . DS, false)
+ App::objects('helper', CakePlugin::path($plugin) . DS . 'views' . DS . 'helpers' . DS, false)
);
}
$helpers = array_merge($pluginHelpers, $helpers);
@@ -260,7 +261,7 @@ class UpgradeShell extends AppShell {
APP
);
if (!empty($this->params['plugin'])) {
- $this->_paths = array(App::pluginPath($this->params['plugin']));
+ $this->_paths = array(CakePlugin::path($this->params['plugin']));
}
$patterns = array(
@@ -299,7 +300,7 @@ class UpgradeShell extends AppShell {
APP
);
if (!empty($this->params['plugin'])) {
- $this->_paths = array(App::pluginPath($this->params['plugin']));
+ $this->_paths = array(CakePlugin::path($this->params['plugin']));
}
$patterns = array(
array(
@@ -354,7 +355,7 @@ class UpgradeShell extends AppShell {
$this->_paths = array_merge($views, $controllers, $components);
if (!empty($this->params['plugin'])) {
- $pluginPath = App::pluginPath($this->params['plugin']);
+ $pluginPath = CakePlugin::path($this->params['plugin']);
$this->_paths = array(
$pluginPath . 'controllers' . DS,
$pluginPath . 'controllers' . DS . 'components' . DS,
@@ -411,7 +412,7 @@ class UpgradeShell extends AppShell {
APP
);
if (!empty($this->params['plugin'])) {
- $this->_paths = array(App::pluginPath($this->params['plugin']));
+ $this->_paths = array(CakePlugin::path($this->params['plugin']));
}
$patterns = array(
array(
@@ -433,7 +434,7 @@ class UpgradeShell extends AppShell {
APP
);
if (!empty($this->params['plugin'])) {
- $this->_paths = array(App::pluginPath($this->params['plugin']));
+ $this->_paths = array(CakePlugin::path($this->params['plugin']));
}
$patterns = array(
array(
@@ -554,6 +555,7 @@ class UpgradeShell extends AppShell {
/**
* Replace cakeError with built-in exceptions.
* NOTE: this ignores calls where you've passed your own secondary parameters to cakeError().
+ *
* @return void
*/
public function exceptions() {
@@ -563,7 +565,7 @@ class UpgradeShell extends AppShell {
$this->_paths = array_merge($controllers, $components);
if (!empty($this->params['plugin'])) {
- $pluginPath = App::pluginPath($this->params['plugin']);
+ $pluginPath = CakePlugin::path($this->params['plugin']);
$this->_paths = array(
$pluginPath . 'controllers' . DS,
$pluginPath . 'controllers' . DS . 'components' . DS,
@@ -609,7 +611,7 @@ class UpgradeShell extends AppShell {
$new = 'View' . DS . Inflector::camelize($old);
$old = 'View' . DS . $old;
- if ($new == $old) {
+ if ($new === $old) {
continue;
}
@@ -661,7 +663,7 @@ class UpgradeShell extends AppShell {
* Find all php files in the folder (honoring recursive) and determine where CakePHP expects the file to be
* If the file is not exactly where CakePHP expects it - move it.
*
- * @param string $path
+ * @param string $path The path to move files in.
* @param array $options array(recursive, checkFolder)
* @return void
*/
@@ -763,7 +765,7 @@ class UpgradeShell extends AppShell {
/**
* Searches the paths and finds files based on extension.
*
- * @param string $extensions
+ * @param string $extensions The extensions to include. Defaults to none.
* @return void
*/
protected function _findFiles($extensions = '') {
@@ -839,8 +841,9 @@ class UpgradeShell extends AppShell {
);
$parser->description(
- __d('cake_console', "A shell to help automate upgrading from CakePHP 1.3 to 2.0. \n" .
- "Be sure to have a backup of your application before running these commands."
+ __d('cake_console', "A tool to help automate upgrading an application or plugin " .
+ "from CakePHP 1.3 to 2.0. Be sure to have a backup of your application before " .
+ "running these commands."
))->addSubcommand('all', array(
'help' => __d('cake_console', 'Run all upgrade commands.'),
'parser' => $subcommandParser
diff --git a/web/api/lib/Cake/Console/ConsoleErrorHandler.php b/web/api/lib/Cake/Console/ConsoleErrorHandler.php
index aa5c464f9..7cbb2df15 100644
--- a/web/api/lib/Cake/Console/ConsoleErrorHandler.php
+++ b/web/api/lib/Cake/Console/ConsoleErrorHandler.php
@@ -40,35 +40,37 @@ class ConsoleErrorHandler {
* @return ConsoleOutput
*/
public static function getStderr() {
- if (empty(self::$stderr)) {
- self::$stderr = new ConsoleOutput('php://stderr');
+ if (empty(static::$stderr)) {
+ static::$stderr = new ConsoleOutput('php://stderr');
}
- return self::$stderr;
+ return static::$stderr;
}
/**
- * Handle a exception in the console environment. Prints a message to stderr.
+ * Handle an exception in the console environment. Prints a message to stderr.
*
- * @param Exception $exception The exception to handle
+ * @param Exception|ParserError $exception The exception to handle
* @return void
*/
- public function handleException(Exception $exception) {
- $stderr = self::getStderr();
+ public function handleException($exception) {
+ $stderr = static::getStderr();
$stderr->write(__d('cake_console', "Error: %s\n%s",
$exception->getMessage(),
$exception->getTraceAsString()
));
- return $this->_stop($exception->getCode() ? $exception->getCode() : 1);
+ $code = $exception->getCode();
+ $code = ($code && is_int($code)) ? $code : 1;
+ return $this->_stop($code);
}
/**
* Handle errors in the console environment. Writes errors to stderr,
* and logs messages if Configure::read('debug') is 0.
*
- * @param integer $code Error code
+ * @param int $code Error code
* @param string $description Description of the error.
* @param string $file The file the error occurred in.
- * @param integer $line The line the error occurred on.
+ * @param int $line The line the error occurred on.
* @param array $context The backtrace of the error.
* @return void
*/
@@ -76,7 +78,7 @@ class ConsoleErrorHandler {
if (error_reporting() === 0) {
return;
}
- $stderr = self::getStderr();
+ $stderr = static::getStderr();
list($name, $log) = ErrorHandler::mapErrorCode($code);
$message = __d('cake_console', '%s in [%s, line %s]', $description, $file, $line);
$stderr->write(__d('cake_console', "%s Error: %s\n", $name, $message));
@@ -93,7 +95,7 @@ class ConsoleErrorHandler {
/**
* Wrapper for exit(), used for testing.
*
- * @param integer $code The exit code.
+ * @param int $code The exit code.
* @return void
*/
protected function _stop($code = 0) {
diff --git a/web/api/lib/Cake/Console/ConsoleInput.php b/web/api/lib/Cake/Console/ConsoleInput.php
index e8af58bb0..551635b82 100644
--- a/web/api/lib/Cake/Console/ConsoleInput.php
+++ b/web/api/lib/Cake/Console/ConsoleInput.php
@@ -37,7 +37,7 @@ class ConsoleInput {
* 2. Handle we are attached to must be stdin.
* Allows rich editing with arrow keys and history when inputting a string.
*
- * @var boolean
+ * @var bool
*/
protected $_canReadline;
@@ -47,7 +47,7 @@ class ConsoleInput {
* @param string $handle The location of the stream to use as input.
*/
public function __construct($handle = 'php://stdin') {
- $this->_canReadline = extension_loaded('readline') && $handle == 'php://stdin' ? true : false;
+ $this->_canReadline = extension_loaded('readline') && $handle === 'php://stdin' ? true : false;
$this->_input = fopen($handle, 'r');
}
@@ -70,8 +70,8 @@ class ConsoleInput {
/**
* Checks if data is available on the stream
*
- * @param integer $timeout An optional time to wait for data
- * @return boolean True for data available, false otherwise
+ * @param int $timeout An optional time to wait for data
+ * @return bool True for data available, false otherwise
*/
public function dataAvailable($timeout = 0) {
$readFds = array($this->_input);
diff --git a/web/api/lib/Cake/Console/ConsoleInputArgument.php b/web/api/lib/Cake/Console/ConsoleInputArgument.php
index 7380893bf..08dbc21e9 100644
--- a/web/api/lib/Cake/Console/ConsoleInputArgument.php
+++ b/web/api/lib/Cake/Console/ConsoleInputArgument.php
@@ -41,7 +41,7 @@ class ConsoleInputArgument {
/**
* Is this option required?
*
- * @var boolean
+ * @var bool
*/
protected $_required;
@@ -57,7 +57,7 @@ class ConsoleInputArgument {
*
* @param string|array $name The long name of the option, or an array with all the properties.
* @param string $help The help text for this option
- * @param boolean $required Whether this argument is required. Missing required args will trigger exceptions
+ * @param bool $required Whether this argument is required. Missing required args will trigger exceptions
* @param array $choices Valid choices for this option.
*/
public function __construct($name, $help = '', $required = false, $choices = array()) {
@@ -85,7 +85,7 @@ class ConsoleInputArgument {
/**
* Generate the help for this argument.
*
- * @param integer $width The width to make the name of the option.
+ * @param int $width The width to make the name of the option.
* @return string
*/
public function help($width = 0) {
@@ -123,7 +123,7 @@ class ConsoleInputArgument {
/**
* Check if this argument is a required argument
*
- * @return boolean
+ * @return bool
*/
public function isRequired() {
return (bool)$this->_required;
@@ -132,8 +132,8 @@ class ConsoleInputArgument {
/**
* Check that $value is a valid choice for this argument.
*
- * @param string $value
- * @return boolean
+ * @param string $value The choice to validate.
+ * @return bool
* @throws ConsoleException
*/
public function validChoice($value) {
diff --git a/web/api/lib/Cake/Console/ConsoleInputOption.php b/web/api/lib/Cake/Console/ConsoleInputOption.php
index 4d68c9f9e..3a4b7a1c9 100644
--- a/web/api/lib/Cake/Console/ConsoleInputOption.php
+++ b/web/api/lib/Cake/Console/ConsoleInputOption.php
@@ -48,7 +48,7 @@ class ConsoleInputOption {
/**
* Is the option a boolean option. Boolean options do not consume a parameter.
*
- * @var boolean
+ * @var bool
*/
protected $_boolean;
@@ -72,7 +72,7 @@ class ConsoleInputOption {
* @param string|array $name The long name of the option, or an array with all the properties.
* @param string $short The short alias for this option
* @param string $help The help text for this option
- * @param boolean $boolean Whether this option is a boolean option. Boolean options don't consume extra tokens
+ * @param bool $boolean Whether this option is a boolean option. Boolean options don't consume extra tokens
* @param string $default The default value for this option.
* @param array $choices Valid choices for this option.
* @throws ConsoleException
@@ -118,7 +118,7 @@ class ConsoleInputOption {
/**
* Generate the help for this this option.
*
- * @param integer $width The width to make the name of the option.
+ * @param int $width The width to make the name of the option.
* @return string
*/
public function help($width = 0) {
@@ -168,7 +168,7 @@ class ConsoleInputOption {
/**
* Check if this option is a boolean option
*
- * @return boolean
+ * @return bool
*/
public function isBoolean() {
return (bool)$this->_boolean;
@@ -177,8 +177,8 @@ class ConsoleInputOption {
/**
* Check that a value is a valid choice for this option.
*
- * @param string $value
- * @return boolean
+ * @param string $value The choice to validate.
+ * @return bool
* @throws ConsoleException
*/
public function validChoice($value) {
diff --git a/web/api/lib/Cake/Console/ConsoleInputSubcommand.php b/web/api/lib/Cake/Console/ConsoleInputSubcommand.php
index 2ddcb955b..65c10db06 100644
--- a/web/api/lib/Cake/Console/ConsoleInputSubcommand.php
+++ b/web/api/lib/Cake/Console/ConsoleInputSubcommand.php
@@ -81,7 +81,7 @@ class ConsoleInputSubcommand {
/**
* Generate the help for this this subcommand.
*
- * @param integer $width The width to make the name of the subcommand.
+ * @param int $width The width to make the name of the subcommand.
* @return string
*/
public function help($width = 0) {
diff --git a/web/api/lib/Cake/Console/ConsoleOptionParser.php b/web/api/lib/Cake/Console/ConsoleOptionParser.php
index 589c27949..f54c5460d 100644
--- a/web/api/lib/Cake/Console/ConsoleOptionParser.php
+++ b/web/api/lib/Cake/Console/ConsoleOptionParser.php
@@ -136,7 +136,7 @@ class ConsoleOptionParser {
* Construct an OptionParser so you can define its behavior
*
* @param string $command The command name this parser is for. The command name is used for generating help.
- * @param boolean $defaultOptions Whether you want the verbose and quiet options set. Setting
+ * @param bool $defaultOptions Whether you want the verbose and quiet options set. Setting
* this to false will prevent the addition of `--verbose` & `--quiet` options.
*/
public function __construct($command = null, $defaultOptions = true) {
@@ -165,7 +165,7 @@ class ConsoleOptionParser {
* Static factory method for creating new OptionParsers so you can chain methods off of them.
*
* @param string $command The command name this parser is for. The command name is used for generating help.
- * @param boolean $defaultOptions Whether you want the verbose and quiet options set.
+ * @param bool $defaultOptions Whether you want the verbose and quiet options set.
* @return ConsoleOptionParser
*/
public static function create($command, $defaultOptions = true) {
@@ -175,7 +175,7 @@ class ConsoleOptionParser {
/**
* Build a parser from an array. Uses an array like
*
- * {{{
+ * ```
* $spec = array(
* 'description' => 'text',
* 'epilog' => 'text',
@@ -189,7 +189,7 @@ class ConsoleOptionParser {
* // list of subcommands to add.
* )
* );
- * }}}
+ * ```
*
* @param array $spec The spec to build the OptionParser with.
* @return ConsoleOptionParser
@@ -218,7 +218,7 @@ class ConsoleOptionParser {
* Get or set the command name for shell/task.
*
* @param string $text The text to set, or null if you want to read
- * @return mixed If reading, the value of the command. If setting $this will be returned
+ * @return string|self If reading, the value of the command. If setting $this will be returned.
*/
public function command($text = null) {
if ($text !== null) {
@@ -233,7 +233,7 @@ class ConsoleOptionParser {
*
* @param string|array $text The text to set, or null if you want to read. If an array the
* text will be imploded with "\n"
- * @return mixed If reading, the value of the description. If setting $this will be returned
+ * @return string|self If reading, the value of the description. If setting $this will be returned.
*/
public function description($text = null) {
if ($text !== null) {
@@ -251,7 +251,7 @@ class ConsoleOptionParser {
* the options and arguments listing when help is generated.
*
* @param string|array $text Text when setting or null when reading. If an array the text will be imploded with "\n"
- * @return mixed If reading, the value of the epilog. If setting $this will be returned.
+ * @return string|self If reading, the value of the epilog. If setting $this will be returned.
*/
public function epilog($text = null) {
if ($text !== null) {
@@ -284,7 +284,7 @@ class ConsoleOptionParser {
* @param ConsoleInputOption|string $name The long name you want to the value to be parsed out as when options are parsed.
* Will also accept an instance of ConsoleInputOption
* @param array $options An array of parameters that define the behavior of the option
- * @return ConsoleOptionParser $this.
+ * @return self
*/
public function addOption($name, $options = array()) {
if (is_object($name) && $name instanceof ConsoleInputOption) {
@@ -324,7 +324,7 @@ class ConsoleOptionParser {
*
* @param ConsoleInputArgument|string $name The name of the argument. Will also accept an instance of ConsoleInputArgument
* @param array $params Parameters for the argument, see above.
- * @return ConsoleOptionParser $this.
+ * @return self
*/
public function addArgument($name, $params = array()) {
if (is_object($name) && $name instanceof ConsoleInputArgument) {
@@ -354,7 +354,7 @@ class ConsoleOptionParser {
*
* @param array $args Array of arguments to add.
* @see ConsoleOptionParser::addArgument()
- * @return ConsoleOptionParser $this
+ * @return self
*/
public function addArguments(array $args) {
foreach ($args as $name => $params) {
@@ -369,7 +369,7 @@ class ConsoleOptionParser {
*
* @param array $options Array of options to add.
* @see ConsoleOptionParser::addOption()
- * @return ConsoleOptionParser $this
+ * @return self
*/
public function addOptions(array $options) {
foreach ($options as $name => $params) {
@@ -391,7 +391,7 @@ class ConsoleOptionParser {
*
* @param ConsoleInputSubcommand|string $name Name of the subcommand. Will also accept an instance of ConsoleInputSubcommand
* @param array $options Array of params, see above.
- * @return ConsoleOptionParser $this.
+ * @return self
*/
public function addSubcommand($name, $options = array()) {
if (is_object($name) && $name instanceof ConsoleInputSubcommand) {
@@ -410,11 +410,22 @@ class ConsoleOptionParser {
return $this;
}
+/**
+ * Remove a subcommand from the option parser.
+ *
+ * @param string $name The subcommand name to remove.
+ * @return self
+ */
+ public function removeSubcommand($name) {
+ unset($this->_subcommands[$name]);
+ return $this;
+ }
+
/**
* Add multiple subcommands at once.
*
* @param array $commands Array of subcommands.
- * @return ConsoleOptionParser $this
+ * @return self
*/
public function addSubcommands(array $commands) {
foreach ($commands as $name => $params) {
@@ -458,7 +469,7 @@ class ConsoleOptionParser {
* @param array $argv Array of args (argv) to parse.
* @param string $command The subcommand to use. If this parameter is a subcommand, that has a parser,
* That parser will be used to parse $argv instead.
- * @return Array array($params, $args)
+ * @return array array($params, $args)
* @throws ConsoleException When an invalid parameter is encountered.
*/
public function parse($argv, $command = null) {
@@ -506,12 +517,11 @@ class ConsoleOptionParser {
* @param string $subcommand If present and a valid subcommand that has a linked parser.
* That subcommands help will be shown instead.
* @param string $format Define the output format, can be text or xml
- * @param integer $width The width to format user content to. Defaults to 72
+ * @param int $width The width to format user content to. Defaults to 72
* @return string Generated help.
*/
public function help($subcommand = null, $format = 'text', $width = 72) {
- if (
- isset($this->_subcommands[$subcommand]) &&
+ if (isset($this->_subcommands[$subcommand]) &&
$this->_subcommands[$subcommand]->parser() instanceof self
) {
$subparser = $this->_subcommands[$subcommand]->parser();
@@ -597,13 +607,14 @@ class ConsoleOptionParser {
$params[$name] = $value;
return $params;
}
+ return array();
}
/**
* Check to see if $name has an option (short/long) defined for it.
*
* @param string $name The name of the option.
- * @return boolean
+ * @return bool
*/
protected function _optionExists($name) {
if (substr($name, 0, 2) === '--') {
diff --git a/web/api/lib/Cake/Console/ConsoleOutput.php b/web/api/lib/Cake/Console/ConsoleOutput.php
index fa021b565..ec6fb3941 100644
--- a/web/api/lib/Cake/Console/ConsoleOutput.php
+++ b/web/api/lib/Cake/Console/ConsoleOutput.php
@@ -47,21 +47,21 @@ class ConsoleOutput {
/**
* Raw output constant - no modification of output text.
*
- * @var integer
+ * @var int
*/
const RAW = 0;
/**
* Plain output - tags will be stripped.
*
- * @var integer
+ * @var int
*/
const PLAIN = 1;
/**
* Color output - Convert known tags in to ANSI color escape codes.
*
- * @var integer
+ * @var int
*/
const COLOR = 2;
@@ -79,10 +79,18 @@ class ConsoleOutput {
*/
protected $_output;
+/**
+ * The number of bytes last written to the output stream
+ * used when overwriting the previous message.
+ *
+ * @var int
+ */
+ protected $_lastWritten = 0;
+
/**
* The current output type. Manipulated with ConsoleOutput::outputAs();
*
- * @var integer
+ * @var int
*/
protected $_outputAs = self::COLOR;
@@ -153,16 +161,19 @@ class ConsoleOutput {
/**
* Construct the output object.
*
- * Checks for a pretty console environment. Ansicon allows pretty consoles
- * on windows, and is supported.
+ * Checks for a pretty console environment. Ansicon and ConEmu allows
+ * pretty consoles on Windows, and is supported.
*
* @param string $stream The identifier of the stream to write output to.
*/
public function __construct($stream = 'php://stdout') {
$this->_output = fopen($stream, 'w');
- if (DS === '\\' && !(bool)env('ANSICON')) {
- $this->_outputAs = self::PLAIN;
+ if ((DS === '\\' && !(bool)env('ANSICON') && env('ConEmuANSI') !== 'ON') ||
+ $stream === 'php://output' ||
+ (function_exists('posix_isatty') && !posix_isatty($this->_output))
+ ) {
+ $this->_outputAs = static::PLAIN;
}
}
@@ -170,15 +181,44 @@ class ConsoleOutput {
* Outputs a single or multiple messages to stdout. If no parameters
* are passed, outputs just a newline.
*
- * @param string|array $message A string or a an array of strings to output
- * @param integer $newlines Number of newlines to append
- * @return integer Returns the number of bytes returned from writing to stdout.
+ * @param string|array $message A string or an array of strings to output
+ * @param int $newlines Number of newlines to append
+ * @return int Returns the number of bytes returned from writing to stdout.
*/
public function write($message, $newlines = 1) {
if (is_array($message)) {
- $message = implode(self::LF, $message);
+ $message = implode(static::LF, $message);
+ }
+ return $this->_write($this->styleText($message . str_repeat(static::LF, $newlines)));
+ }
+
+/**
+ * Overwrite some already output text.
+ *
+ * Useful for building progress bars, or when you want to replace
+ * text already output to the screen with new text.
+ *
+ * **Warning** You cannot overwrite text that contains newlines.
+ *
+ * @param array|string $message The message to output.
+ * @param int $newlines Number of newlines to append.
+ * @param int|null $size The number of bytes to overwrite. Defaults to the
+ * length of the last message output.
+ * @return void
+ */
+ public function overwrite($message, $newlines = 1, $size = null) {
+ $size = $size ?: $this->_lastWritten;
+ // Output backspaces.
+ $this->write(str_repeat("\x08", $size), 0);
+ $newBytes = $this->write($message, 0);
+ // Fill any remaining bytes with spaces.
+ $fill = $size - $newBytes;
+ if ($fill > 0) {
+ $this->write(str_repeat(' ', $fill), 0);
+ }
+ if ($newlines) {
+ $this->write("", $newlines);
}
- return $this->_write($this->styleText($message . str_repeat(self::LF, $newlines)));
}
/**
@@ -188,11 +228,11 @@ class ConsoleOutput {
* @return string String with color codes added.
*/
public function styleText($text) {
- if ($this->_outputAs == self::RAW) {
+ if ($this->_outputAs == static::RAW) {
return $text;
}
- if ($this->_outputAs == self::PLAIN) {
- $tags = implode('|', array_keys(self::$_styles));
+ if ($this->_outputAs == static::PLAIN) {
+ $tags = implode('|', array_keys(static::$_styles));
return preg_replace('#?(?:' . $tags . ')>#', '', $text);
}
return preg_replace_callback(
@@ -203,7 +243,7 @@ class ConsoleOutput {
/**
* Replace tags with color codes.
*
- * @param array $matches.
+ * @param array $matches An array of matches to replace.
* @return string
*/
protected function _replaceTags($matches) {
@@ -213,16 +253,16 @@ class ConsoleOutput {
}
$styleInfo = array();
- if (!empty($style['text']) && isset(self::$_foregroundColors[$style['text']])) {
- $styleInfo[] = self::$_foregroundColors[$style['text']];
+ if (!empty($style['text']) && isset(static::$_foregroundColors[$style['text']])) {
+ $styleInfo[] = static::$_foregroundColors[$style['text']];
}
- if (!empty($style['background']) && isset(self::$_backgroundColors[$style['background']])) {
- $styleInfo[] = self::$_backgroundColors[$style['background']];
+ if (!empty($style['background']) && isset(static::$_backgroundColors[$style['background']])) {
+ $styleInfo[] = static::$_backgroundColors[$style['background']];
}
unset($style['text'], $style['background']);
foreach ($style as $option => $value) {
if ($value) {
- $styleInfo[] = self::$_options[$option];
+ $styleInfo[] = static::$_options[$option];
}
}
return "\033[" . implode($styleInfo, ';') . 'm' . $matches['text'] . "\033[0m";
@@ -232,10 +272,11 @@ class ConsoleOutput {
* Writes a message to the output stream.
*
* @param string $message Message to write.
- * @return boolean success
+ * @return bool success
*/
protected function _write($message) {
- return fwrite($this->_output, $message);
+ $this->_lastWritten = fwrite($this->_output, $message);
+ return $this->_lastWritten;
}
/**
@@ -265,23 +306,23 @@ class ConsoleOutput {
*/
public function styles($style = null, $definition = null) {
if ($style === null && $definition === null) {
- return self::$_styles;
+ return static::$_styles;
}
if (is_string($style) && $definition === null) {
- return isset(self::$_styles[$style]) ? self::$_styles[$style] : null;
+ return isset(static::$_styles[$style]) ? static::$_styles[$style] : null;
}
if ($definition === false) {
- unset(self::$_styles[$style]);
+ unset(static::$_styles[$style]);
return true;
}
- self::$_styles[$style] = $definition;
+ static::$_styles[$style] = $definition;
return true;
}
/**
* Get/Set the output type to use. The output type how formatting tags are treated.
*
- * @param integer $type The output type to use. Should be one of the class constants.
+ * @param int $type The output type to use. Should be one of the class constants.
* @return mixed Either null or the value if getting.
*/
public function outputAs($type = null) {
@@ -295,7 +336,9 @@ class ConsoleOutput {
* Clean up and close handles
*/
public function __destruct() {
- fclose($this->_output);
+ if (is_resource($this->_output)) {
+ fclose($this->_output);
+ }
}
}
diff --git a/web/api/lib/Cake/Console/HelpFormatter.php b/web/api/lib/Cake/Console/HelpFormatter.php
index c3b40c354..3a8fac98f 100644
--- a/web/api/lib/Cake/Console/HelpFormatter.php
+++ b/web/api/lib/Cake/Console/HelpFormatter.php
@@ -14,7 +14,7 @@
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
-App::uses('String', 'Utility');
+App::uses('CakeText', 'Utility');
/**
* HelpFormatter formats help for console shells. Can format to either
@@ -33,19 +33,19 @@ class HelpFormatter {
/**
* The maximum number of arguments shown when generating usage.
*
- * @var integer
+ * @var int
*/
protected $_maxArgs = 6;
/**
* The maximum number of options shown when generating usage.
*
- * @var integer
+ * @var int
*/
protected $_maxOptions = 6;
/**
- * Build the help formatter for a an OptionParser
+ * Build the help formatter for an OptionParser
*
* @param ConsoleOptionParser $parser The option parser help is being generated for.
*/
@@ -56,7 +56,7 @@ class HelpFormatter {
/**
* Get the help as formatted text suitable for output on the command line.
*
- * @param integer $width The width of the help output.
+ * @param int $width The width of the help output.
* @return string
*/
public function text($width = 72) {
@@ -64,7 +64,7 @@ class HelpFormatter {
$out = array();
$description = $parser->description();
if (!empty($description)) {
- $out[] = String::wrap($description, $width);
+ $out[] = CakeText::wrap($description, $width);
$out[] = '';
}
$out[] = __d('cake_console', 'Usage:');
@@ -76,7 +76,7 @@ class HelpFormatter {
$out[] = '';
$max = $this->_getMaxLength($subcommands) + 2;
foreach ($subcommands as $command) {
- $out[] = String::wrap($command->help($max), array(
+ $out[] = CakeText::wrap($command->help($max), array(
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
@@ -93,7 +93,7 @@ class HelpFormatter {
$out[] = __d('cake_console', 'Options:');
$out[] = '';
foreach ($options as $option) {
- $out[] = String::wrap($option->help($max), array(
+ $out[] = CakeText::wrap($option->help($max), array(
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
@@ -108,7 +108,7 @@ class HelpFormatter {
$out[] = __d('cake_console', 'Arguments:');
$out[] = '';
foreach ($arguments as $argument) {
- $out[] = String::wrap($argument->help($max), array(
+ $out[] = CakeText::wrap($argument->help($max), array(
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
@@ -118,7 +118,7 @@ class HelpFormatter {
}
$epilog = $parser->epilog();
if (!empty($epilog)) {
- $out[] = String::wrap($epilog, $width);
+ $out[] = CakeText::wrap($epilog, $width);
$out[] = '';
}
return implode("\n", $out);
@@ -159,8 +159,8 @@ class HelpFormatter {
/**
* Iterate over a collection and find the longest named thing.
*
- * @param array $collection
- * @return integer
+ * @param array $collection The collection to find a max length of.
+ * @return int
*/
protected function _getMaxLength($collection) {
$max = 0;
@@ -173,7 +173,7 @@ class HelpFormatter {
/**
* Get the help as an xml string.
*
- * @param boolean $string Return the SimpleXml object or a string. Defaults to true.
+ * @param bool $string Return the SimpleXml object or a string. Defaults to true.
* @return string|SimpleXmlElement See $string
*/
public function xml($string = true) {
diff --git a/web/api/lib/Cake/Console/Helper/BaseShellHelper.php b/web/api/lib/Cake/Console/Helper/BaseShellHelper.php
new file mode 100644
index 000000000..f06a17aac
--- /dev/null
+++ b/web/api/lib/Cake/Console/Helper/BaseShellHelper.php
@@ -0,0 +1,82 @@
+_consoleOutput = $consoleOutput;
+ $this->config($config);
+ }
+
+/**
+ * Initialize config & store config values
+ *
+ * @param null $config Config values to set
+ * @return array|void
+ */
+ public function config($config = null) {
+ if ($config === null) {
+ return $this->_config;
+ }
+ if (!$this->_configInitialized) {
+ $this->_config = array_merge($this->_defaultConfig, $config);
+ $this->_configInitialized = true;
+ } else {
+ $this->_config = array_merge($this->_config, $config);
+ }
+ }
+
+/**
+ * This method should output content using `$this->_consoleOutput`.
+ *
+ * @param array $args The arguments for the helper.
+ * @return void
+ */
+ abstract public function output($args);
+}
\ No newline at end of file
diff --git a/web/api/lib/Cake/Console/Helper/ProgressShellHelper.php b/web/api/lib/Cake/Console/Helper/ProgressShellHelper.php
new file mode 100644
index 000000000..03b216963
--- /dev/null
+++ b/web/api/lib/Cake/Console/Helper/ProgressShellHelper.php
@@ -0,0 +1,122 @@
+ null);
+ if (isset($args[0])) {
+ $args['callback'] = $args[0];
+ }
+ if (!$args['callback'] || !is_callable($args['callback'])) {
+ throw new RuntimeException('Callback option must be a callable.');
+ }
+ $this->init($args);
+ $callback = $args['callback'];
+ while ($this->_progress < $this->_total) {
+ $callback($this);
+ $this->draw();
+ }
+ $this->_consoleOutput->write('');
+ }
+
+/**
+ * Initialize the progress bar for use.
+ *
+ * - `total` The total number of items in the progress bar. Defaults
+ * to 100.
+ * - `width` The width of the progress bar. Defaults to 80.
+ *
+ * @param array $args The initialization data.
+ * @return void
+ */
+ public function init(array $args = array()) {
+ $args += array('total' => 100, 'width' => 80);
+ $this->_progress = 0;
+ $this->_width = $args['width'];
+ $this->_total = $args['total'];
+ }
+
+/**
+ * Increment the progress bar.
+ *
+ * @param int $num The amount of progress to advance by.
+ * @return void
+ */
+ public function increment($num = 1) {
+ $this->_progress = min(max(0, $this->_progress + $num), $this->_total);
+ }
+
+/**
+ * Render the progress bar based on the current state.
+ *
+ * @return void
+ */
+ public function draw() {
+ $numberLen = strlen(' 100%');
+ $complete = round($this->_progress / $this->_total, 2);
+ $barLen = ($this->_width - $numberLen) * ($this->_progress / $this->_total);
+ $bar = '';
+ if ($barLen > 1) {
+ $bar = str_repeat('=', $barLen - 1) . '>';
+ }
+ $pad = ceil($this->_width - $numberLen - $barLen);
+ if ($pad > 0) {
+ $bar .= str_repeat(' ', $pad);
+ }
+ $percent = ($complete * 100) . '%';
+ $bar .= str_pad($percent, $numberLen, ' ', STR_PAD_LEFT);
+ $this->_consoleOutput->overwrite($bar, 0);
+ }
+}
\ No newline at end of file
diff --git a/web/api/lib/Cake/Console/Helper/TableShellHelper.php b/web/api/lib/Cake/Console/Helper/TableShellHelper.php
new file mode 100644
index 000000000..7cf6c799a
--- /dev/null
+++ b/web/api/lib/Cake/Console/Helper/TableShellHelper.php
@@ -0,0 +1,124 @@
+ true,
+ 'rowSeparator' => false,
+ 'headerStyle' => 'info',
+ );
+
+/**
+ * Calculate the column widths
+ *
+ * @param array $rows The rows on which the columns width will be calculated on.
+ * @return array
+ */
+ protected function _calculateWidths($rows) {
+ $widths = array();
+ foreach ($rows as $line) {
+ for ($i = 0, $len = count($line); $i < $len; $i++) {
+ $columnLength = mb_strlen($line[$i]);
+ if ($columnLength > (isset($widths[$i]) ? $widths[$i] : 0)) {
+ $widths[$i] = $columnLength;
+ }
+ }
+ }
+ return $widths;
+ }
+
+/**
+ * Output a row separator.
+ *
+ * @param array $widths The widths of each column to output.
+ * @return void
+ */
+ protected function _rowSeparator($widths) {
+ $out = '';
+ foreach ($widths as $column) {
+ $out .= '+' . str_repeat('-', $column + 2);
+ }
+ $out .= '+';
+ $this->_consoleOutput->write($out);
+ }
+
+/**
+ * Output a row.
+ *
+ * @param array $row The row to output.
+ * @param array $widths The widths of each column to output.
+ * @param array $options Options to be passed.
+ * @return void
+ */
+ protected function _render($row, $widths, $options = array()) {
+ $out = '';
+ foreach ($row as $i => $column) {
+ $pad = $widths[$i] - mb_strlen($column);
+ if (!empty($options['style'])) {
+ $column = $this->_addStyle($column, $options['style']);
+ }
+ $out .= '| ' . $column . str_repeat(' ', $pad) . ' ';
+ }
+ $out .= '|';
+ $this->_consoleOutput->write($out);
+ }
+
+/**
+ * Output a table.
+ *
+ * @param array $rows The data to render out.
+ * @return void
+ */
+ public function output($rows) {
+ $config = $this->config();
+ $widths = $this->_calculateWidths($rows);
+ $this->_rowSeparator($widths);
+ if ($config['headers'] === true) {
+ $this->_render(array_shift($rows), $widths, array('style' => $config['headerStyle']));
+ $this->_rowSeparator($widths);
+ }
+ foreach ($rows as $line) {
+ $this->_render($line, $widths);
+ if ($config['rowSeparator'] === true) {
+ $this->_rowSeparator($widths);
+ }
+ }
+ if ($config['rowSeparator'] !== true) {
+ $this->_rowSeparator($widths);
+ }
+ }
+
+/**
+ * Add style tags
+ *
+ * @param string $text The text to be surrounded
+ * @param string $style The style to be applied
+ * @return string
+ */
+ protected function _addStyle($text, $style) {
+ return '<' . $style . '>' . $text . '' . $style . '>';
+ }
+}
\ No newline at end of file
diff --git a/web/api/lib/Cake/Console/Shell.php b/web/api/lib/Cake/Console/Shell.php
index b6a6cbcf2..c446b9cd3 100644
--- a/web/api/lib/Cake/Console/Shell.php
+++ b/web/api/lib/Cake/Console/Shell.php
@@ -22,7 +22,6 @@ App::uses('ConsoleInputSubcommand', 'Console');
App::uses('ConsoleOptionParser', 'Console');
App::uses('ClassRegistry', 'Utility');
App::uses('File', 'Utility');
-App::uses('ClassRegistry', 'Utility');
/**
* Base class for command-line utilities for automating programmer chores.
@@ -31,24 +30,31 @@ App::uses('ClassRegistry', 'Utility');
*/
class Shell extends Object {
+/**
+ * Default error code
+ *
+ * @var int
+ */
+ const CODE_ERROR = 1;
+
/**
* Output constant making verbose shells.
*
- * @var integer
+ * @var int
*/
const VERBOSE = 2;
/**
* Output constant for making normal shells.
*
- * @var integer
+ * @var int
*/
const NORMAL = 1;
/**
* Output constants for making quiet shells.
*
- * @var integer
+ * @var int
*/
const QUIET = 0;
@@ -62,7 +68,7 @@ class Shell extends Object {
/**
* If true, the script will ask for permission to perform actions.
*
- * @var boolean
+ * @var bool
*/
public $interactive = true;
@@ -167,6 +173,21 @@ class Shell extends Object {
*/
public $stdin;
+/**
+ * The number of bytes last written to the output stream
+ * used when overwriting the previous message.
+ *
+ * @var int
+ */
+ protected $_lastWritten = 0;
+
+/**
+ * Contains helpers which have been previously instantiated
+ *
+ * @var array
+ */
+ protected $_helpers = array();
+
/**
* Constructs this Shell instance.
*
@@ -239,7 +260,7 @@ class Shell extends Object {
/**
* If $uses is an array load each of the models in the array
*
- * @return boolean
+ * @return bool
*/
protected function _loadModels() {
if (is_array($this->uses)) {
@@ -254,7 +275,7 @@ class Shell extends Object {
/**
* Lazy loads models using the loadModel() method if declared in $uses
*
- * @param string $name
+ * @param string $name The name of the model to look for.
* @return void
*/
public function __isset($name) {
@@ -303,7 +324,7 @@ class Shell extends Object {
/**
* Loads tasks defined in public $tasks
*
- * @return boolean
+ * @return bool
*/
public function loadTasks() {
if ($this->tasks === true || empty($this->tasks) || empty($this->Tasks)) {
@@ -318,7 +339,7 @@ class Shell extends Object {
* Check to see if this shell has a task with the provided name.
*
* @param string $task The task name to check.
- * @return boolean Success
+ * @return bool Success
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasTask
*/
public function hasTask($task) {
@@ -329,7 +350,7 @@ class Shell extends Object {
* Check to see if this shell has a callable method by the given name.
*
* @param string $name The method name to check.
- * @return boolean
+ * @return bool
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hasMethod
*/
public function hasMethod($name) {
@@ -446,7 +467,7 @@ class Shell extends Object {
/**
* Display the help in the correct format
*
- * @param string $command
+ * @param string $command The command to get help for.
* @return void
*/
protected function _displayHelp($command) {
@@ -477,7 +498,7 @@ class Shell extends Object {
/**
* Overload get for lazy building of tasks
*
- * @param string $name
+ * @param string $name The property name to access.
* @return Shell Object of Task
*/
public function __get($name) {
@@ -492,6 +513,19 @@ class Shell extends Object {
return $this->{$name};
}
+/**
+ * Safely access the values in $this->params.
+ *
+ * @param string $name The name of the parameter to get.
+ * @return string|bool|null Value. Will return null if it doesn't exist.
+ */
+ public function param($name) {
+ if (!isset($this->params[$name])) {
+ return null;
+ }
+ return $this->params[$name];
+ }
+
/**
* Prompts the user for input, and returns it.
*
@@ -553,7 +587,8 @@ class Shell extends Object {
$result = $this->stdin->read();
if ($result === false) {
- return $this->_stop(1);
+ $this->_stop(self::CODE_ERROR);
+ return self::CODE_ERROR;
}
$result = trim($result);
@@ -574,13 +609,13 @@ class Shell extends Object {
* - `indent` Indent the text with the string provided. Defaults to null.
*
* @param string $text Text the text to format.
- * @param string|integer|array $options Array of options to use, or an integer to wrap the text to.
+ * @param string|int|array $options Array of options to use, or an integer to wrap the text to.
* @return string Wrapped / indented text
- * @see String::wrap()
+ * @see CakeText::wrap()
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::wrapText
*/
public function wrapText($text, $options = array()) {
- return String::wrap($text, $options);
+ return CakeText::wrap($text, $options);
}
/**
@@ -594,10 +629,10 @@ class Shell extends Object {
* present in most shells. Using Shell::QUIET for a message means it will always display.
* While using Shell::VERBOSE means it will only display when verbose output is toggled.
*
- * @param string|array $message A string or a an array of strings to output
- * @param integer $newlines Number of newlines to append
- * @param integer $level The message's output level, see above.
- * @return integer|boolean Returns the number of bytes returned from writing to stdout.
+ * @param string|array $message A string or an array of strings to output
+ * @param int $newlines Number of newlines to append
+ * @param int $level The message's output level, see above.
+ * @return int|bool Returns the number of bytes returned from writing to stdout.
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::out
*/
public function out($message = null, $newlines = 1, $level = Shell::NORMAL) {
@@ -609,17 +644,49 @@ class Shell extends Object {
$currentLevel = Shell::QUIET;
}
if ($level <= $currentLevel) {
- return $this->stdout->write($message, $newlines);
+ $this->_lastWritten = $this->stdout->write($message, $newlines);
+ return $this->_lastWritten;
}
return true;
}
+/**
+ * Overwrite some already output text.
+ *
+ * Useful for building progress bars, or when you want to replace
+ * text already output to the screen with new text.
+ *
+ * **Warning** You cannot overwrite text that contains newlines.
+ *
+ * @param array|string $message The message to output.
+ * @param int $newlines Number of newlines to append.
+ * @param int $size The number of bytes to overwrite. Defaults to the length of the last message output.
+ * @return int|bool Returns the number of bytes returned from writing to stdout.
+ */
+ public function overwrite($message, $newlines = 1, $size = null) {
+ $size = $size ? $size : $this->_lastWritten;
+
+ // Output backspaces.
+ $this->out(str_repeat("\x08", $size), 0);
+
+ $newBytes = $this->out($message, 0);
+
+ // Fill any remaining bytes with spaces.
+ $fill = $size - $newBytes;
+ if ($fill > 0) {
+ $this->out(str_repeat(' ', $fill), 0);
+ }
+ if ($newlines) {
+ $this->out($this->nl($newlines), 0);
+ }
+ }
+
/**
* Outputs a single or multiple error messages to stderr. If no parameters
* are passed outputs just a newline.
*
- * @param string|array $message A string or a an array of strings to output
- * @param integer $newlines Number of newlines to append
+ * @param string|array $message A string or an array of strings to output
+ * @param int $newlines Number of newlines to append
* @return void
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::err
*/
@@ -630,7 +697,7 @@ class Shell extends Object {
/**
* Returns a single or multiple linefeeds sequences.
*
- * @param integer $multiplier Number of times the linefeed sequence should be repeated
+ * @param int $multiplier Number of times the linefeed sequence should be repeated
* @return string
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::nl
*/
@@ -641,8 +708,8 @@ class Shell extends Object {
/**
* Outputs a series of minus characters to the standard output, acts as a visual separator.
*
- * @param integer $newlines Number of newlines to pre- and append
- * @param integer $width Width of the line, defaults to 63
+ * @param int $newlines Number of newlines to pre- and append
+ * @param int $width Width of the line, defaults to 63
* @return void
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::hr
*/
@@ -667,7 +734,8 @@ class Shell extends Object {
if (!empty($message)) {
$this->err($message);
}
- return $this->_stop(1);
+ $this->_stop(self::CODE_ERROR);
+ return self::CODE_ERROR;
}
/**
@@ -691,7 +759,7 @@ class Shell extends Object {
*
* @param string $path Where to put the file.
* @param string $contents Content to put in the file.
- * @return boolean Success
+ * @return bool Success
* @link http://book.cakephp.org/2.0/en/console-and-shells.html#Shell::createFile
*/
public function createFile($path, $contents) {
@@ -705,7 +773,8 @@ class Shell extends Object {
if (strtolower($key) === 'q') {
$this->out(__d('cake_console', 'Quitting.'), 2);
- return $this->_stop();
+ $this->_stop();
+ return true;
} elseif (strtolower($key) !== 'y') {
$this->out(__d('cake_console', 'Skip `%s`', $path), 2);
return false;
@@ -726,10 +795,32 @@ class Shell extends Object {
return false;
}
+/**
+ * Load given shell helper class
+ *
+ * @param string $name Name of the helper class. Supports plugin syntax.
+ * @return BaseShellHelper Instance of helper class
+ * @throws RuntimeException If invalid class name is provided
+ */
+ public function helper($name) {
+ if (isset($this->_helpers[$name])) {
+ return $this->_helpers[$name];
+ }
+ list($plugin, $helperClassName) = pluginSplit($name, true);
+ $helperClassName = Inflector::camelize($name) . "ShellHelper";
+ App::uses($helperClassName, $plugin . "Console/Helper");
+ if (!class_exists($helperClassName)) {
+ throw new RuntimeException("Class " . $helperClassName . " not found");
+ }
+ $helper = new $helperClassName($this->stdout);
+ $this->_helpers[$name] = $helper;
+ return $helper;
+ }
+
/**
* Action to create a Unit Test
*
- * @return boolean Success
+ * @return bool Success
*/
protected function _checkUnitTest() {
if (class_exists('PHPUnit_Framework_TestCase')) {
@@ -819,8 +910,8 @@ class Shell extends Object {
/**
* creates the singular name for use in views.
*
- * @param string $name
- * @return string $name
+ * @param string $name The plural underscored value.
+ * @return string name
*/
protected function _singularName($name) {
return Inflector::variable(Inflector::singularize($name));
@@ -860,7 +951,7 @@ class Shell extends Object {
* Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
*
* @param string $pluginName Name of the plugin you want ie. DebugKit
- * @return string $path path to the correct plugin.
+ * @return string path path to the correct plugin.
*/
protected function _pluginPath($pluginName) {
if (CakePlugin::loaded($pluginName)) {
@@ -874,7 +965,7 @@ class Shell extends Object {
* If you don't wish to see in your stdout or stderr everything that is logged
* through CakeLog, call this function with first param as false
*
- * @param boolean $enable whether to enable CakeLog output or not
+ * @param bool $enable whether to enable CakeLog output or not
* @return void
*/
protected function _useLogger($enable = true) {
diff --git a/web/api/lib/Cake/Console/ShellDispatcher.php b/web/api/lib/Cake/Console/ShellDispatcher.php
index b284fcbe9..d53851127 100644
--- a/web/api/lib/Cake/Console/ShellDispatcher.php
+++ b/web/api/lib/Cake/Console/ShellDispatcher.php
@@ -43,7 +43,7 @@ class ShellDispatcher {
* a status code of either 0 or 1 according to the result of the dispatch.
*
* @param array $args the argv from PHP
- * @param boolean $bootstrap Should the environment be bootstrapped.
+ * @param bool $bootstrap Should the environment be bootstrapped.
*/
public function __construct($args = array(), $bootstrap = true) {
set_time_limit(0);
@@ -79,9 +79,11 @@ class ShellDispatcher {
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
- define('DS', DIRECTORY_SEPARATOR);
define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(dirname(__FILE__))));
define('CAKEPHP_SHELL', true);
+ if (!defined('DS')) {
+ define('DS', DIRECTORY_SEPARATOR);
+ }
if (!defined('CORE_PATH')) {
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
@@ -114,7 +116,7 @@ class ShellDispatcher {
/**
* Initializes the environment and loads the CakePHP core.
*
- * @return boolean Success.
+ * @return bool Success.
*/
protected function _bootstrap() {
if (!defined('ROOT')) {
@@ -175,12 +177,15 @@ class ShellDispatcher {
}
set_exception_handler($exception['consoleHandler']);
set_error_handler($error['consoleHandler'], Configure::read('Error.level'));
+
+ App::uses('Debugger', 'Utility');
+ Debugger::getInstance()->output('txt');
}
/**
* Dispatches a CLI request
*
- * @return boolean
+ * @return bool
* @throws MissingShellMethodException
*/
public function dispatch() {
@@ -244,6 +249,11 @@ class ShellDispatcher {
App::uses('AppShell', 'Console/Command');
App::uses($class, $plugin . 'Console/Command');
+ if (!class_exists($class)) {
+ $plugin = Inflector::camelize($shell) . '.';
+ App::uses($class, $plugin . 'Console/Command');
+ }
+
if (!class_exists($class)) {
throw new MissingShellException(array(
'class' => $class
@@ -317,12 +327,13 @@ class ShellDispatcher {
/**
* Parses out the paths from from the argv
*
- * @param array $args
+ * @param array $args The argv to parse.
* @return void
*/
protected function _parsePaths($args) {
$parsed = array();
$keys = array('-working', '--working', '-app', '--app', '-root', '--root');
+ $args = (array)$args;
foreach ($keys as $key) {
while (($index = array_search($key, $args)) !== false) {
$keyname = str_replace('-', '', $key);
@@ -357,7 +368,7 @@ class ShellDispatcher {
/**
* Stop execution of the current script
*
- * @param integer|string $status see http://php.net/exit for values
+ * @param int|string $status see http://php.net/exit for values
* @return void
*/
protected function _stop($status = 0) {
diff --git a/web/api/lib/Cake/Console/TaskCollection.php b/web/api/lib/Cake/Console/TaskCollection.php
index ff1ddee67..3fafddd13 100644
--- a/web/api/lib/Cake/Console/TaskCollection.php
+++ b/web/api/lib/Cake/Console/TaskCollection.php
@@ -43,7 +43,7 @@ class TaskCollection extends ObjectCollection {
/**
* Constructor
*
- * @param Shell $Shell
+ * @param Shell $Shell The shell this task collection is attached to.
*/
public function __construct(Shell $Shell) {
$this->_Shell = $Shell;
@@ -53,13 +53,13 @@ class TaskCollection extends ObjectCollection {
* Loads/constructs a task. Will return the instance in the registry if it already exists.
*
* You can alias your task as an existing task by setting the 'className' key, i.e.,
- * {{{
+ * ```
* public $tasks = array(
* 'DbConfig' => array(
* 'className' => 'Bakeplus.DbConfigure'
* );
* );
- * }}}
+ * ```
* All calls to the `DbConfig` task would use `DbConfigure` found in the `Bakeplus` plugin instead.
*
* @param string $task Task name to load
diff --git a/web/api/lib/Cake/Console/Templates/default/actions/controller_actions.ctp b/web/api/lib/Cake/Console/Templates/default/actions/controller_actions.ctp
index b6b89a993..dfc309215 100644
--- a/web/api/lib/Cake/Console/Templates/default/actions/controller_actions.ctp
+++ b/web/api/lib/Cake/Console/Templates/default/actions/controller_actions.ctp
@@ -53,10 +53,10 @@
$this->->create();
if ($this->->save($this->request->data)) {
- $this->Session->setFlash(__('The has been saved.'));
+ $this->Flash->success(__('The has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
- $this->Session->setFlash(__('The could not be saved. Please, try again.'));
+ $this->Flash->error(__('The could not be saved. Please, try again.'));
return $this->flash(__('The has been saved.'), array('action' => 'index'));
@@ -94,10 +94,10 @@
if ($this->request->is(array('post', 'put'))) {
if ($this->->save($this->request->data)) {
- $this->Session->setFlash(__('The has been saved.'));
+ $this->Flash->success(__('The has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
- $this->Session->setFlash(__('The could not be saved. Please, try again.'));
+ $this->Flash->error(__('The could not be saved. Please, try again.'));
return $this->flash(__('The has been saved.'), array('action' => 'index'));
@@ -138,9 +138,9 @@
$this->request->allowMethod('post', 'delete');
if ($this->->delete()) {
- $this->Session->setFlash(__('The has been deleted.'));
+ $this->Flash->success(__('The has been deleted.'));
} else {
- $this->Session->setFlash(__('The could not be deleted. Please, try again.'));
+ $this->Flash->error(__('The could not be deleted. Please, try again.'));
}
return $this->redirect(array('action' => 'index'));
diff --git a/web/api/lib/Cake/Console/Templates/default/classes/controller.ctp b/web/api/lib/Cake/Console/Templates/default/classes/controller.ctp
index e290a8675..6beb4b401 100644
--- a/web/api/lib/Cake/Console/Templates/default/classes/controller.ctp
+++ b/web/api/lib/Cake/Console/Templates/default/classes/controller.ctp
@@ -23,10 +23,10 @@ echo "App::uses('{$plugin}AppController', '{$pluginPath}Controller');\n";
?>
/**
* Controller
- *
Controller extends App
echo ");\n\n";
endif;
- echo trim($actions);
+ if (!empty($actions)) {
+ echo trim($actions) . "\n";
+ }
endif; ?>
}
diff --git a/web/api/lib/Cake/Console/Templates/default/classes/fixture.ctp b/web/api/lib/Cake/Console/Templates/default/classes/fixture.ctp
index 0fb23e24f..7ac2c3987 100644
--- a/web/api/lib/Cake/Console/Templates/default/classes/fixture.ctp
+++ b/web/api/lib/Cake/Console/Templates/default/classes/fixture.ctp
@@ -21,8 +21,7 @@
echo "
/**
- * Fixture
- *
+ * Fixture
*/
class Fixture extends CakeTestFixture {
diff --git a/web/api/lib/Cake/Console/Templates/default/classes/model.ctp b/web/api/lib/Cake/Console/Templates/default/classes/model.ctp
index 0014e004e..6c3e64763 100644
--- a/web/api/lib/Cake/Console/Templates/default/classes/model.ctp
+++ b/web/api/lib/Cake/Console/Templates/default/classes/model.ctp
@@ -106,7 +106,7 @@ foreach ($associations as $assoc):
if (!empty($assoc)):
?>
- //The Associations below have been created with all possible keys, those that are not needed can be removed
+ // The Associations below have been created with all possible keys, those that are not needed can be removed
', '');
/**
* Test Case
- *
*/
class Test extends ControllerTestCase {
diff --git a/web/api/lib/Cake/Console/Templates/default/views/form.ctp b/web/api/lib/Cake/Console/Templates/default/views/form.ctp
index fa9c58315..4a21aabe3 100644
--- a/web/api/lib/Cake/Console/Templates/default/views/form.ctp
+++ b/web/api/lib/Cake/Console/Templates/default/views/form.ctp
@@ -1,7 +1,5 @@
Form->input('{$field}');\n";
@@ -46,7 +44,7 @@
-
Form->postLink(__('Delete'), array('action' => 'delete', \$this->Form->value('{$modelClass}.{$primaryKey}')), null, __('Are you sure you want to delete # %s?', \$this->Form->value('{$modelClass}.{$primaryKey}'))); ?>"; ?>
+
Form->postLink(__('Delete'), array('action' => 'delete', \$this->Form->value('{$modelClass}.{$primaryKey}')), array('confirm' => __('Are you sure you want to delete # %s?', \$this->Form->value('{$modelClass}.{$primaryKey}')))); ?>"; ?>
\n";
echo "\t\t\tHtml->link(__('View'), array('action' => 'view', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
echo "\t\t\tHtml->link(__('Edit'), array('action' => 'edit', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
- echo "\t\t\tForm->postLink(__('Delete'), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), array(), __('Are you sure you want to delete # %s?', \${$singularVar}['{$modelClass}']['{$primaryKey}'])); ?>\n";
+ echo "\t\t\tForm->postLink(__('Delete'), array('action' => 'delete', \${$singularVar}['{$modelClass}']['{$primaryKey}']), array('confirm' => __('Are you sure you want to delete # %s?', \${$singularVar}['{$modelClass}']['{$primaryKey}']))); ?>\n";
echo "\t\t
\n";
echo "\t
\n";
echo "\n";
?>
+
Paginator->counter(array(
- 'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
+ 'format' => __('Page {:page} of {:pages}, showing {:current} records out of {:count} total, starting on record {:start}, ending on {:end}')
));
?>"; ?>
diff --git a/web/api/lib/Cake/View/ThemeView.php b/web/api/lib/Cake/View/ThemeView.php
index 8b36429fe..8e201a4f1 100644
--- a/web/api/lib/Cake/View/ThemeView.php
+++ b/web/api/lib/Cake/View/ThemeView.php
@@ -24,7 +24,7 @@ App::uses('View', 'View');
* Stub class for 2.1 Compatibility
*
* @package Cake.View
- * @deprecated Deprecated since 2.1, use View class instead
+ * @deprecated 3.0.0 Deprecated since 2.1, use View class instead
*/
class ThemeView extends View {
diff --git a/web/api/lib/Cake/View/View.php b/web/api/lib/Cake/View/View.php
index 6ccefbe72..f68db4e22 100644
--- a/web/api/lib/Cake/View/View.php
+++ b/web/api/lib/Cake/View/View.php
@@ -80,7 +80,7 @@ class View extends Object {
/**
* Name of the controller.
*
- * @var string Name of controller
+ * @var string
*/
public $name = null;
@@ -94,14 +94,14 @@ class View extends Object {
/**
* An array of names of built-in helpers to include.
*
- * @var mixed A single name as a string or a list of names as an array.
+ * @var mixed
*/
public $helpers = array();
/**
* Path to View.
*
- * @var string Path to View
+ * @var string
*/
public $viewPath = null;
@@ -129,7 +129,7 @@ class View extends Object {
/**
* Path to Layout.
*
- * @var string Path to Layout
+ * @var string
*/
public $layoutPath = null;
@@ -137,7 +137,7 @@ class View extends Object {
* Turns on or off CakePHP's conventional mode of applying layout files. On by default.
* Setting to off means that layouts will not be automatically applied to rendered views.
*
- * @var boolean
+ * @var bool
*/
public $autoLayout = true;
@@ -181,7 +181,7 @@ class View extends Object {
/**
* True when the view has been rendered.
*
- * @var boolean
+ * @var bool
*/
public $hasRendered = false;
@@ -251,6 +251,13 @@ class View extends Object {
*/
protected $_paths = array();
+/**
+ * Holds an array of plugin paths.
+ *
+ * @var array
+ */
+ protected $_pathsForPlugin = array();
+
/**
* The names of views and their parents used with View::extend();
*
@@ -293,7 +300,7 @@ class View extends Object {
/**
* Whether the event manager was already configured for this object
*
- * @var boolean
+ * @var bool
*/
protected $_eventManagerConfigured = false;
@@ -381,13 +388,12 @@ class View extends Object {
* If an array, the following keys can be used:
* - `config` - Used to store the cached element in a custom cache configuration.
* - `key` - Used to define the key used in the Cache::write(). It will be prefixed with `element_`
- * - `plugin` - Load an element from a specific plugin. This option is deprecated, see below.
+ * - `plugin` - (deprecated!) Load an element from a specific plugin. This option is deprecated, and
+ * will be removed in CakePHP 3.0. Use `Plugin.element_name` instead.
* - `callbacks` - Set to true to fire beforeRender and afterRender helper callbacks for this element.
* Defaults to false.
* - `ignoreMissing` - Used to allow missing elements. Set to true to not trigger notices.
* @return string Rendered Element
- * @deprecated The `$options['plugin']` is deprecated and will be removed in CakePHP 3.0. Use
- * `Plugin.element_name` instead.
*/
public function element($name, $data = array(), $options = array()) {
$file = $plugin = null;
@@ -426,7 +432,7 @@ class View extends Object {
* @param string $name Name of template file in the /app/View/Elements/ folder,
* or `MyPlugin.template` to check the template element from MyPlugin. If the element
* is not found in the plugin, the normal view path cascade will be searched.
- * @return boolean Success
+ * @return bool Success
*/
public function elementExists($name) {
return (bool)$this->_getElementFilename($name);
@@ -452,15 +458,17 @@ class View extends Object {
* @param string $view Name of view file to use
* @param string $layout Layout to use.
* @return string|null Rendered content or null if content already rendered and returned earlier.
+ * @triggers View.beforeRender $this, array($viewFileName)
+ * @triggers View.afterRender $this, array($viewFileName)
* @throws CakeException If there is an error in the view.
*/
public function render($view = null, $layout = null) {
if ($this->hasRendered) {
- return;
+ return null;
}
if ($view !== false && $viewFileName = $this->_getViewFileName($view)) {
- $this->_currentType = self::TYPE_VIEW;
+ $this->_currentType = static::TYPE_VIEW;
$this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($viewFileName)));
$this->Blocks->set('content', $this->_render($viewFileName));
$this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($viewFileName)));
@@ -498,6 +506,8 @@ class View extends Object {
* @param string $content Content to render in a view, wrapped by the surrounding layout.
* @param string $layout Layout name
* @return mixed Rendered output, or false on error
+ * @triggers View.beforeLayout $this, array($layoutFileName)
+ * @triggers View.afterLayout $this, array($layoutFileName)
* @throws CakeException if there is an error in the view.
*/
public function renderLayout($content, $layout = null) {
@@ -532,7 +542,7 @@ class View extends Object {
$this->viewVars['title_for_layout'] = $title;
$this->Blocks->set('title', $title);
- $this->_currentType = self::TYPE_LAYOUT;
+ $this->_currentType = static::TYPE_LAYOUT;
$this->Blocks->set('content', $this->_render($layoutFileName));
$this->getEventManager()->dispatch(new CakeEvent('View.afterLayout', $this, array($layoutFileName)));
@@ -545,7 +555,7 @@ class View extends Object {
*
* @param string $filename the cache file to include
* @param string $timeStart the page render start time
- * @return boolean Success of rendering the cached file.
+ * @return bool Success of rendering the cached file.
*/
public function renderCache($filename, $timeStart) {
$response = $this->response;
@@ -584,15 +594,14 @@ class View extends Object {
*
* @param string $var The view var you want the contents of.
* @return mixed The content of the named var if its set, otherwise null.
- * @deprecated Will be removed in 3.0. Use View::get() instead.
+ * @deprecated 3.0.0 Will be removed in 3.0. Use View::get() instead.
*/
public function getVar($var) {
return $this->get($var);
}
/**
- * Returns the contents of the given View variable or a block.
- * Blocks are checked before view variables.
+ * Returns the contents of the given View variable.
*
* @param string $var The view var you want the contents of.
* @param mixed $default The default/fallback content of $var.
@@ -682,13 +691,23 @@ class View extends Object {
*
* @param string $name Name of the block
* @param string $default Default text
- * @return string $default The block content or $default if the block does not exist.
+ * @return string default The block content or $default if the block does not exist.
* @see ViewBlock::get()
*/
public function fetch($name, $default = '') {
return $this->Blocks->get($name, $default);
}
+/**
+ * Check if a block exists
+ *
+ * @param string $name Name of the block
+ * @return bool
+ */
+ public function exists($name) {
+ return $this->Blocks->exists($name);
+ }
+
/**
* End a capturing block. The compliment to View::start()
*
@@ -709,11 +728,11 @@ class View extends Object {
* @throws LogicException when you extend an element which doesn't exist
*/
public function extend($name) {
- if ($name[0] === '/' || $this->_currentType === self::TYPE_VIEW) {
+ if ($name[0] === '/' || $this->_currentType === static::TYPE_VIEW) {
$parent = $this->_getViewFileName($name);
} else {
switch ($this->_currentType) {
- case self::TYPE_ELEMENT:
+ case static::TYPE_ELEMENT:
$parent = $this->_getElementFileName($name);
if (!$parent) {
list($plugin, $name) = $this->pluginSplit($name);
@@ -726,7 +745,7 @@ class View extends Object {
));
}
break;
- case self::TYPE_LAYOUT:
+ case static::TYPE_LAYOUT:
$parent = $this->_getLayoutFileName($name);
break;
default:
@@ -751,7 +770,7 @@ class View extends Object {
* update/replace a script element.
* @param string $content The content of the script being added, optional.
* @return void
- * @deprecated Will be removed in 3.0. Superseded by blocks functionality.
+ * @deprecated 3.0.0 Will be removed in 3.0. Superseded by blocks functionality.
* @see View::start()
*/
public function addScript($name, $content = null) {
@@ -808,7 +827,14 @@ class View extends Object {
}
$this->viewVars = $data + $this->viewVars;
}
-
+/**
+ * Retrieve the current view type
+ *
+ * @return string
+ */
+ public function getCurrentType() {
+ return $this->_currentType;
+ }
/**
* Magic accessor for helpers. Provides access to attributes that were deprecated.
*
@@ -856,7 +882,7 @@ class View extends Object {
* Magic isset check for deprecated attributes.
*
* @param string $name Name of the attribute to check.
- * @return boolean
+ * @return bool
*/
public function __isset($name) {
if (isset($this->{$name})) {
@@ -889,6 +915,8 @@ class View extends Object {
* @param string $viewFile Filename of the view
* @param array $data Data to include in rendered view. If empty the current View::$viewVars will be used.
* @return string Rendered output
+ * @triggers View.beforeRenderFile $this, array($viewFile)
+ * @triggers View.afterRenderFile $this, array($viewFile, $content)
* @throws CakeException when a block is left open.
*/
protected function _render($viewFile, $data = array()) {
@@ -930,7 +958,7 @@ class View extends Object {
/**
* Sandbox method to evaluate a template / view script in.
*
- * @param string $viewFn Filename of the view
+ * @param string $viewFile Filename of the view
* @param array $dataForView Data to include in rendered view.
* If empty the current View::$viewVars will be used.
* @return string Rendered output
@@ -984,9 +1012,6 @@ class View extends Object {
$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
} elseif (strpos($name, DS) !== false) {
if ($name[0] === DS || $name[1] === ':') {
- if (is_file($name)) {
- return $name;
- }
$name = trim($name, DS);
} elseif ($name[0] === '.') {
$name = substr($name, 3);
@@ -1003,18 +1028,7 @@ class View extends Object {
}
}
}
- $defaultPath = $paths[0];
-
- if ($this->plugin) {
- $pluginPaths = App::path('plugins');
- foreach ($paths as $path) {
- if (strpos($path, $pluginPaths[0]) === 0) {
- $defaultPath = $path;
- break;
- }
- }
- }
- throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
+ throw new MissingViewException(array('file' => $name . $this->ext));
}
/**
@@ -1023,7 +1037,7 @@ class View extends Object {
* It checks if the plugin is loaded, else filename will stay unchanged for filenames containing dot
*
* @param string $name The name you want to plugin split.
- * @param boolean $fallback If true uses the plugin set in the current CakeRequest when parsed plugin is not loaded
+ * @param bool $fallback If true uses the plugin set in the current CakeRequest when parsed plugin is not loaded
* @return array Array with 2 indexes. 0 => plugin name, 1 => filename
*/
public function pluginSplit($name, $fallback = true) {
@@ -1067,7 +1081,7 @@ class View extends Object {
}
}
}
- throw new MissingLayoutException(array('file' => $paths[0] . $file . $this->ext));
+ throw new MissingLayoutException(array('file' => $file . $this->ext));
}
/**
@@ -1108,12 +1122,17 @@ class View extends Object {
* Return all possible paths to find view files in order
*
* @param string $plugin Optional plugin name to scan for view files.
- * @param boolean $cached Set to false to force a refresh of view paths. Default true.
+ * @param bool $cached Set to false to force a refresh of view paths. Default true.
* @return array paths
*/
protected function _paths($plugin = null, $cached = true) {
- if ($plugin === null && $cached === true && !empty($this->_paths)) {
- return $this->_paths;
+ if ($cached === true) {
+ if ($plugin === null && !empty($this->_paths)) {
+ return $this->_paths;
+ }
+ if ($plugin !== null && isset($this->_pathsForPlugin[$plugin])) {
+ return $this->_pathsForPlugin[$plugin];
+ }
}
$paths = array();
$viewPaths = App::path('View');
@@ -1145,7 +1164,7 @@ class View extends Object {
}
$paths = array_merge($paths, $corePaths);
if ($plugin !== null) {
- return $paths;
+ return $this->_pathsForPlugin[$plugin] = $paths;
}
return $this->_paths = $paths;
}
@@ -1190,24 +1209,27 @@ class View extends Object {
* @param array $data Data to render
* @param array $options Element options
* @return string
+ * @triggers View.beforeRender $this, array($file)
+ * @triggers View.afterRender $this, array($file, $element)
*/
protected function _renderElement($file, $data, $options) {
+ $current = $this->_current;
+ $restore = $this->_currentType;
+ $this->_currentType = static::TYPE_ELEMENT;
+
if ($options['callbacks']) {
$this->getEventManager()->dispatch(new CakeEvent('View.beforeRender', $this, array($file)));
}
- $current = $this->_current;
- $restore = $this->_currentType;
-
- $this->_currentType = self::TYPE_ELEMENT;
$element = $this->_render($file, array_merge($this->viewVars, $data));
- $this->_currentType = $restore;
- $this->_current = $current;
-
if ($options['callbacks']) {
$this->getEventManager()->dispatch(new CakeEvent('View.afterRender', $this, array($file, $element)));
}
+
+ $this->_currentType = $restore;
+ $this->_current = $current;
+
if (isset($options['cache'])) {
Cache::write($this->elementCacheSettings['key'], $element, $this->elementCacheSettings['config']);
}
diff --git a/web/api/lib/Cake/View/ViewBlock.php b/web/api/lib/Cake/View/ViewBlock.php
index 28667c8c3..2d4908a28 100644
--- a/web/api/lib/Cake/View/ViewBlock.php
+++ b/web/api/lib/Cake/View/ViewBlock.php
@@ -1,7 +1,5 @@
_active)) {
- throw new CakeException(__("A view block with the name '%s' is already/still open.", $name));
+ throw new CakeException(__d('cake', "A view block with the name '%s' is already/still open.", $name));
}
$this->_active[] = $name;
ob_start();
@@ -166,7 +164,7 @@ class ViewBlock {
* @param string $name Name of the block
* @param string $value The content for the block.
* @return void
- * @deprecated As of 2.3 use ViewBlock::concat() instead.
+ * @deprecated 3.0.0 As of 2.3 use ViewBlock::concat() instead.
*/
public function append($name, $value = null) {
$this->concat($name, $value);
@@ -198,6 +196,16 @@ class ViewBlock {
return $this->_blocks[$name];
}
+/**
+ * Check if a block exists
+ *
+ * @param string $name Name of the block
+ * @return bool
+ */
+ public function exists($name) {
+ return isset($this->_blocks[$name]);
+ }
+
/**
* Get the names of all the existing blocks.
*
diff --git a/web/api/lib/Cake/View/XmlView.php b/web/api/lib/Cake/View/XmlView.php
index 1bf5419ed..7d7610836 100644
--- a/web/api/lib/Cake/View/XmlView.php
+++ b/web/api/lib/Cake/View/XmlView.php
@@ -36,10 +36,10 @@ App::uses('Hash', 'Utility');
* You can also define `'_serialize'` as an array. This will create an additional
* top level element named `` containing all the named view variables:
*
- * {{{
+ * ```
* $this->set(compact('posts', 'users', 'stuff'));
* $this->set('_serialize', array('posts', 'users'));
- * }}}
+ * ```
*
* The above would generate a XML object that looks like:
*
@@ -63,7 +63,7 @@ class XmlView extends View {
/**
* Constructor
*
- * @param Controller $controller
+ * @param Controller $controller Controller instance.
*/
public function __construct(Controller $controller = null) {
parent::__construct($controller);
@@ -109,6 +109,10 @@ class XmlView extends View {
/**
* Serialize view vars.
*
+ * ### Special parameters
+ * `_xmlOptions` You can set an array of custom options for Xml::fromArray() this way, e.g.
+ * 'format' as 'attributes' instead of 'tags'.
+ *
* @param array $serialize The viewVars that need to be serialized.
* @return string The serialized data
*/
@@ -131,10 +135,16 @@ class XmlView extends View {
}
$options = array();
+ if (isset($this->viewVars['_xmlOptions'])) {
+ $options = $this->viewVars['_xmlOptions'];
+ }
if (Configure::read('debug')) {
$options['pretty'] = true;
}
+ if (isset($options['return']) && strtolower($options['return']) === 'domdocument') {
+ return Xml::fromArray($data, $options)->saveXML();
+ }
return Xml::fromArray($data, $options)->asXML();
}
diff --git a/web/api/lib/Cake/basics.php b/web/api/lib/Cake/basics.php
index 60deced1c..e1edb6ea1 100644
--- a/web/api/lib/Cake/basics.php
+++ b/web/api/lib/Cake/basics.php
@@ -38,7 +38,7 @@ if (!function_exists('config')) {
*
* `config('config1', 'config2');`
*
- * @return boolean Success
+ * @return bool Success
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#config
*/
function config() {
@@ -64,24 +64,27 @@ if (!function_exists('debug')) {
* Only runs if debug level is greater than zero.
*
* @param mixed $var Variable to show debug information for.
- * @param boolean $showHtml If set to true, the method prints the debug data in a browser-friendly way.
- * @param boolean $showFrom If set to true, the method prints from where the function was called.
+ * @param bool $showHtml If set to true, the method prints the debug data in a browser-friendly way.
+ * @param bool $showFrom If set to true, the method prints from where the function was called.
* @return void
* @link http://book.cakephp.org/2.0/en/development/debugging.html#basic-debugging
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug
*/
function debug($var, $showHtml = null, $showFrom = true) {
- if (Configure::read('debug') > 0) {
- App::uses('Debugger', 'Utility');
- $file = '';
- $line = '';
- $lineInfo = '';
- if ($showFrom) {
- $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
- $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
- $line = $trace[0]['line'];
- }
- $html = << 1, 'depth' => 2, 'format' => 'array'));
+ $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
+ $line = $trace[0]['line'];
+ }
+ $html = <<
%s
@@ -89,33 +92,61 @@ if (!function_exists('debug')) {
HTML;
- $text = <<%s (line %s)', $file, $line);
- }
- }
- printf($template, $lineInfo, $var);
}
+ if ($showHtml === null && $template !== $text) {
+ $showHtml = true;
+ }
+ $var = Debugger::exportVar($var, 25);
+ if ($showHtml) {
+ $template = $html;
+ $var = h($var);
+ if ($showFrom) {
+ $lineInfo = sprintf('%s (line %s)', $file, $line);
+ }
+ }
+ printf($template, $lineInfo, $var);
+ }
+
+}
+
+if (!function_exists('stackTrace')) {
+
+/**
+ * Outputs a stack trace based on the supplied options.
+ *
+ * ### Options
+ *
+ * - `depth` - The number of stack frames to return. Defaults to 999
+ * - `args` - Should arguments for functions be shown? If true, the arguments for each method call
+ * will be displayed.
+ * - `start` - The stack frame to start generating a trace from. Defaults to 1
+ *
+ * @param array $options Format for outputting stack trace
+ * @return mixed Formatted stack trace
+ * @see Debugger::trace()
+ */
+ function stackTrace(array $options = array()) {
+ if (!Configure::read('debug')) {
+ return;
+ }
+ App::uses('Debugger', 'Utility');
+
+ $options += array('start' => 0);
+ $options['start']++;
+ echo Debugger::trace($options);
}
}
@@ -125,11 +156,11 @@ if (!function_exists('sortByKey')) {
/**
* Sorts given $array by key $sortBy.
*
- * @param array $array Array to sort
+ * @param array &$array Array to sort
* @param string $sortBy Sort by this key
* @param string $order Sort order asc/desc (ascending or descending).
- * @param integer $type Type of sorting to perform
- * @return mixed Sorted array
+ * @param int $type Type of sorting to perform
+ * @return array|null Sorted array, or null if not an array.
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#sortByKey
*/
function sortByKey(&$array, $sortBy, $order = 'asc', $type = SORT_NUMERIC) {
@@ -163,13 +194,15 @@ if (!function_exists('h')) {
* @param string|array|object $text Text to wrap through htmlspecialchars. Also works with arrays, and objects.
* Arrays will be mapped and have all their elements escaped. Objects will be string cast if they
* implement a `__toString` method. Otherwise the class name will be used.
- * @param boolean $double Encode existing html entities
+ * @param bool $double Encode existing html entities
* @param string $charset Character set to use when escaping. Defaults to config value in 'App.encoding' or 'UTF-8'
* @return string Wrapped text
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#h
*/
function h($text, $double = true, $charset = null) {
- if (is_array($text)) {
+ if (is_string($text)) {
+ //optimize for strings
+ } elseif (is_array($text)) {
$texts = array();
foreach ($text as $k => $t) {
$texts[$k] = h($t, $double, $charset);
@@ -209,7 +242,7 @@ if (!function_exists('pluginSplit')) {
* Commonly used like `list($plugin, $name) = pluginSplit($name);`
*
* @param string $name The name you want to plugin split.
- * @param boolean $dotAppend Set to true if you want the plugin to have a '.' appended to it.
+ * @param bool $dotAppend Set to true if you want the plugin to have a '.' appended to it.
* @param string $plugin Optional default plugin to use if no plugin is found. Defaults to null.
* @return array Array with 2 indexes. 0 => plugin name, 1 => class name
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pluginSplit
@@ -235,14 +268,14 @@ if (!function_exists('pr')) {
* In terminals this will act the same as using print_r() directly, when not run on cli
* print_r() will wrap
tags around the output of given array. Similar to debug().
*
- * @see debug()
* @param mixed $var Variable to print out
* @return void
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#pr
+ * @see debug()
*/
function pr($var) {
if (Configure::read('debug') > 0) {
- $template = php_sapi_name() !== 'cli' ? '
' : "\n%s\n";
printf($template, print_r($var, true));
}
}
@@ -254,10 +287,8 @@ if (!function_exists('am')) {
/**
* Merge a group of arrays
*
- * @param array First array
- * @param array Second array
- * @param array Third array
- * @param array Etc...
+ * Accepts variable arguments. Each argument will be converted into an array and then merged.
+ *
* @return array All array parameters merged into one
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#am
*/
@@ -284,7 +315,7 @@ if (!function_exists('env')) {
* environment information.
*
* @param string $key Environment variable name.
- * @return string Environment variable setting.
+ * @return string|bool|null Environment variable setting.
* @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#env
*/
function env($key) {
@@ -389,7 +420,7 @@ if (!function_exists('cache')) {
* @param mixed $expires A valid strtotime string when the data expires.
* @param string $target The target of the cached data; either 'cache' or 'public'.
* @return mixed The contents of the temporary file.
- * @deprecated Will be removed in 3.0. Please use Cache::write() instead.
+ * @deprecated 3.0.0 Will be removed in 3.0. Please use Cache::write() instead.
*/
function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
if (Configure::read('Cache.disable')) {
@@ -549,19 +580,13 @@ if (!function_exists('__')) {
*/
function __($singular, $args = null) {
if (!$singular) {
- return;
+ return null;
}
App::uses('I18n', 'I18n');
$translated = I18n::translate($singular);
- if ($args === null) {
- return $translated;
- } elseif (!is_array($args)) {
- $args = array_slice(func_get_args(), 1);
- }
-
- $translated = preg_replace('/(? '',
+ JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
+ JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
+ JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
+ JSON_ERROR_SYNTAX => 'Syntax error',
+ JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded'
+ );
+ $error = json_last_error();
+ return array_key_exists($error, $errors) ? $errors[$error] : "Unknown error ({$error})";
+ }
+
+}
diff --git a/web/api/lib/Cake/bootstrap.php b/web/api/lib/Cake/bootstrap.php
index e1bd899eb..b17c9f68f 100644
--- a/web/api/lib/Cake/bootstrap.php
+++ b/web/api/lib/Cake/bootstrap.php
@@ -148,6 +148,8 @@ App::uses('Cache', 'Cache');
App::uses('Object', 'Core');
App::uses('Multibyte', 'I18n');
+App::$bootstrapping = true;
+
/**
* Full URL prefix
*/
@@ -170,19 +172,6 @@ Configure::write('App.imageBaseUrl', IMAGES_URL);
Configure::write('App.cssBaseUrl', CSS_URL);
Configure::write('App.jsBaseUrl', JS_URL);
-App::$bootstrapping = true;
-
-Configure::bootstrap(isset($boot) ? $boot : true);
-
-if (function_exists('mb_internal_encoding')) {
- $encoding = Configure::read('App.encoding');
- if (!empty($encoding)) {
- mb_internal_encoding($encoding);
- }
- if (!empty($encoding) && function_exists('mb_regex_encoding')) {
- mb_regex_encoding($encoding);
- }
-}
if (!function_exists('mb_stripos')) {
@@ -191,9 +180,9 @@ if (!function_exists('mb_stripos')) {
*
* @param string $haystack The string from which to get the position of the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
- * @param integer $offset The position in $haystack to start searching.
+ * @param int $offset The position in $haystack to start searching.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false
+ * @return int|bool The numeric position of the first occurrence of $needle in the $haystack string, or false
* if $needle is not found.
*/
function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
@@ -209,12 +198,12 @@ if (!function_exists('mb_stristr')) {
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
- * @param boolean $part Determines which portion of $haystack this function returns.
+ * @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is false.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string|boolean The portion of $haystack, or false if $needle is not found.
+ * @return string|bool The portion of $haystack, or false if $needle is not found.
*/
function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::stristr($haystack, $needle, $part);
@@ -229,7 +218,7 @@ if (!function_exists('mb_strlen')) {
*
* @param string $string The string being checked for length.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer The number of characters in string $string having character encoding encoding.
+ * @return int The number of characters in string $string having character encoding encoding.
* A multi-byte character is counted as 1.
*/
function mb_strlen($string, $encoding = null) {
@@ -245,9 +234,9 @@ if (!function_exists('mb_strpos')) {
*
* @param string $haystack The string being checked.
* @param string $needle The position counted from the beginning of haystack.
- * @param integer $offset The search offset. If it is not specified, 0 is used.
+ * @param int $offset The search offset. If it is not specified, 0 is used.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
+ * @return int|bool The numeric position of the first occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
@@ -263,12 +252,12 @@ if (!function_exists('mb_strrchr')) {
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
- * @param boolean $part Determines which portion of $haystack this function returns.
+ * @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string|boolean The portion of $haystack. or false if $needle is not found.
+ * @return string|bool The portion of $haystack. or false if $needle is not found.
*/
function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::strrchr($haystack, $needle, $part);
@@ -283,12 +272,12 @@ if (!function_exists('mb_strrichr')) {
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
- * @param boolean $part Determines which portion of $haystack this function returns.
+ * @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string|boolean The portion of $haystack. or false if $needle is not found.
+ * @return string|bool The portion of $haystack. or false if $needle is not found.
*/
function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::strrichr($haystack, $needle, $part);
@@ -303,9 +292,9 @@ if (!function_exists('mb_strripos')) {
*
* @param string $haystack The string from which to get the position of the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
- * @param integer $offset The position in $haystack to start searching.
+ * @param int $offset The position in $haystack to start searching.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string,
+ * @return int|bool The numeric position of the last occurrence of $needle in the $haystack string,
* or false if $needle is not found.
*/
function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
@@ -321,10 +310,10 @@ if (!function_exists('mb_strrpos')) {
*
* @param string $haystack The string being checked, for the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
- * @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
+ * @param int $offset May be specified to begin searching an arbitrary number of characters into the string.
* Negative values will stop searching at an arbitrary point prior to the end of the string.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string.
+ * @return int|bool The numeric position of the last occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
@@ -340,12 +329,12 @@ if (!function_exists('mb_strstr')) {
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack
- * @param boolean $part Determines which portion of $haystack this function returns.
+ * @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is FALSE.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return string|boolean The portion of $haystack, or true if $needle is not found.
+ * @return string|bool The portion of $haystack, or true if $needle is not found.
*/
function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::strstr($haystack, $needle, $part);
@@ -391,7 +380,7 @@ if (!function_exists('mb_substr_count')) {
* @param string $haystack The string being checked.
* @param string $needle The string being found.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
- * @return integer The number of times the $needle substring occurs in the $haystack string.
+ * @return int The number of times the $needle substring occurs in the $haystack string.
*/
function mb_substr_count($haystack, $needle, $encoding = null) {
return Multibyte::substrCount($haystack, $needle);
@@ -405,8 +394,8 @@ if (!function_exists('mb_substr')) {
* Get part of string
*
* @param string $string The string being checked.
- * @param integer $start The first position used in $string.
- * @param integer $length The maximum length of the returned string.
+ * @param int $start The first position used in $string.
+ * @param int $length The maximum length of the returned string.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string The portion of $string specified by the $string and $length parameters.
*/
@@ -424,13 +413,13 @@ if (!function_exists('mb_encode_mimeheader')) {
* @param string $str The string being encoded
* @param string $charset specifies the name of the character set in which str is represented in.
* The default value is determined by the current NLS setting (mbstring.language).
- * @param string $transfer_encoding specifies the scheme of MIME encoding.
+ * @param string $transferEncoding specifies the scheme of MIME encoding.
* It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
* @param string $linefeed specifies the EOL (end-of-line) marker with which
* mb_encode_mimeheader() performs line-folding
* (a ยป RFC term, the act of breaking a line longer than a certain length into multiple lines.
* The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
- * @param integer $indent [definition unknown and appears to have no affect]
+ * @param int $indent [definition unknown and appears to have no affect]
* @return string A converted version of the string represented in ASCII.
*/
function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
@@ -438,3 +427,15 @@ if (!function_exists('mb_encode_mimeheader')) {
}
}
+
+Configure::bootstrap(isset($boot) ? $boot : true);
+
+if (function_exists('mb_internal_encoding')) {
+ $encoding = Configure::read('App.encoding');
+ if (!empty($encoding)) {
+ mb_internal_encoding($encoding);
+ }
+ if (!empty($encoding) && function_exists('mb_regex_encoding')) {
+ mb_regex_encoding($encoding);
+ }
+}