Sunil Rawat
Sunil Rawat

Reputation: 709

call a Method from One Repository to another Repository Symfony2

Hi I am using symfony2 With ODM, I want to call a function from one reposotory to another repository to re-use it. I did not get a way to call it directly.

Following my code.

//My LedgerRepository.php

class LedgerRepository extends DocumentRepository
{

public function ProfitLoss(){
//Some re-usable code

  }
 }

//My BudgetRepository.php

class BudgetRepository extends DocumentRepository
{
 //So here I want to call method ProfitLoss() from LedgerRepository


}

how to make it possible please guide.

Thanks advance

Upvotes: 0

Views: 586

Answers (1)

nurikabe
nurikabe

Reputation: 4010

In this case good old inheritance may come to the rescue. Both Ledger and Budget deal with financial transactions. Why not this?:

class TransactionsRepository extends DocumentRepository
{
    public function ProfitLoss() {}
}

class LedgerRepository extends TransactionsRepository {}
class BudgetRepository extends TransactionsRepository {}

In this case both Ledger and Budget can "share" methods in TransactionsRepository.

Upvotes: 1

Related Questions