<?php declare(strict_types=1); namespace tests; use Phpml\Classification\SVC; use Phpml\FeatureExtraction\TfIdfTransformer; use Phpml\FeatureExtraction\TokenCountVectorizer; use Phpml\Pipeline; use Phpml\Preprocessing\Imputer; use Phpml\Preprocessing\Imputer\Strategy\MostFrequentStrategy; use Phpml\Preprocessing\Normalizer; use Phpml\Regression\SVR; use Phpml\Tokenization\WordTokenizer; use PHPUnit\Framework\TestCase; class PipelineTest extends TestCase { public function testPipelineConstruction(): void { $transformers = [ new TfIdfTransformer(), ]; $estimator = new SVC(); $pipeline = new Pipeline($transformers, $estimator); $this->assertEquals($transformers, $pipeline->getTransformers()); $this->assertEquals($estimator, $pipeline->getEstimator()); }机器是由各种金属和非金属部件组装成的装置,消耗能源,可以运转、做功。它是用来代替人的劳动、进行能量变换、信息处理、以及产生有用功。机器贯穿在人类历史的全过程中。但是近代真正意义上的“机器”,却是在西方工业革命后才逐步被发明出来。
<?php namespace Flexihash\Hasher; /** * Uses CRC32 to hash a value into a signed 32bit int address space. * Under 32bit PHP this (safely) overflows into negatives ints. * * @author Paul Annesley * @license http://www.opensource.org/licenses/mit-license.php */ class Crc32Hasher implements HasherInterface { public function hash($string) { return crc32($string); } }Hash,一般翻译做“散列”,也有直接音译为“哈希”的,就是把任意长度的输入(又叫做预映射, pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值。这种转换是一种压缩映射,也就是,散列值的空间通常远小于输入的空间,不同的输入可能会散列成相同的输出,所以不可能从散列值来唯一的确定输入值。简单的说就是一种将任意长度的消息压缩到某一固定长度的消息摘要的函数。HASH函数(计算机算法领域)
<?php namespace Ricoa\CopyWritingCorrect; use Ricoa\CopyWritingCorrect\Correctors\CharacterCorrector; use Ricoa\CopyWritingCorrect\Correctors\ProperNounsCorrector; use Ricoa\CopyWritingCorrect\Correctors\SpaceCorrector; class CopyWritingCorrectService{ protected $corrects=[ ProperNounsCorrector::class, CharacterCorrector::class, SpaceCorrector::class, ]; /** * @param array $corrects */ public function resetCorrectors(array $corrects) { $this->corrects=$corrects; }统一中文文案、排版的相关用法,降低团队成员之间的沟通成本,增强网站气质。
<?php namespace BotMan\BotMan; use React\Socket\Server; use BotMan\BotMan\Http\Curl; use React\EventLoop\LoopInterface; use BotMan\BotMan\Cache\ArrayCache; use BotMan\BotMan\Drivers\DriverManager; use BotMan\BotMan\Interfaces\CacheInterface; use Symfony\Component\HttpFoundation\Request; use BotMan\BotMan\Interfaces\StorageInterface; use BotMan\BotMan\Storages\Drivers\FileStorage; class BotManFactory { private static $extensions = []; /** * @param $methodName * @param $callable */ public static function extend($methodName, $callable) { self::$extensions[$methodName] = $callable; }这是一个制作聊天机器人的库,感兴趣的朋友可以下载使用
<?php /** * @link http://github.com/zendframework/zend-cache for the canonical source repository * @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Cache; class ConfigProvider { /** * Return default configuration for zend-cache. * * @return array */ public function __invoke() { return [ 'dependencies' => $this->getDependencyConfig(), ]; } /** * Return default service mappings for zend-cache. * * @return array */ public function getDependencyConfig() { return [ 'abstract_factories' => [ Service\StorageCacheAbstractServiceFactory::class, ], 'factories' => [ PatternPluginManager::class => Service\PatternPluginManagerFactory::class, Storage\AdapterPluginManager::class => Service\StorageAdapterPluginManagerFactory::class, Storage\PluginManager::class => Service\StoragePluginManagerFactory::class, ], ]; } }大家在使用PHP的过程中,会考虑到很重要的一点就是安全性问题。那么,今天我们就来为大家介绍保证PHP安全的首要措施验证类库,数据的验证是您可能采用的最重要的习惯。而在提及输入时,十分简单:不要相信用户。在保证PHP安全而进行验证数据时,记住设计并验证应用程序允许使用的值通常比防止所有未知值更容易。
<?php namespace Cake\Validation; use ReflectionClass; class RulesProvider { /** * The class/object to proxy. * * @var mixed */ protected $_class; /** * The proxied class' reflection * * @var \ReflectionClass */ protected $_reflection; /** * Constructor, sets the default class to use for calling methods * * @param string $class the default class to proxy */ public function __construct($class = '\Cake\Validation\Validation') { $this->_class = $class; $this->_reflection = new ReflectionClass($class); }我们知道,在使用语言的过程中,肯定会关注在实际开发过程中的安全性问题。那么,今天我们就来为大家介绍保证PHP安全的首要措施验证类库,数据的验证是您可能采用的最重要的习惯。而在提及输入时,十分简单:不要相信用户。在保证PHP安全而进行验证数据时,记住设计并验证应用程序允许使用的值通常比防止所有未知值更容易。
<?php namespace Illuminate\Validation; use Illuminate\Contracts\Validation\Rule as RuleContract; class ClosureValidationRule implements RuleContract { public $callback; public $failed = false; public $message; /** * Create a new Closure based validation rule. * * @param \Closure $callback * @return void */ public function __construct($callback) { $this->callback = $callback; }我们知道,在使用语言的过程中,肯定会关注在实际开发过程中的安全性问题。就需要到我们这个验证数据的类库了。数据的验证是您可能采用的最重要的习惯。而在提及输入时,十分简单:不要相信用户。在保证PHP安全而进行验证数据时,记住设计并验证应用程序允许使用的值通常比防止所有未知值更容易。
<?php class FileInfoTest extends PHPUnit_Framework_TestCase { protected $fileWithExtension; protected $fileWithoutExtension; public function setUp() { $this->fileWithExtension = new \Upload\FileInfo(dirname(__FILE__) . '/assets/foo.txt', 'foo.txt'); $this->fileWithoutExtension = new \Upload\FileInfo(dirname(__FILE__) . '/assets/foo_wo_ext', 'foo_wo_ext'); } public function testConstructor() { $this->assertAttributeEquals('foo', 'name', $this->fileWithExtension); $this->assertAttributeEquals('txt', 'extension', $this->fileWithExtension); $this->assertAttributeEquals('foo_wo_ext', 'name', $this->fileWithoutExtension); $this->assertAttributeEquals('', 'extension', $this->fileWithoutExtension); }我们知道,在使用语言的过程中,肯定会关注在实际开发过程中的安全性问题。那么,今天我们就来为大家介绍保证PHP安全的首要措施——验证数据。数据的验证是您可能采用的最重要的习惯。而在提及输入时,十分简单:不要相信用户。在保证PHP安全而进行验证数据时,记住设计并验证应用程序允许使用的值通常比防止所有未知值更容易。下面列出了适用于各种验证数据的一般验证提示:1. 使用白名单中的值2. 始终重新验证有限的选项3. 使用内置转义函数4. 验证正确的数据类型(如数字)白名单中的值(White-listed value)是正确的值,与无效的黑名单值(Black-listed value)相对。两者之间的区别是,通常在进行验证数据时,可能值的列表或范围小于无效值的列表或范围,其中许多值可能是未知值或意外值。
<?php /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require __DIR__.'/classes/Swift.php'; Swift::registerAutoload(function () { // Load in dependency maps require __DIR__.'/dependency_maps/cache_deps.php'; require __DIR__.'/dependency_maps/mime_deps.php'; require __DIR__.'/dependency_maps/message_deps.php'; require __DIR__.'/dependency_maps/transport_deps.php'; // Load in global library preferences require __DIR__.'/preferences.php'; });这个库与phpmailer作用一样,但性能比phpmailer好,尤其是在处理附件的能力上,发送邮件成功的几率也高
<?php /* * This file is part of the Stash package. * * (c) Robert Hafner <tedivm@tedivm.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ spl_autoload_register(function ($class) { $base = '/src/'; if (strpos($class, 'Stash\Test') === 0) { $base = '/tests/'; } $file = __DIR__.$base.strtr($class, '\', '/').'.php'; if (file_exists($file)) { require $file; return true; } });为什么要缓存查询结果?缓存查询结果能极大地改进脚本执行时间和资源需求。缓存SQL查询结果也允许你通过后期处理数据。如果你用文件缓存去存储全部脚本的输出结果(HTML正常的方法是非常占用资源并且相反的影响了脚本的性能。只能通过取得的大量返回数据和数据库服务器的位置这二个要素来相互协调。尽管持续连接可以改进连接数据库时的负载,但非常耗费内存资源,如果获取的是大量的数据,那么存储的全部时间会非常短暂。所以StashPHP缓存库就是专门解决PHP里的这个缓存问题。
<?php if (!isset($argv[1]) || $argv[1] === '-h' || $argv[1] === '--help') { echo 'usage: php ' . $argv[0] . ' <version> <stability>' . PHP_EOL; echo PHP_EOL; echo ' version:' . PHP_EOL; echo ' Version of the package, in the form of major.minor.bug' . PHP_EOL; echo PHP_EOL; echo ' stability:' . PHP_EOL; echo ' One of alpha, beta, stable' . PHP_EOL; die(); } if (!isset($argv[2])) { die('You must provide the stability (alpha, beta, or stable)'); } $context = array( 'date' => gmdate('Y-m-d'), 'time' => gmdate('H:m:00'), 'version' => $argv[1], 'api_version' => $argv[1], 'stability' => $argv[2], 'api_stability' => $argv[2], );Requests-1.7.0HTTP库是一个PHP的HTTP类库。相对于cURL等类库来说,它具有简单易用且友好的API,且不依赖于cURL。它支持HEAD、 GET、 POST、 PUT、 DELETE和PATCH等方法,基本能满足任何形式的HTTP请求。Requests不依赖于任何PHP标准库外的扩展,唯一的要求就是需要PHP5.2 的版本。但是如果PHP的cURL可用,Requests会优先使用它,否则会使用socket。
<?php namespace Illuminate\Tests\Support; use stdClass; use ArrayAccess; use Mockery as m; use ReflectionClass; use JsonSerializable; use PHPUnit\Framework\TestCase; use Illuminate\Support\Collection; use Illuminate\Contracts\Support\Jsonable; use Illuminate\Contracts\Support\Arrayable; class SupportCollectionTest extends TestCase { public function testFirstReturnsFirstItemInCollection() { $c = new Collection(['foo', 'bar']); $this->assertEquals('foo', $c->first()); } public function testFirstWithCallback() { $data = new Collection(['foo', 'bar', 'baz']); $result = $data->first(function ($value) { return $value === 'bar'; }); $this->assertEquals('bar', $result); }PHP的Laravel集合库是获取一个集合的库,一个集合相当于一张表。