<?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集合庫是取得一個集合的函式庫,一個集合相當於一張表。