code
stringlengths 17
247k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function GetHashByMD5Path()
{
global $zbp;
return md5($this->Password . $zbp->guid);
} | 获取加路径盐的Hash密码 (其实并没有用path,而是用zbp->guid替代了).
@return string | GetHashByMD5Path | php | zblogcn/zblogphp | zb_system/function/lib/base/member.php | https://github.com/zblogcn/zblogphp/blob/master/zb_system/function/lib/base/member.php | MIT |
public function sqlPush($sql)
{
$this->pri_sql[] = $sql;
} | If we use $this->$getName directly, PHP will throw [Indirect modification of overloaded property]
So we have to wrap it.
It maybe a bug of PHP.
@see http://stackoverflow.com/questions/10454779/php-indirect-modification-of-overloaded-property
@param $sql | sqlPush | php | zblogcn/zblogphp | zb_system/function/lib/sql/global.php | https://github.com/zblogcn/zblogphp/blob/master/zb_system/function/lib/sql/global.php | MIT |
public static function shouldClosedResourceAssertionBeSkipped( $actual ) {
return ( ResourceHelper::isResourceStateReliable( $actual ) === false );
} | Helper function to determine whether an assertion regarding a resource's state should be skipped.
Due to some bugs in PHP itself, the "is closed resource" determination
cannot always be done reliably.
This method can determine whether or not the current value in combination with
the current PHP version on which the test is being run is affected by this.
Use this function to skip running a test using `assertIs[Not]ClosedResource()` or
to skip running just that particular assertion.
@param mixed $actual The variable to test.
@return bool | shouldClosedResourceAssertionBeSkipped | php | Yoast/PHPUnit-Polyfills | src/Polyfills/AssertClosedResource_Empty.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/Polyfills/AssertClosedResource_Empty.php | BSD-3-Clause |
public static function set_up_before_class() {} | This method is called before the first test of this test class is run.
@return void | set_up_before_class | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitGte8.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitGte8.php | BSD-3-Clause |
protected function set_up() {} | Sets up the fixture, for example, open a network connection.
This method is called before each test.
@return void | set_up | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitGte8.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitGte8.php | BSD-3-Clause |
protected function assert_pre_conditions() {} | Performs assertions shared by all tests of a test case.
This method is called before the execution of a test starts and after set_up() is called.
@return void | assert_pre_conditions | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitGte8.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitGte8.php | BSD-3-Clause |
protected function assert_post_conditions() {} | Performs assertions shared by all tests of a test case.
This method is called before the execution of a test ends and before tear_down() is called.
@return void | assert_post_conditions | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitGte8.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitGte8.php | BSD-3-Clause |
protected function tear_down() {} | Tears down the fixture, for example, close a network connection.
This method is called after each test.
@return void | tear_down | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitGte8.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitGte8.php | BSD-3-Clause |
public static function tear_down_after_class() {} | This method is called after the last test of this test class is run.
@return void | tear_down_after_class | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitGte8.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitGte8.php | BSD-3-Clause |
public static function setUpBeforeClass() {
parent::setUpBeforeClass();
static::set_up_before_class();
} | This method is called before the first test of this test class is run.
@codeCoverageIgnore
@return void | setUpBeforeClass | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitLte7.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitLte7.php | BSD-3-Clause |
protected function assertPreConditions() {
parent::assertPreConditions();
$this->assert_pre_conditions();
} | Performs assertions shared by all tests of a test case.
This method is called before the execution of a test starts and after setUp() is called.
@since 0.2.0
@return void | assertPreConditions | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitLte7.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitLte7.php | BSD-3-Clause |
protected function assertPostConditions() {
parent::assertPostConditions();
$this->assert_post_conditions();
} | Performs assertions shared by all tests of a test case.
This method is called before the execution of a test ends and before tearDown() is called.
@since 0.2.0
@return void | assertPostConditions | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitLte7.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitLte7.php | BSD-3-Clause |
public static function tearDownAfterClass() {
static::tear_down_after_class();
parent::tearDownAfterClass();
} | This method is called after the last test of this test class is run.
@codeCoverageIgnore
@return void | tearDownAfterClass | php | Yoast/PHPUnit-Polyfills | src/TestCases/TestCasePHPUnitLte7.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/TestCasePHPUnitLte7.php | BSD-3-Clause |
public static function setUpFixturesBeforeClass() {
parent::setUpBeforeClass();
} | This method is called before the first test of this test class is run.
@beforeClass
@codeCoverageIgnore
@return void | setUpFixturesBeforeClass | php | Yoast/PHPUnit-Polyfills | src/TestCases/XTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/XTestCase.php | BSD-3-Clause |
protected function setUpFixtures() {
parent::setUp();
} | Sets up the fixture, for example, open a network connection.
This method is called before each test.
@before
@return void | setUpFixtures | php | Yoast/PHPUnit-Polyfills | src/TestCases/XTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/XTestCase.php | BSD-3-Clause |
protected function tearDownFixtures() {
parent::tearDown();
} | Tears down the fixture, for example, close a network connection.
This method is called after each test.
@after
@return void | tearDownFixtures | php | Yoast/PHPUnit-Polyfills | src/TestCases/XTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/XTestCase.php | BSD-3-Clause |
public static function tearDownFixturesAfterClass() {
parent::tearDownAfterClass();
} | This method is called after the last test of this test class is run.
@afterClass
@codeCoverageIgnore
@return void | tearDownFixturesAfterClass | php | Yoast/PHPUnit-Polyfills | src/TestCases/XTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/src/TestCases/XTestCase.php | BSD-3-Clause |
private function usesNativePHPUnitAssertion() {
$phpunit_version = PHPUnit_Version::id();
return ( \version_compare( $phpunit_version, '10.1.0', '>=' )
|| ( \version_compare( $phpunit_version, '9.6.11', '>=' ) && \version_compare( $phpunit_version, '10.0.0', '<' ) )
);
} | Check whether native PHPUnit assertions will be used or the polyfill.
@return bool | usesNativePHPUnitAssertion | php | Yoast/PHPUnit-Polyfills | tests/Polyfills/AssertObjectPropertyTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/Polyfills/AssertObjectPropertyTestCase.php | BSD-3-Clause |
private function getKey( $pathname, $proj_id ) {
if ( \function_exists( 'ftok' ) ) {
return \ftok( $pathname, $proj_id );
}
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
$st = @\stat( $pathname );
if ( ! $st ) {
return -1;
}
return \sprintf( '%u', ( ( $st['ino'] & 0xffff ) | ( ( $st['dev'] & 0xff ) << 16 ) | ( ( $proj_id & 0xff ) << 24 ) ) );
} | Helper function: work round ftok() not always being available (on Windows).
@link https://www.php.net/manual/en/function.ftok.php#43309
@param string $pathname Path to file.
@param string $proj_id Project identifier.
@return string | getKey | php | Yoast/PHPUnit-Polyfills | tests/Polyfills/AssertClosedResourceShmopTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/Polyfills/AssertClosedResourceShmopTestCase.php | BSD-3-Clause |
public static function prepareResource() {
self::$openResource = \opendir( __DIR__ );
self::$closedResource = \opendir( __DIR__ );
\closedir( self::$closedResource );
} | Create some resources for use in the tests.
@beforeClass
@return void | prepareResource | php | Yoast/PHPUnit-Polyfills | tests/Polyfills/AssertContainsOnlyTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/Polyfills/AssertContainsOnlyTestCase.php | BSD-3-Clause |
public static function closeResource() {
\closedir( self::$openResource );
} | Clean up the previously created and still open resource.
@afterClass
@return void | closeResource | php | Yoast/PHPUnit-Polyfills | tests/Polyfills/AssertContainsOnlyTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/Polyfills/AssertContainsOnlyTestCase.php | BSD-3-Clause |
public static function dummyCallable() {
// Nothing to see here.
} | Dummy method to have a callable method available.
@return void | dummyCallable | php | Yoast/PHPUnit-Polyfills | tests/Polyfills/AssertContainsOnlyTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/Polyfills/AssertContainsOnlyTestCase.php | BSD-3-Clause |
public function isClosedResourceExpectExceptionOnOpenResource( $actual ) {
$pattern = '`^Failed asserting that .+? is of type ["]?resource \(closed\)["]?`';
$this->expectException( AssertionFailedError::class );
$this->expectExceptionMessageMatches( $pattern );
$this->assertIsClosedResource( $actual );
} | Helper method: Verify that an exception is thrown when `assertIsClosedResource()` is passed an open resource.
@param resource $actual The resource under test.
@return void | isClosedResourceExpectExceptionOnOpenResource | php | Yoast/PHPUnit-Polyfills | tests/Polyfills/AssertClosedResourceTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/Polyfills/AssertClosedResourceTestCase.php | BSD-3-Clause |
public function isNotClosedResourceExpectExceptionOnClosedResource( $actual ) {
/*
* PHPUnit itself will report closed resources as `NULL` prior to Exporter 3.0.4/4.1.4.
* See: https://github.com/sebastianbergmann/exporter/pull/37
*/
$pattern = '`^Failed asserting that (resource \(closed\)|NULL) is not of type ["]?resource \(closed\)["]?`';
$this->expectException( AssertionFailedError::class );
$this->expectExceptionMessageMatches( $pattern );
self::assertIsNotClosedResource( $actual );
} | Helper method: Verify that an exception is thrown when `assertIsNotClosedResource()` is passed a closed resource.
@param resource $actual The resource under test.
@return void | isNotClosedResourceExpectExceptionOnClosedResource | php | Yoast/PHPUnit-Polyfills | tests/Polyfills/AssertClosedResourceTestCase.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/Polyfills/AssertClosedResourceTestCase.php | BSD-3-Clause |
protected function set_up() {
$this->result = new TestResult();
$this->listener = new TestListenerImplementation();
$this->result->addListener( $this->listener );
} | Set up a test result and add the test listener to it.
@return void | set_up | php | Yoast/PHPUnit-Polyfills | tests/TestListeners/TestListenerTest.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/TestListeners/TestListenerTest.php | BSD-3-Clause |
public static function setUpFixturesBeforeClass() {
parent::setUpFixturesBeforeClass();
++self::$beforeClass;
} | This method is called before the first test of this test class is run.
@beforeClass
@return void | setUpFixturesBeforeClass | php | Yoast/PHPUnit-Polyfills | tests/TestCases/XTestCaseTest.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/TestCases/XTestCaseTest.php | BSD-3-Clause |
protected function setUpFixtures() {
parent::setUpFixtures();
++self::$before;
} | This method is called before each test.
@before
@return void | setUpFixtures | php | Yoast/PHPUnit-Polyfills | tests/TestCases/XTestCaseTest.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/TestCases/XTestCaseTest.php | BSD-3-Clause |
protected function tearDownFixtures() {
++self::$after;
parent::tearDownFixtures();
} | This method is called after each test.
@after
@return void | tearDownFixtures | php | Yoast/PHPUnit-Polyfills | tests/TestCases/XTestCaseTest.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/TestCases/XTestCaseTest.php | BSD-3-Clause |
public static function tearDownFixturesAfterClass() {
// Reset.
self::$beforeClass = 0;
self::$before = 0;
self::$after = 0;
parent::tearDownFixturesAfterClass();
} | This method is called after the last test of this test class is run.
@afterClass
@return void | tearDownFixturesAfterClass | php | Yoast/PHPUnit-Polyfills | tests/TestCases/XTestCaseTest.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/TestCases/XTestCaseTest.php | BSD-3-Clause |
protected function set_up() {
++self::$before;
} | This method is called before each test.
@return void | set_up | php | Yoast/PHPUnit-Polyfills | tests/TestCases/TestCaseTest.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/TestCases/TestCaseTest.php | BSD-3-Clause |
protected function assert_pre_conditions() {
++self::$preConditions;
} | This method is called before the execution of a test starts and after set_up() is called.
@return void | assert_pre_conditions | php | Yoast/PHPUnit-Polyfills | tests/TestCases/TestCaseTest.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/TestCases/TestCaseTest.php | BSD-3-Clause |
protected function assert_post_conditions() {
++self::$postConditions;
} | This method is called before the execution of a test ends and before tear_down() is called.
@return void | assert_post_conditions | php | Yoast/PHPUnit-Polyfills | tests/TestCases/TestCaseTest.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/TestCases/TestCaseTest.php | BSD-3-Clause |
protected function tear_down() {
++self::$after;
} | This method is called after each test.
@return void | tear_down | php | Yoast/PHPUnit-Polyfills | tests/TestCases/TestCaseTest.php | https://github.com/Yoast/PHPUnit-Polyfills/blob/master/tests/TestCases/TestCaseTest.php | BSD-3-Clause |
public function resolveRouteBinding($value, $field = null)
{
if ($field === null) {
$field = $this->getRouteKeyName();
}
if (is_string($value) && ctype_digit($value)) {
$value = (int) $value;
}
if (is_int($value) && $field === $this->getRouteKeyName()) {
$value = $this->getOptimus()->decode($value);
}
return $this->where($field, $value)->first();
} | Retrieve the model for a bound value.
@param mixed $value
@param string|null $field
@return \Illuminate\Database\Eloquent\Model|null | resolveRouteBinding | php | cybercog/laravel-optimus | src/Traits/OptimusEncodedRouteKey.php | https://github.com/cybercog/laravel-optimus/blob/master/src/Traits/OptimusEncodedRouteKey.php | MIT |
public function save()
{
$newCategory = $this->validated();
$newCategory['creator_id'] = $this->user()->id;
return Category::create($newCategory);
} | Save category to the database.
@return \App\Models\Category | save | php | buku-masjid/buku-masjid | app/Http/Requests/Categories/CreateRequest.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Requests/Categories/CreateRequest.php | MIT |
public function delete()
{
$category = $this->route('category');
if ($this->has('delete_transactions')) {
$category->transactions()->delete();
} else {
$category->transactions()->update(['category_id' => null]);
}
if ($this->get('category_id') == $category->id) {
return $category->delete();
}
return false;
} | Delete category from database.
@return bool | delete | php | buku-masjid/buku-masjid | app/Http/Requests/Categories/DeleteRequest.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Requests/Categories/DeleteRequest.php | MIT |
public function save()
{
$transaction = $this->route('transaction');
$transaction->update($this->validated());
return $transaction;
} | Update transaction in database.
@return \App\Models\Category | save | php | buku-masjid/buku-masjid | app/Http/Requests/Transactions/UpdateRequest.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Requests/Transactions/UpdateRequest.php | MIT |
protected function authenticated(Request $request, $user)
{
if ($user->is_active == 0) {
$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate();
flash(trans('auth.user_inactive'), 'error');
return redirect()->route('login');
}
flash(trans('auth.welcome', ['name' => $user->name]));
} | The user has been authenticated.
@param mixed $user
@return mixed | authenticated | php | buku-masjid/buku-masjid | app/Http/Controllers/Auth/LoginController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Auth/LoginController.php | MIT |
public function index()
{
$yearMonth = $this->getYearMonth();
return new TransactionCollection(
$this->getTansactions($yearMonth)
);
} | Return a listing of the transaction.
@return \App\Http\Resources\TransactionCollection | index | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/TransactionsController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/TransactionsController.php | MIT |
public function store(CreateRequest $transactionCreateForm)
{
$transaction = $transactionCreateForm->save();
$responseMessage = __('transaction.income_added');
if ($transaction['in_out'] == 0) {
$responseMessage = __('transaction.spending_added');
}
$responseData = [
'message' => $responseMessage,
'data' => new TransactionResource($transaction),
];
return response()->json($responseData, 201);
} | Store a newly created transaction in storage.
@return \Illuminate\Http\JsonResponse | store | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/TransactionsController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/TransactionsController.php | MIT |
public function show(Transaction $transaction)
{
return new TransactionResource($transaction);
} | Show the specified transaction data.
@return \App\Http\Controllers\Api\TransactionResource | show | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/TransactionsController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/TransactionsController.php | MIT |
public function update(UpdateRequest $transactionUpdateForm, Transaction $transaction)
{
$transaction = $transactionUpdateForm->save();
return response()->json([
'message' => __('transaction.updated'),
'data' => new TransactionResource($transaction),
]);
} | Update the specified transaction in storage.
@return \Illuminate\Http\JsonResponse | update | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/TransactionsController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/TransactionsController.php | MIT |
public function destroy(Transaction $transaction)
{
$this->authorize('delete', $transaction);
request()->validate(['transaction_id' => 'required']);
if (request('transaction_id') == $transaction->id && $transaction->delete()) {
return response()->json(['message' => __('transaction.deleted')]);
}
return response()->json(['message' => __('transaction.undeleted')]);
} | Remove the specified transaction from storage.
@return \Illuminate\Http\JsonResponse | destroy | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/TransactionsController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/TransactionsController.php | MIT |
public function index()
{
$categories = Category::all();
return $categories;
} | Get a listing of the category.
@return \Illuminate\Http\Response | index | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/CategoriesController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/CategoriesController.php | MIT |
public function store(CreateRequest $categoryCreateForm)
{
$category = $categoryCreateForm->save();
return response()->json([
'message' => __('category.created'),
'data' => $category->fresh(),
], 201);
} | Store a newly created category in storage.
@return \Illuminate\Http\Response | store | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/CategoriesController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/CategoriesController.php | MIT |
public function update(UpdateRequest $categoryUpdateForm, Category $category)
{
$category = $categoryUpdateForm->save();
return response()->json([
'message' => __('category.updated'),
'data' => $category,
]);
} | Update the specified category in storage.
@return \Illuminate\Http\Response | update | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/CategoriesController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/CategoriesController.php | MIT |
public function destroy(DeleteRequest $categoryDeleteForm, Category $category)
{
if ($categoryDeleteForm->delete()) {
return response()->json(['message' => __('category.deleted')]);
}
return response()->json('Unprocessable Entity.', 422);
} | Remove the specified category from storage.
@return \Illuminate\Http\Response | destroy | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/CategoriesController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/CategoriesController.php | MIT |
protected function sendLoginResponse(Request $request)
{
$this->clearLoginAttempts($request);
return new UserResource($request->user());
} | Send the response after the user was authenticated.
@return \Illuminate\Http\Response | sendLoginResponse | php | buku-masjid/buku-masjid | app/Http/Controllers/Api/Auth/LoginController.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Http/Controllers/Api/Auth/LoginController.php | MIT |
function get_years()
{
$yearRange = range(2020, date('Y'));
foreach ($yearRange as $year) {
$years[$year] = $year;
}
return $years;
} | Get array of year list starting from 2018.
@return array | get_years | php | buku-masjid/buku-masjid | app/Helpers/date_time.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Helpers/date_time.php | MIT |
function balance($perDate = null, $startDate = null, $categoryId = null, $bookId = null)
{
$transactionQuery = DB::table('transactions');
if ($perDate) {
$transactionQuery->where('date', '<=', $perDate);
}
if ($startDate) {
$transactionQuery->where('date', '>=', $startDate);
}
if ($categoryId) {
$transactionQuery->where('category_id', $categoryId);
}
if ($bookId) {
$transactionQuery->where('book_id', $bookId);
}
$transactions = $transactionQuery->where('creator_id', auth()->id())->get();
return $transactions->sum(function ($transaction) {
return $transaction->in_out ? $transaction->amount : -$transaction->amount;
});
} | Get balance amount based on transactions.
@param string|null $perDate
@param string|null $startDate
@return float | balance | php | buku-masjid/buku-masjid | app/Helpers/functions.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Helpers/functions.php | MIT |
public function transactions()
{
return $this->hasMany(Transaction::class);
} | Category has many transactions relation.
@return \Illuminate\Database\Eloquent\Relations\HasMany | transactions | php | buku-masjid/buku-masjid | app/Models/Category.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Models/Category.php | MIT |
public function getNameLabelAttribute()
{
return '<span class="badge" style="background-color: '.$this->color.'">'.$this->name.'</span>';
} | Get category name label attribute.
@return string | getNameLabelAttribute | php | buku-masjid/buku-masjid | app/Models/Category.php | https://github.com/buku-masjid/buku-masjid/blob/master/app/Models/Category.php | MIT |
public static function bootValidatingTrait()
{
static::observe(new ValidatingObserver);
} | Boot the trait. Adds an observer class for validating.
@return void | bootValidatingTrait | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function getValidating()
{
return $this->validating;
} | Returns whether or not the model will attempt to validate
itself when saving.
@return bool | getValidating | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function setValidating($value)
{
$this->validating = (boolean) $value;
} | Set whether the model should attempt validation on saving.
@param bool $value
@return void | setValidating | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function getThrowValidationExceptions()
{
return isset($this->throwValidationExceptions) ? $this->throwValidationExceptions : false;
} | Returns whether the model will raise an exception or
return a boolean when validating.
@return bool | getThrowValidationExceptions | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function setThrowValidationExceptions($value)
{
$this->throwValidationExceptions = (boolean) $value;
} | Set whether the model should raise an exception or
return a boolean on a failed validation.
@param bool $value
@return void
@throws InvalidArgumentException | setThrowValidationExceptions | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function getInjectUniqueIdentifier()
{
return isset($this->injectUniqueIdentifier) ? $this->injectUniqueIdentifier : true;
} | Returns whether or not the model will add it's unique
identifier to the rules when validating.
@return bool | getInjectUniqueIdentifier | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function setInjectUniqueIdentifier($value)
{
$this->injectUniqueIdentifier = (boolean) $value;
} | Set the model to add unique identifier to rules when performing
validation.
@param bool $value
@return void
@throws InvalidArgumentException | setInjectUniqueIdentifier | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function getValidationMessages()
{
return isset($this->validationMessages) ? $this->validationMessages : [];
} | Get the custom validation messages being used by the model.
@return array | getValidationMessages | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
protected function modelValidationMessages()
{
return (new static)->getValidationMessages();
} | Handy method for using the static call Model::validationMessages().
Protected access only to allow __callStatic to get to it.
@return array | modelValidationMessages | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function getValidationAttributeNames()
{
return isset($this->validationAttributeNames) ? $this->validationAttributeNames : [];
} | Get the validating attribute names.
@return array | getValidationAttributeNames | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
protected function modelValidationAttributeNames()
{
return (new static)->getValidationAttributeNames();
} | Handy method for using the static call Model::validationAttributeNames().
Protected access only to allow __callStatic to get to it.
@return array | modelValidationAttributeNames | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function setValidationAttributeNames(?array $attributeNames = null)
{
$this->validationAttributeNames = $attributeNames;
} | Set the validating attribute names.
@param array $attributeNames
@return void | setValidationAttributeNames | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function getRules()
{
return isset($this->rules) ? $this->rules : [];
} | Get the global validation rules.
@return array | getRules | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function getPreparedRules()
{
return $this->injectUniqueIdentifierToRules($this->getRules());
} | Get the validation rules after being prepared by the injectors.
@return array | getPreparedRules | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
protected function rules()
{
return $this->getRules();
} | Handy method for using the static call Model::rules(). Protected access
only to allow __callStatic to get to it.
@return array | rules | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function setRules(?array $rules = null)
{
$this->rules = $rules;
} | Set the global validation rules.
@param array $rules
@return void | setRules | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function getErrors()
{
return $this->validationErrors ?: new MessageBag;
} | Get the validation error messages from the model.
@return \Illuminate\Support\MessageBag | getErrors | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function isValid()
{
$rules = $this->getRules();
return $this->performValidation($rules);
} | Returns whether the model is valid or not.
@return bool | isValid | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function isValidOrFail()
{
if ( ! $this->isValid()) {
$this->throwValidationException();
}
return true;
} | Returns if the model is valid, otherwise throws an exception.
@return bool
@throws \Watson\Validating\ValidationException | isValidOrFail | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function isInvalid()
{
return ! $this->isValid();
} | Returns whether the model is invalid or not.
@return bool | isInvalid | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function forceSave(array $options = [])
{
$currentValidatingSetting = $this->getValidating();
$this->setValidating(false);
$result = $this->getModel()->save($options);
$this->setValidating($currentValidatingSetting);
return $result;
} | Force the model to be saved without undergoing validation.
@param array $options
@return bool | forceSave | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function saveOrFail(array $options = [])
{
if ($this->isInvalid()) {
return $this->throwValidationException();
}
return $this->getModel()->parentSaveOrFail($options);
} | Perform a one-off save that will raise an exception on validation error
instead of returning a boolean (which is the default behaviour).
@param array $options
@return bool
@throws \Throwable | saveOrFail | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function parentSaveOrFail($options)
{
return parent::saveOrFail($options);
} | Call the parent save or fail method provided by Eloquent.
@param array $options
@return bool
@throws \Throwable | parentSaveOrFail | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function saveOrReturn(array $options = [])
{
return $this->getModel()->save($options);
} | Perform a one-off save that will return a boolean on
validation error instead of raising an exception.
@param array $options
@return bool | saveOrReturn | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
protected function makeValidator($rules = [])
{
// Get the casted model attributes.
$attributes = $this->getModelAttributes();
if ($this->getInjectUniqueIdentifier()) {
$rules = $this->injectUniqueIdentifierToRules($rules);
}
$messages = $this->getValidationMessages();
$validator = $this->getValidator()->make($attributes, $rules, $messages);
if ($this->getValidationAttributeNames()) {
$validator->setAttributeNames($this->getValidationAttributeNames());
}
$this->withValidator($validator);
return $validator;
} | Make a Validator instance for a given ruleset.
@param array $rules
@return \Illuminate\Contracts\Validation\Validator | makeValidator | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
protected function withValidator($validator)
{
//
} | Provide a hook to interact with the validator before it is used.
@param \Illuminate\Contracts\Validation\Validator $validator
@return void | withValidator | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
protected function performValidation($rules = [])
{
$validation = $this->makeValidator($rules);
$result = $validation->passes();
$this->setErrors($validation->messages());
return $result;
} | Validate the model against it's rules, returning whether
or not it passes and setting the error messages on the
model if required.
@param array $rules
@return bool
@throws \Watson\Validating\ValidationException | performValidation | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function updateRulesUniques()
{
$rules = $this->getRules();
$this->setRules($this->injectUniqueIdentifierToRules($rules));
} | Update the unique rules of the global rules to
include the model identifier.
@return void | updateRulesUniques | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
protected function getUniqueIdentifierInjectorMethod($validationRule)
{
$method = 'prepare' . Str::studly($validationRule) . 'Rule';
return method_exists($this, $method) ? $method : false;
} | Get the dynamic method name for a unique identifier injector rule if it
exists, otherwise return false.
@param string $validationRule
@return mixed | getUniqueIdentifierInjectorMethod | php | dwightwatson/validating | src/ValidatingTrait.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingTrait.php | MIT |
public function __construct(Validator $validator, Model $model)
{
parent::__construct($validator);
$this->model = $model;
} | Create a new validation exception instance.
@param \Illuminate\Contracts\Validation\Validator $validator
@param \Illuminate\Database\Eloquent\Model $model
@return void | __construct | php | dwightwatson/validating | src/ValidationException.php | https://github.com/dwightwatson/validating/blob/master/src/ValidationException.php | MIT |
public function model()
{
return $this->model;
} | Get the model with validation errors.
@return \Illuminate\Database\Eloquent\Model | model | php | dwightwatson/validating | src/ValidationException.php | https://github.com/dwightwatson/validating/blob/master/src/ValidationException.php | MIT |
public function getModel()
{
return $this->model();
} | Get the mdoel with validation errors.
@return \Illuminate\Database\Eloquent\Model | getModel | php | dwightwatson/validating | src/ValidationException.php | https://github.com/dwightwatson/validating/blob/master/src/ValidationException.php | MIT |
public function getMessageBag()
{
return $this->errors();
} | Get the messages for the instance.
@return \Illuminate\Contracts\Support\MessageBag | getMessageBag | php | dwightwatson/validating | src/ValidationException.php | https://github.com/dwightwatson/validating/blob/master/src/ValidationException.php | MIT |
public function saving(Model $model)
{
return $this->performValidation($model, 'saving');
} | Register the validation event for saving the model. Saving validation
should only occur if creating and updating validation does not.
@param \Illuminate\Database\Eloquent\Model $model
@return boolean | saving | php | dwightwatson/validating | src/ValidatingObserver.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingObserver.php | MIT |
public function restoring(Model $model)
{
return $this->performValidation($model, 'restoring');
} | Register the validation event for restoring the model.
@param \Illuminate\Database\Eloquent\Model $model
@return boolean | restoring | php | dwightwatson/validating | src/ValidatingObserver.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingObserver.php | MIT |
protected function performValidation(Model $model, $event)
{
// If the model has validating enabled, perform it.
if ($model->getValidating()) {
// Fire the namespaced validating event and prevent validation
// if it returns a value.
if ($this->fireValidatingEvent($model, $event) !== null) {
return;
}
if ($model->isValid() === false) {
// Fire the validating failed event.
$this->fireValidatedEvent($model, 'failed');
if ($model->getThrowValidationExceptions()) {
$model->throwValidationException();
}
return false;
}
// Fire the validating.passed event.
$this->fireValidatedEvent($model, 'passed');
} else {
$this->fireValidatedEvent($model, 'skipped');
}
} | Perform validation with the specified ruleset.
@param \Illuminate\Database\Eloquent\Model $model
@param string $event
@return boolean | performValidation | php | dwightwatson/validating | src/ValidatingObserver.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingObserver.php | MIT |
protected function fireValidatingEvent(Model $model, $event)
{
return Event::until("eloquent.validating: ".get_class($model), [$model, $event]);
} | Fire the namespaced validating event.
@param \Illuminate\Database\Eloquent\Model $model
@param string $event
@return mixed | fireValidatingEvent | php | dwightwatson/validating | src/ValidatingObserver.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingObserver.php | MIT |
protected function fireValidatedEvent(Model $model, $status)
{
Event::dispatch("eloquent.validated: ".get_class($model), [$model, $status]);
} | Fire the namespaced post-validation event.
@param \Illuminate\Database\Eloquent\Model $model
@param string $status
@return void | fireValidatedEvent | php | dwightwatson/validating | src/ValidatingObserver.php | https://github.com/dwightwatson/validating/blob/master/src/ValidatingObserver.php | MIT |
protected function prepareUniqueWithRule($parameters, $field)
{
// Table and intermediary fields are required for this validator to work and cannot be guessed.
// Let's just check the model identifier.
if ($this->exists) {
// If the identifier isn't set, add it.
if (count($parameters) < 3 || ! preg_match('/^\d+(\s?=\s?\w*)?$/', last($parameters))) {
$parameters[] = $this->getModel()->getKey();
}
}
return 'unique_with:' . implode(',', $parameters);
} | Prepare a unique_with rule, adding the model identifier if required.
@param array $parameters
@param string $field
@return string | prepareUniqueWithRule | php | dwightwatson/validating | src/Injectors/UniqueWithInjector.php | https://github.com/dwightwatson/validating/blob/master/src/Injectors/UniqueWithInjector.php | MIT |
protected function prepareUniqueRule($parameters, $field)
{
// If the table name isn't set, infer it.
if (empty($parameters[0])) {
$parameters[0] = $this->getModel()->getTable();
}
// If the connection name isn't set but exists, infer it.
if ((strpos($parameters[0], '.') === false) && (($connectionName = $this->getModel()->getConnectionName()) !== null)) {
$parameters[0] = $connectionName.'.'.$parameters[0];
}
// If the field name isn't get, infer it.
if (! isset($parameters[1])) {
$parameters[1] = $field;
}
if ($this->exists) {
// If the identifier isn't set, infer it.
if (! isset($parameters[2]) || strtolower($parameters[2]) === 'null') {
$parameters[2] = $this->getModel()->getKey();
}
// If the primary key isn't set, infer it.
if (! isset($parameters[3])) {
$parameters[3] = $this->getModel()->getKeyName();
}
// If the additional where clause isn't set, infer it.
// Example: unique:users,email,123,id,username,NULL
foreach ($parameters as $key => $parameter) {
if (strtolower((string) $parameter) === 'null') {
// Maintain NULL as string in case the model returns a null value
$value = $this->getModel()->{$parameters[$key - 1]};
$parameters[$key] = is_null($value) ? 'NULL' : $value;
}
}
}
return 'unique:' . implode(',', $parameters);
} | Prepare a unique rule, adding the table name, column and model identifier
if required.
@param array $parameters
@param string $field
@return string | prepareUniqueRule | php | dwightwatson/validating | src/Injectors/UniqueInjector.php | https://github.com/dwightwatson/validating/blob/master/src/Injectors/UniqueInjector.php | MIT |
public function __call($method, $parameters)
{
return $this->forwardCallTo(
$this->new(),
$method,
$parameters
);
} | Handle dynamic method calls into a new Searcher instance.
@param string $method
@param array $parameters
@return mixed | __call | php | protonemedia/laravel-cross-eloquent-search | src/SearchFactory.php | https://github.com/protonemedia/laravel-cross-eloquent-search/blob/master/src/SearchFactory.php | MIT |
public function __construct()
{
$this->modelsToSearchThrough = new Collection;
$this->orderByAsc();
} | Initialises the instanace with a fresh Collection and default sort. | __construct | php | protonemedia/laravel-cross-eloquent-search | src/Searcher.php | https://github.com/protonemedia/laravel-cross-eloquent-search/blob/master/src/Searcher.php | MIT |
protected function getIdAndOrderAttributes()
{
$query = $this->getCompiledQueryBuilder();
// Determine the pagination method to call on Eloquent\Builder
$paginateMethod = $this->simplePaginate ? 'simplePaginate' : 'paginate';
// get all results or limit the results by pagination
return $this->pageName
? $query->{$paginateMethod}($this->perPage, ['*'], $this->pageName, $this->page)
: $query->get();
// the collection will be something like:
//
// [
// [
// "0_post_key": null
// "0_post_order": null
// "1_video_key": 3
// "1_video_order": "2020-07-07 19:51:08"
// ],
// [
// "0_post_key": 1
// "0_post_order": "2020-07-08 19:51:08"
// "1_video_key": null
// "1_video_order": null
// ]
// ]
} | Paginates the compiled query or fetches all results.
@return \Illuminate\Support\Collection|\Illuminate\Contracts\Pagination\LengthAwarePaginator | getIdAndOrderAttributes | php | protonemedia/laravel-cross-eloquent-search | src/Searcher.php | https://github.com/protonemedia/laravel-cross-eloquent-search/blob/master/src/Searcher.php | MIT |
public static function __callStatic($method, $parameters)
{
try {
$userAgent = new UserAgent();
return $userAgent->{$method}(...$parameters);
} catch (\Throwable $th) {
throw AgentException::create("The method '{$method}()' does not exist.");
}
} | Handle calls to missing static methods.
@param string $method The name of the method being called.
@param array $parameters The parameters passed to the method.
@throws AgentException If the method does not exist.
@return mixed The result of the called method. | __callStatic | php | rmunate/AgentDetection | src/Agent.php | https://github.com/rmunate/AgentDetection/blob/master/src/Agent.php | MIT |
public static function detect()
{
return new UserAgent();
} | Get a UserAgent instance for the current request.
@return UserAgent The UserAgent instance. | detect | php | rmunate/AgentDetection | src/Agent.php | https://github.com/rmunate/AgentDetection/blob/master/src/Agent.php | MIT |
public static function get()
{
return $_SERVER['HTTP_USER_AGENT'] ?? null;
} | Get the raw user agent string from the current request.
@return string|null The user agent string. | get | php | rmunate/AgentDetection | src/Agent.php | https://github.com/rmunate/AgentDetection/blob/master/src/Agent.php | MIT |
public static function set(string $string)
{
return new UserAgent($string);
} | Set a custom user agent string for testing or manipulation.
@param string $string The custom user agent string.
@return UserAgent The UserAgent instance with the custom string. | set | php | rmunate/AgentDetection | src/Agent.php | https://github.com/rmunate/AgentDetection/blob/master/src/Agent.php | MIT |
public function isMobile()
{
return Utilities::inString($this->agent, Identifiers::MOBILES);
} | Check if the user agent represents a mobile device.
@return bool True if the user agent is from a mobile device, false otherwise. | isMobile | php | rmunate/AgentDetection | src/Server/UserAgent.php | https://github.com/rmunate/AgentDetection/blob/master/src/Server/UserAgent.php | MIT |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.