Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added ServerShell for PHP Built-in Server #713

Closed
wants to merge 14 commits into
from

Conversation

Projects
None yet
8 participants
Contributor

shin1x1 commented Jul 11, 2012

Hi, I would propose adding new Shell Command.It is ServerShell.

ServerShell provides a httpd server for CakePHP application without other httpd server(Apache, nginx etc).

It is use PHP CLI build-in server.

Use case is below.

1. default (http://localhost/)

$ cd /path/to/app
$ ./Console/cake server

Welcome to CakePHP v2.2.0 Console
---------------------------------------------------------------
App : app
Path: /path/to/app/
---------------------------------------------------------------
ServerHost  : localhost
ListenPort  : 80
DocumentRoot: /path/to/app/webroot
---------------------------------------------------------------
[WARNING] Don't use this at the production enviroment
built-in server is running...

2. specify ListenPort (http://localhost:8000/)

$ ./Console/cake server -p 8000

Welcome to CakePHP v2.2.0 Console
---------------------------------------------------------------
App : app
Path: /path/to/app/
---------------------------------------------------------------
ServerHost  : localhost
ListenPort  : 8000
DocumentRoot: /path/to/app/webroot
---------------------------------------------------------------
[WARNING] Don't use this at the production enviroment
built-in server is running...

3. usage

$ ./Console/cake -h

Welcome to CakePHP v2.2.0 Console
---------------------------------------------------------------
App : app
Path: /Users/shin/sandbox/cakephp_shin1x1/app/
---------------------------------------------------------------
PHP Built-in Server for CakePHP

Usage:
cake server [-h] [-v] [-q] [-H] [-p] [-d]

Options:

--help, -h           Display this help.
--verbose, -v        Enable verbose output.
--quiet, -q          Enable quiet output.
--host, -H           ServerHost
--port, -p           ListenPort
--document_root, -d  DocumentRoot 

4. PHP 5.3 or lower

$ ./Console/cake server

Welcome to CakePHP v2.2.0 Console
---------------------------------------------------------------
App : app
Path: /path/to/app/
---------------------------------------------------------------
ServerHost  : localhost
ListenPort  : 80
DocumentRoot: /path/to/app/webroot
---------------------------------------------------------------
This command is available on PHP5.4 or above    
Member

burzum commented Jul 11, 2012

+1 but give it a better name like PhpWebserverShell and change the pull request to merge it into 2.3, not master.

Member

rchavik commented Jul 11, 2012

Can we have shorter output, say:

    Welcome to CakePHP v2.2.0 Console
    ---------------------------------------------------------------
    App : app
    Path: /path/to/app/
    DocumentRoot: /path/to/app/webroot
    ---------------------------------------------------------------
    built-in server is running in http://somelocalsite.dev:80/

Also, [WARNING] Don't use this at the production enviroment is just noise imo, and should be documented in docs, not on each run.

@lorenzo lorenzo and 1 other commented on an outdated diff Jul 11, 2012

lib/Cake/Console/Command/ServerShell.php
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+
+App::uses('AppShell', 'Console/Command');
+
+/**
+ * built-in Server Shell
+ *
+ * @package Cake.Console.Command
+ */
+class ServerShell extends AppShell {
+ const DEFAULT_HOST = 'localhost';
+ const DEFAULT_PORT = 80;
+
+ /**
+ * server host
@lorenzo

lorenzo Jul 11, 2012

Owner

This is not our indentation style for comments.

@shama

shama Jul 11, 2012

Contributor

Also please use hard tabs rather then spaces.

@lorenzo lorenzo commented on an outdated diff Jul 11, 2012

lib/Cake/Console/Command/ServerShell.php
+ * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org CakePHP(tm) Project
+ * @since CakePHP(tm) v 1.2.0.5012
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+
+App::uses('AppShell', 'Console/Command');
+
+/**
+ * built-in Server Shell
+ *
+ * @package Cake.Console.Command
+ */
+class ServerShell extends AppShell {
+ const DEFAULT_HOST = 'localhost';
+ const DEFAULT_PORT = 80;
@lorenzo

lorenzo Jul 11, 2012

Owner

Missing doc blocks for constants

@lorenzo lorenzo and 3 others commented on an outdated diff Jul 11, 2012

lib/Cake/Console/Command/ServerShell.php
+/**
+ * built-in Server Shell
+ *
+ * Implementation of a Cake Shell to show CakePHP core method signatures.
+ *
+ * PHP 5
+ *
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org CakePHP(tm) Project
+ * @since CakePHP(tm) v 1.2.0.5012
@lorenzo

lorenzo Jul 11, 2012

Owner

1.2.0? You were a visionaire hehe, just select a correct version and year please :P

@huoxito

huoxito Jul 11, 2012

Contributor

I wonder if Im the only one who thinks all those license info on every CakePHP class are so useless .. I mean docs for methods and classes are great but that, what is that for? ps no big deal anyway

@jeremyharris

jeremyharris Jul 11, 2012

Contributor

I think the idea is that each file needs to contain it so if a file is copied elsewhere, the license follows that file. Prevents people from disassembling pieces of the core code and changing the license to something else.

@burzum

burzum Jul 12, 2012

Member

Exactly.

@lorenzo lorenzo commented on an outdated diff Jul 11, 2012

lib/Cake/Console/Command/ServerShell.php
+ $parser = parent::getOptionParser();
+
+ $parser->addOption('host', array(
+ 'short' => 'H',
+ 'help' => __d('cake_console', 'ServerHost')
+ ));
+ $parser->addOption('port', array(
+ 'short' => 'p',
+ 'help' => __d('cake_console', 'ListenPort')
+ ));
+ $parser->addOption('document_root', array(
+ 'short' => 'd',
+ 'help' => __d('cake_console', 'DocumentRoot')
+ ));
+
+ $parser->description(__('PHP Built-in Server for CakePHP'));
@lorenzo

lorenzo Jul 11, 2012

Owner

All other strings are using __d, why not this one?

@lorenzo lorenzo commented on the diff Jul 11, 2012

app/webroot/index.php
@@ -70,6 +70,11 @@
define('WWW_ROOT', dirname(__FILE__) . DS);
}
+// for built-in server
@lorenzo

lorenzo Jul 11, 2012

Owner

If you change this file, please also change the file in Cake/Console/Templates/skel

markstory added some commits Jul 11, 2012

Type check before unset()
Calling unset() on string indices fails fatally on 5.3.x and lower.

Fixes #3027

@shama shama commented on an outdated diff Jul 11, 2012

app/webroot/index.php
@@ -70,6 +70,11 @@
define('WWW_ROOT', dirname(__FILE__) . DS);
}
+// for built-in server
+if (php_sapi_name() == 'cli-server') {
+ $_SERVER['PHP_SELF'] = '/'.basename(__FILE__);
@shama

shama Jul 11, 2012

Contributor

Indentation is off here, Cake uses hard tabs.

@shama shama and 1 other commented on an outdated diff Jul 11, 2012

lib/Cake/Console/Command/ServerShell.php
+ $this->out(__d('cake_console', '<warning>This command is available on PHP5.4 or above</warning>'));
+ return;
+ }
+
+ $this->out(__d('cake_console', 'ServerHost : %s', $this->_host));
+ $this->out(__d('cake_console', 'ListenPort : %d', $this->_port));
+ $this->out(__d('cake_console', 'DocumentRoot: %s', $this->_documentRoot));
+ $this->hr();
+
+ $command = sprintf("php -S %s:%d -t %s",
+ $this->_host,
+ $this->_port,
+ $this->_documentRoot
+ );
+
+ $this->out(__d('cake_console', '<warning>[WARNING] Don\'t use this at the production enviroment</warning>'));
@shama

shama Jul 11, 2012

Contributor

Typo; should be environment. Although I agree with @rchavik about excluding this message all together. :)

@markstory

markstory Jul 12, 2012

Owner

I like this warning, external docs are good, but hitting people on the head everytime they run this is good as well.

@shama shama commented on an outdated diff Jul 11, 2012

lib/Cake/Console/Command/ServerShell.php
+ *
+ * @package Cake.Console.Command
+ */
+class ServerShell extends AppShell {
+ const DEFAULT_HOST = 'localhost';
+ const DEFAULT_PORT = 80;
+
+ /**
+ * server host
+ *
+ * @var string
+ */
+ protected $_host = null;
+
+ /**
+ * listern port
@shama

shama Jul 11, 2012

Contributor

Typo, should be listen.

Owner

markstory commented Jul 12, 2012

This change is also similar to #634

Contributor

shin1x1 commented Jul 12, 2012

Thanks for all the comments!
I will fix comment, indentation, tab, and typo:D

@burzum Hi, I change the pull request to 2.3 branch.
thank you new name! PhpWebserverShell is a good name.

but I will enter many characters.

$ ./Console/cake php_web_server

ServerShell is shorter.

$ ./Console/cake server

@rchavik good idea! I try to shorter output message.

Member

burzum commented Jul 12, 2012

@shin1x1 I clearly prefer to type a few characters more in favor for a better variable, class or shell name than ending up with non specific and generic names. To be honest, at least for me, and I do not think for any person who's programming for some time it really doesn't matter if you type 6 or 12 chars.

Owner

markstory commented Jul 13, 2012

I'd rather have the shorter name personally. php_web_server is a bit redundant, what other kind of server would you be starting other than a php + web server?

Member

rchavik commented Jul 13, 2012

how about http_server ?

also, is it possible to squash these commits in a logical chunks?

Member

rchavik commented Jul 13, 2012

nevermind about the squash, i just saw your #714. nice.

@rchavik rchavik closed this Jul 13, 2012

Contributor

shin1x1 commented Jul 14, 2012

@burzum I think that variable, class name should be a specific, too. I type a few chars with code completion(Vim, Emacs, Eclipse). But shell name is need to enter full chars. so, I like short name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment