再说Windows下使用solar

前面我有篇博文“也说windows下使用Solar”中讲到,通过在/docroot/index.php文件中加入一段小代码可以浏览你的应用,但是现在在windows下使用Solar是不明智的。今天我要否决这个观点,solar-phper的福音到了。现在你可以在windows下布署并开发solar了。特别提醒:必须是windows vista以上的版本才支持类似于unix风格的symlink。

最应该感谢的是Sanakan,它在也说windows下使用SolarWindows XP下junction工具和Solar 两篇帖子中阐明了整个过程,做出了重要贡献。

首先,为了能够浏览Solar应用,你仍需要在/docroot/index.php文件中加入条件:

if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
   // windows doesn't like the default symlinks
   set_include_path("$system/include;$system/source/solar");
} else {
   // unix
   set_include_path("$system/include");
}

其次就是CLI了,打开/script/solar文件,找到17行,修改$dirs数组:

if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
 $vendor_dir = $vendor?"\\$vendor":$vendor;
    $dirs = array(
        // source solar
       "\source\solar\script\solar",
     // source vendor
      "\source".$vendor_dir."\script".$vendor,
      // copy solar
     "\scrip\solar",
       // copy vendor
        "\script".$vendor_dir,
    );
} else {
  $dirs = array(
        // symlink solar
      "/source/solar/script/solar",
     // symlink vendor
     "/source/$vendor/script/$vendor",
     // copy solar
     "/scrip/solar",
       // copy vendor
        "/script/$vendor",
    );
}

找到72行,把include-path修改为:

if ($system) {
    if (strtolower(substr(PHP_OS, 0, 3)) == 'win') {
       // windows doesn't like the default symlinks
       $include = "$system/include;$system/source/solar;.";
    } else {
       // unix, yay
       $include = "$system/include:.";
    }
} else {
    $include = get_include_path();
}

现在你就可以在command里创建vendor、model和app了。 首先进入到script目录,然后使用命令make-***即可,如下:

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\ROY>d:

D:\>cd wamp\www\solar\script

D:\wamp\www\solar\script>php solar make-model Acme_Model_Tosts --table blogs
Making model 'Acme_Model_Tosts'.
Will write to 'D:\wamp\www\solar\include\'.
Using table 'blogs'.
Not using inheritance.
Making class directory ... done.
Writing model class ... done.
Writing record class ... done.
Writing collection class ... done.
Connecting to database for metadata ...connected.
Fetching table cols ... done.
Fetching index info ... no indexes found.
Writing metadata class ... done.
Creating locale directory ... done.
Saving locale file for en_US ... done.
Done.

当然,你需要先把php.exe的路径放到环境变量中,否是会提示command not found.