# Injection

Sometimes you need to add some text content to an already existing file.

It is possible using injections.

Let's say we have a PHP class named _CartRenderer_ like the following:

{% code title="CartRenderer.php" %}
```php
<?php
class CartRenderer
{
}
```
{% endcode %}

### After

In the following example we insert the _interface implementation_ after the class name.

```
---
to: CartRenderer.php
inject: true
after: /^class .*/mi
---
{{ ' ' }}implements SingletonInterface
```

### Before

This injection can also be done using the `before` setting.

This example inserts the _final_ keyword before the class declaration.

```
---
to: CartRenderer.php
inject: true
before: /^class .*/mi
---
final{{ ' ' }}
```

### Replace

This injection mode replace the actual match of the regex.

```
---
to: CartRenderer.php
inject: true
replace: /^final class/m
---
abstract class
```

### Conditional injection

And last, we can skip any injections using the `skip_if` setting:

```
---
to: CartRenderer.php
inject: true
before: /^class .*/mi
skip_if: /^final class/mi
---
final{{ ' ' }}
```
