prokhonenkov/yii2-word-counter

The word counter

1.0 2020-02-11 04:03 UTC

This package is auto-updated.

Last update: 2024-11-11 15:19:13 UTC


README

This extension count words and sort them by the number and alphabet.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require prokhonenkov/yii2-word-counter 

or add

"prokhonenkov/yii2-word-counter": "*"

to the require section of your composer.json file.

Configuration

Add component declaration to your config file for console config:

<?php

return [
    // ... your config
    'components' => [
        'wordCounter' => [
            'class' => \prokhonenkov\wordcounter\WordCounter::class,
        ],
    ]
];

Usage

Pass filepath to setFilePath method and invoke count method.

class TextController extends \yii\console\Controller
{
    public function actionCountWords(string $fileName)
    {
        $result = \Yii::$app->wordCounter
			->setFilePath($fileName)
			->count();

        print_r($result);
    }
}