PHPackages                             cw/tool - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cw/tool

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cw/tool
=======

v3.x-dev(9y ago)22942[1 issues](https://github.com/cameronandwilding/CWTool/issues)[1 PRs](https://github.com/cameronandwilding/CWTool/pulls)PHP

Since Aug 17Pushed 9y ago6 watchersCompare

[ Source](https://github.com/cameronandwilding/CWTool)[ Packagist](https://packagist.org/packages/cw/tool)[ RSS](/packages/cw-tool/feed)WikiDiscussions v3.1 Synced today

READMEChangelogDependencies (4)Versions (17)Used By (0)

CW Tool (Drupal structuring and utility framework)
==================================================

[](#cw-tool-drupal-structuring-and-utility-framework)

- Drupal 7: [![Build Status](https://camo.githubusercontent.com/aae959c2b608d6437686a57cffc61696160b74547f9ea7d6b259a68dc526c231/68747470733a2f2f7472617669732d63692e6f72672f63616d65726f6e616e6477696c64696e672f4357546f6f6c2e706e673f6272616e63683d76332e31)](https://travis-ci.org/cameronandwilding/CWTool)
- Drupal 8: [![Build Status](https://camo.githubusercontent.com/9fb4329b70a50077330bd53e4035279d277bb22af34224afcdae48ff1563567f/68747470733a2f2f7472617669732d63692e6f72672f63616d65726f6e616e6477696c64696e672f4357546f6f6c2e706e673f6272616e63683d382e782d312e30)](https://travis-ci.org/cameronandwilding/CWTool)

What does it do?
================

[](#what-does-it-do)

CWTool has 2 main purpose. First it is a structuring framework over the Drupal API. Second it is a helper library for PHP and Drupal.

Why Drupal needs a structuring framework? Drupal (especially the 7th version) uses associated arrays everywhere, and even the more object oriented parts of it is mostly a bunch of loosely coupled weak objects. As an example nodes are plain PHP objects containing numerous associated arrays. Work with node objects are dangerous and not sustainable. Wrapping them into controllers and models however gives you well defined business layer and safety.

Another example is forms. In a old fashioned Drupal project forms are defined and altered in hooks and plain functions without much organization. Form classes and form extenders can help creating cohesive classes and reducing redundant code to the minimum.

Other than providing classes for building up a business domain CWTool intend to provide the Drupal API through adapters to increase testability of the business layer. For example entity API and variable handling is via adaptors, which means the Drupal implementation is just one version and you can override it anytime.

And possibly a +1 purpose of CWTool is to provide dependency injection to the application via a service container. Using services from DI allows the app (and developers) to switch and replace services (such as logging, variable handling, object loading, caching - to name a few) without much hassle.

The utility part of CWTool is a pure helper function library to speed up development time by reducing redundant and error prone code. There are various utilities for strings, arrays, dates, functional style code, etc.

Common use of CWTool in a generic Drupal (7) application
========================================================

[](#common-use-of-cwtool-in-a-generic-drupal-7-application)

- install module (with dependencies)
- make a dedicated app module (with composer + PSR4 autoloading)
- implement the [service container hook](docs/DependencyInjection.md) for DI
- use the [Drush tool](src/CW/Drush/DrushDefinition.php) to generate all the node, user and taxonomy controllers and put it into `src/Controller//.php`
- create the necessary template processors and create [processor classes](docs/Theme.md) for each
- implement the [variable collector hook](docs/Variables.md) and add all app variables

For utilities the best is to go through of the documentation, tests and source code to see what is available. If you don't find what you need: add it, commit it and write a test for it.

Install
-------

[](#install)

- copy the module into the modules folder
    - even better if you add it as a git submodule
    - even better through composer: `composer require cw/tool`
- update composer dependencies:
    - `composer update` in the module folder
- enable cw\_tool module
    - `drush en cw_tool`

Main features
-------------

[](#main-features)

- [Dependency injection layer](docs/DependencyInjection.md)
- [Entity controllers and factories](docs/EntityController.md)
- [Entity creators](docs/Creators.md)
- [Site variable and its form handlers](docs/Variables.md)
- [Forms](docs/Forms.md)
- [Theme and template management](docs/Theme.md)
- [Generic model interface](docs/Model.md)
- [Blocks](docs/Block.md)
- Structural aid:
    - [Self factory](src/CW/Factory/SelfFactory.php)
- Utilities:
    - [Arrays](docs/ArrayUtil.md)
    - [Functionals](docs/FunctionalUtil.md)
    - [Page request](docs/Request.md)

Drush commands
--------------

[](#drush-commands)

**Entity controller class scaffolding**

Creates boilerplate PHP class code for bootstrapping.

```
drush cwt-sc-ctrl node blog --namespace=My\\Namespace
```

General development guidelines
------------------------------

[](#general-development-guidelines)

**Use entities via their controllers**

Entities should have their own controller, and loaded with the controller factory.

**Controller should contain the minimum necessary behavior**

Controllers suppose to contain data access and minimum business logic. Controller should not generate themed output. Controller should not sanitize it's content.

Controller should hold the field names (as constants), property or state constants.

For extra behavior (such as controller rendered output, forms, ets) there should be a dedicated class implementing ControllerAware or ControllerContainer.

**Services over static classes**

When new class needed to wrap a functionality, a new service is preferred. Usually they contain a logger at least.

**Param objects over arrays**

Avoid using arrays as argument. Make a parameter object instead.

**Always use the structuring classes where available**

- for new forms use `FormBulider`
- for template (pre)processors use `AbstractThemeProcessor`
- for blocks use `Block`
- for form states use `FormState` or `NodeFormState`

**Avoid code in hooks**

Only keep proxy calls in hooks to the appropriate classes, but no logic at all.

Documentation
-------------

[](#documentation)

Execute Doxygen generator:

`doxygen Doxygen`

The Doxygen binary is a requirement.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~265 days

Total

3

Last Release

3383d ago

Major Versions

2.x-dev → v3.x-dev2016-07-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc6eae8e55920207c5e755223dc1e700381d8551c3e1edc071b140f38d29b59d?d=identicon)[itarato](/maintainers/itarato)

---

Top Contributors

[![itarato](https://avatars.githubusercontent.com/u/49009?v=4)](https://github.com/itarato "itarato (299 commits)")[![blairwadman](https://avatars.githubusercontent.com/u/432244?v=4)](https://github.com/blairwadman "blairwadman (8 commits)")[![mike1937](https://avatars.githubusercontent.com/u/1544633?v=4)](https://github.com/mike1937 "mike1937 (7 commits)")

### Embed Badge

![Health badge](/badges/cw-tool/health.svg)

```
[![Health](https://phpackages.com/badges/cw-tool/health.svg)](https://phpackages.com/packages/cw-tool)
```

###  Alternatives

[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k53](/packages/friendsoftypo3-content-blocks)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[oat-sa/tao-core

TAO core extension

66143.7k122](/packages/oat-sa-tao-core)[blackfire/player

A powerful web crawler and web scraper with Blackfire support

49617.1k](/packages/blackfire-player)[altis/local-server

Local Server module for Altis

18221.6k3](/packages/altis-local-server)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
