手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表分类:PHP

composer引用本地git做为源库

PHP使用者大多对composer是又爱又恨,爱的是composer require后,很多类库不用去下载了,恨的是网速卡成翔,虽然国内有很多道友做了镜象,但对于bower库这些都还是整体更新。

那么,如何只利用composer的基本功能来为自己服务呢?composer的官网有介绍,只要在composer.json中加入几行代码就行了。。

JavaScript代码
  1. "repositories":[  
  2.        {  
  3.            "type":"git",  
  4.            "url":"/var/www/gouki/test/"  
  5.        },  
  6.    ]  

上面的代码中/var/www/gouki/test,是我的一个git库。也是按照composer的标准来建的。里面只有一个composer.json文件:

JavaScript代码
  1. {  
  2.     "name":"gouki/test",  
  3.     "description":"test",  
  4.     "authors":[  
  5.         {  
  6.             "name":"gouki",  
  7.             "email":"xxxx@qq.com"  
  8.         }  
  9.     ],  
  10.     "minimum-stability":"dev",  
  11.     "require":{},  
  12.     "autoload":{  
  13.         "psr-4":{  
  14.             "gouki\\test\\":"src/" 
  15.         } 
  16.     }, 
  17.     "extra":{ 
  18.         "branch-alias":{ 
  19.             "dev-master":"1.0.x-dev"  
  20.         }  
  21.     }  
  22. }  

src目录下的代码中使用的namespace就是gouki\test,然后在原项目的composer.json中再加入:

JavaScript代码
  1. "require":{  
  2.         "gouki/test":"dev-master"  
  3.     },  

最后,运行一下composer update,你会看到项目的根目录下多了vendor目录,同时,vendor目录下也会多一个gouki/test的目录,至此项目引入成功,如果还不放心,那就看一下:vendor/composer/autoload_psr4.php中有没有gouki/test。

之所以这么做,就是因为前文所说的速度,当然也有小团队的成本。比如写个类,就可以直接composer进行加载了。

问题就这么来了,如果放到线上去,那上面的

XML/HTML代码
  1. "repositories":[    
  2.        {    
  3.            "type":"git",    
  4.            "url":"/var/www/gouki/test/"    
  5.        },    
  6.    ]   
  7. 需要改为:  
  8. "repositories":[    
  9.        {    
  10.            "type":"git",    
  11.            "url":"http://xxxx.xxx.xxx/git"    
  12.        },    
  13.    ]     

如果该git是public的,则不需要任何处理,如果git是需要登录的,则需要在项目的根目录下(和composer.json平级的目录)增加一个auth.json,里面也就两三行代码

JavaScript代码
  1. {    
  2.     "http-basic":{    
  3.         "http://xxxx.xxx.xxx/git":{    
  4.             "username":"",    
  5.             "password":""    
  6.         }    
  7.     }    
  8. }    

当然如果你是ssh免登陆的git则另计。至此一个小小的自建composer源就已经完成。

Composer的Illegal offset type in isset or empty

标题的内容也是手贱导致的,本来composer不self-update也不会出现这个问题,这不,一升到最新的composer就出问题了

1、由于我们为了追求速度,大部分都是用的国内的源,这些源往往都不是https的,这回好了,出错了。
XML/HTML代码
  1. Your configuration does not allow connection to http://packagist.phpcomposer.com. See https://getcomposer.org/doc/06-config.md#secure-http for details.  
  2. http://packagist.phpcomposer.com could not be fully loaded, package information was loaded from the local cache and may be out of date  
OK,打开https://getcomposer.org/doc/06-config.md#secure-http查看了一下,在composer.json和~/.composer/config.json中的config节点下,增加:"secure-http":false
 
2、composer update的时候报:
XML/HTML代码
  1. Installation failed, reverting ./composer.json to its original content.  
OK,现在可以用composer diag来检查 一下了,结果 发现:
XML/HTML代码
  1.  composer diag  
  2. Checking composer.json: FAIL  
  3. No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.  
  4. require.yiisoft/yii2 : unbound version constraints (*) should be avoided  
  5. Checking platform settings: OK  
  6. Checking git settings: OK  
  7. Checking http connectivity to packagist: OK  
  8. Checking https connectivity to packagist: OK  
  9. Checking github.com oauth access: OK  
  10. Checking disk free space: OK  
  11. Checking pubkeys:  
  12. Tags Public Key Fingerprint: ???? 已隐藏  
  13. Dev Public Key Fingerprint: ????? 已隐藏  
  14. OK  
  15. Checking composer version: FAIL  
  16. You are not running the latest stable version, run `composer self-update` to update (e8b1a5f35772e39ca21ab855a278bd84a0a534b2 => 1.0.0-beta2)  
居然显示 ,composer中一定要有license节点,require的也需要带 版本号了。于是一一加上,然后接着composer update
 
3、出现如标题一般的错误 
处理方法:一般出现这种错误 ,大部分情况下是fxp插件需要更新了,执行composer global require fxp/composer-asset-plugin --prefer-dist,
 
XML/HTML代码
  1. Changed current directory to /Users/gouki/.composer  
  2. Using version ^1.1 for fxp/composer-asset-plugin  
  3. ./composer.json has been updated  
  4. Loading composer repositories with package information  
  5. Updating dependencies (including require-dev)  
  6.   - Removing fxp/composer-asset-plugin (v1.1.1)  
  7.   - Installing fxp/composer-asset-plugin (v1.1.2)  
  8.     Downloading: 100%  
  9.   
  10. Writing lock file  
  11. Generating autoload files  
更新完后,再composer udpate就OK了!
当然如果还有问题,你应该查看官网的issue,比如:https://github.com/francoispluchino/composer-asset-plugin/issues/191,刚开始的时候确实是BUG,后面更新了就好了。哈哈
 

The file or directory to be published does not exist: vendor/bower/jquery/dist

 标题所说的问题可能早期用户都遇到过。但其实这个问题在官方也早就有解决方案了,不知道为什么还有人问起。

这其实是与:fxp/composer-asset-plugin 相关的一个BUG,你在global require的时候,用1.1的beta版就没问题了。
很简单就能发现这个问题了,你先:composer global require "fxp/composer-asset-plugin:~1.1.1",然后composer install就OK了。
其实你如果每次composer update报这个错,你就应该有警惕了:
XML/HTML代码
  1. Deprecation Notice: The Composer\Package\LinkConstraint\MultiConstraint class is deprecated, use Composer\Semver\Constraint\MultiConstraint instead. in phar:///usr/local/bin/compose  
  2. r/src/Composer/Package/LinkConstraint/MultiConstraint.php:17  
  3. Deprecation Notice: The Composer\Package\LinkConstraint\LinkConstraintInterface interface is deprecated, use Composer\Semver\Constraint\ConstraintInterface instead. in phar:///usr/l  
  4. ocal/bin/composer/src/Composer/Package/LinkConstraint/LinkConstraintInterface.php:17  
当然如果你操作完后还是没看到有任何反应,OK,先清除cache......
不多说,Over
 

imageworkshop中的position的说明及代码

position有9个点:lt,mt,rt,lm,mm,rm,lb,mb,rb,其实对应的是几个英文:lt(left top),mt(middle top),rt(right top),以此类推

上官方原图:

大小: 49.72 K
尺寸: 376 x 376
浏览: 2405 次
点击打开新窗口浏览全图

OK,然后我们看一下他的代码是怎么写的,如果有人涉及到也可以借鉴:

 

PHP代码
  1. <?php  
  2.   
  3. /** 
  4.      * Calculate the left top positions of a layer inside a parent layer container 
  5.      * $position: http://phpimageworkshop.com/doc/22/corners-positions-schema-of-an-image.html 
  6.      * 
  7.      * @param integer $containerWidth 
  8.      * @param integer $containerHeight 
  9.      * @param integer $layerWidth 
  10.      * @param integer $layerHeight 
  11.      * @param integer $layerPositionX 
  12.      * @param integer $layerPositionY 
  13.      * @param string $position 
  14.      * 
  15.      * @return array 
  16.      */  
  17.     public static function calculatePositions($containerWidth$containerHeight$layerWidth$layerHeight$layerPositionX$layerPositionY$position = 'LT')  
  18.     {  
  19.         $position = strtolower($position);  
  20.   
  21.         if ($position == 'rt') {  
  22.   
  23.             $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;  
  24.   
  25.         } elseif ($position == 'lb') {  
  26.   
  27.             $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;  
  28.   
  29.         } elseif ($position == 'rb') {  
  30.   
  31.             $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;  
  32.             $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;  
  33.   
  34.         } elseif ($position == 'mm') {  
  35.   
  36.             $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;  
  37.             $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;  
  38.   
  39.         } elseif ($position == 'mt') {  
  40.   
  41.             $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;  
  42.   
  43.         } elseif ($position == 'mb') {  
  44.   
  45.             $layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;  
  46.             $layerPositionY = $containerHeight - $layerHeight - $layerPositionY;  
  47.   
  48.         } elseif ($position == 'lm') {  
  49.   
  50.             $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;  
  51.   
  52.         } elseif ($position == 'rm') {  
  53.   
  54.             $layerPositionX = $containerWidth - $layerWidth - $layerPositionX;  
  55.             $layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;  
  56.         }  
  57.   
  58.         return array(  
  59.             'x' => $layerPositionX,  
  60.             'y' => $layerPositionY,  
  61.         );  
  62.     }  

END;

 

 

 

Tags: imageworkshop, position

access-control-allow-origin-multiple-origin-domains

原文来自:http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains

主要是因为涉及到CSS和JS文件是挂在别的域,然后又遇到了ajax之类的操作,所以就需要有跨域操作了,本来很方便的,只是在.htaccess文件中加了一句
XML/HTML代码
  1. Header add Access-Control-Allow-Origin "http://xxxxxx.com"  
但因为备案原因,所以又添加了一个备用域名,结果,就报错了,报错提示是:
XML/HTML代码
  1. font from origin 'http://xxxxx.com' has been blocked from loading by Cross-Origin Resource Sharing policy: The 'Access-Control-Allow-Origin' header contains multiple values 'http://yyyy.com, http://zzzz.com', but only one is allowed. Origin 'http://xxxxx.com' is therefore not allowed access.  
我晶,不支持多域名啊,google了一下,找到了这一篇:http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains
 
不多贴,其实挺有意思。。方法也有不少
1、利用apache的环境变量:
XML/HTML代码
  1. SetEnvIf Origin "^(.*\.example\.com)$" ORIGIN_SUB_DOMAIN=$1  
  2. <FilesMatch "\.woff$">  
  3.     Header set Access-Control-Allow-Origin "%{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN  
  4. </FilesMatch>  
2、用PHP来判断:
PHP代码
  1. $http_origin = $_SERVER['HTTP_ORIGIN'];  
  2.   
  3. if ($http_origin == "http://www.domain1.com" || $http_origin == "http://www.domain2.com" || $http_origin == "http://www.domain3.info")  
  4. {    
  5.     header("Access-Control-Allow-Origin: $http_origin");  
  6. }  
3、和1有点类似
XML/HTML代码
  1. SetEnvIf Origin "^http(s)?://(.+\.)?(domain\.org|domain2\.com)$" origin_is=$0   
  2. Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is  
4、这是nginx的:
XML/HTML代码
  1. location /fonts {  
  2.     # this will echo back the origin header  
  3.     if ($http_origin ~ "example.org$") {  
  4.         add_header "Access-Control-Allow-Origin" $http_origin;  
  5.     }  
  6. }  
更多的,还是去原网页看吧。。