idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
3,900
protected function getRedirectType ( $ BID ) { $ objCat = \ Database :: getInstance ( ) -> prepare ( "SELECT pid as CatID FROM `tl_banner` WHERE id=?" ) -> execute ( $ BID ) ; if ( 0 == $ objCat -> numRows ) { return '301' ; } $ objCat -> next ( ) ; $ objBRT = \ Database :: getInstance ( ) -> prepare ( "SELECT `banner_categories` ,`banner_redirect` FROM `tl_module` WHERE type=? AND banner_categories=?" ) -> execute ( 'banner' , $ objCat -> CatID ) ; if ( 0 == $ objBRT -> numRows ) { return '301' ; } $ arrBRT = array ( ) ; while ( $ objBRT -> next ( ) ) { $ arrBRT [ ] = ( $ objBRT -> banner_redirect == 'temporary' ) ? '302' : '301' ; } if ( count ( $ arrBRT ) == 1 ) { return $ arrBRT [ 0 ] ; } else { $ anz301 = $ anz302 = 0 ; foreach ( $ arrBRT as $ type ) { if ( $ type == '301' ) { $ anz301 ++ ; } else { $ anz302 ++ ; } } if ( $ anz301 >= $ anz302 ) { return '301' ; } else { return '302' ; } } }
Search Banner Redirect Definition
3,901
protected function getCmsOrderedConfigReplace ( ) { $ orderColumns = $ this -> data [ 'ordered_by' ] ? : [ ] ; $ translatedOrderColumns = array_intersect ( array_keys ( $ orderColumns ) , $ this -> data [ 'translated_attributes' ] ) ; if ( count ( $ translatedOrderColumns ) ) { foreach ( $ translatedOrderColumns as $ column ) { unset ( $ orderColumns [ $ column ] ) ; } } if ( ! count ( $ orderColumns ) ) return '' ; if ( config ( 'pxlcms.generator.models.scopes.position_order' ) !== CmsModelWriter :: SCOPE_GLOBAL ) return '' ; $ longestLength = 0 ; foreach ( $ orderColumns as $ attribute => $ direction ) { if ( strlen ( $ attribute ) > $ longestLength ) { $ longestLength = strlen ( $ attribute ) ; } } $ replace = $ this -> tab ( ) . "protected \$cmsOrderBy = [\n" ; foreach ( $ orderColumns as $ attribute => $ direction ) { $ replace .= $ this -> tab ( 2 ) . "'" . str_pad ( $ attribute . "'" , $ longestLength + 1 ) . " => '" . $ direction . "',\n" ; } $ replace .= $ this -> tab ( ) . "];\n\n" ; return $ replace ; }
Returns the replace required depending on whether the CMS module has automatic sorting for defined columns
3,902
protected function getCatID ( ) { $ objBannerCatID = \ Database :: getInstance ( ) -> prepare ( "SELECT MIN(pid) AS ID FROM tl_banner" ) -> execute ( ) ; $ objBannerCatID -> next ( ) ; if ( $ objBannerCatID -> ID === null ) { return 0 ; } else { return $ objBannerCatID -> ID ; } }
Get min category id
3,903
protected function getBannersByCatID ( $ CatID = 0 ) { $ arrBanners = array ( ) ; if ( $ CatID == - 1 ) { $ objBanners = \ Database :: getInstance ( ) -> prepare ( "SELECT tb.id , tb.banner_type , tb.banner_name , tb.banner_url , tb.banner_jumpTo , tb.banner_image , tb.banner_image_extern , tb.banner_weighting , tb.banner_start , tb.banner_stop , tb.banner_published , tb.banner_until , tb.banner_comment , tb.banner_views_until , tb.banner_clicks_until , tbs.banner_views , tbs.banner_clicks FROM tl_banner tb , tl_banner_stat tbs WHERE tb.id=tbs.id ORDER BY tb.pid , tb.sorting" ) -> execute ( ) ; } else { $ objBanners = \ Database :: getInstance ( ) -> prepare ( "SELECT tb.id , tb.banner_type , tb.banner_name , tb.banner_url , tb.banner_jumpTo , tb.banner_image , tb.banner_image_extern , tb.banner_weighting , tb.banner_start , tb.banner_stop , tb.banner_published , tb.banner_until , tb.banner_comment , tb.banner_views_until , tb.banner_clicks_until , tbs.banner_views , tbs.banner_clicks FROM tl_banner tb , tl_banner_stat tbs WHERE tb.id=tbs.id AND tb.pid =? ORDER BY tb.sorting" ) -> execute ( $ CatID ) ; } $ intRows = $ objBanners -> numRows ; if ( $ intRows > 0 ) { while ( $ objBanners -> next ( ) ) { $ arrBanners [ ] = array ( 'id' => $ objBanners -> id , 'banner_type' => $ objBanners -> banner_type , 'banner_name' => $ objBanners -> banner_name , 'banner_url' => $ objBanners -> banner_url , 'banner_jumpTo' => $ objBanners -> banner_jumpTo , 'banner_image' => $ objBanners -> banner_image , 'banner_image_extern' => $ objBanners -> banner_image_extern , 'banner_weighting' => $ objBanners -> banner_weighting , 'banner_start' => $ objBanners -> banner_start , 'banner_stop' => $ objBanners -> banner_stop , 'banner_published' => $ objBanners -> banner_published , 'banner_until' => $ objBanners -> banner_until , 'banner_comment' => $ objBanners -> banner_comment , 'banner_views_until' => $ objBanners -> banner_views_until , 'banner_clicks_until' => $ objBanners -> banner_clicks_until , 'banner_views' => $ objBanners -> banner_views , 'banner_clicks' => $ objBanners -> banner_clicks ) ; } } return $ arrBanners ; }
Get banners by category id
3,904
protected function getBannerCategories ( $ banner_number ) { $ objBannerCat = \ Database :: getInstance ( ) -> prepare ( "SELECT id , title FROM tl_banner_category WHERE id IN (SELECT pid FROM tl_banner LEFT JOIN tl_banner_category ON tl_banner.pid = tl_banner_category.id GROUP BY tl_banner.pid ) ORDER BY title" ) -> execute ( ) ; if ( $ objBannerCat -> numRows > 0 ) { if ( $ banner_number == 0 ) { $ arrBannerCats [ ] = array ( 'id' => '0' , 'title' => $ GLOBALS [ 'TL_LANG' ] [ 'tl_banner_stat' ] [ 'select' ] ) ; $ this -> intCatID = 0 ; } $ arrBannerCats [ ] = array ( 'id' => '-1' , 'title' => $ GLOBALS [ 'TL_LANG' ] [ 'tl_banner_stat' ] [ 'allkat' ] ) ; while ( $ objBannerCat -> next ( ) ) { $ arrBannerCats [ ] = array ( 'id' => $ objBannerCat -> id , 'title' => $ objBannerCat -> title ) ; } } else { $ arrBannerCats [ ] = array ( 'id' => '0' , 'title' => '---------' ) ; } return $ arrBannerCats ; }
Get banner categories
3,905
protected function getBannerCategoriesByUsergroups ( ) { $ arrBannerCats = array ( ) ; $ objBannerCat = \ Database :: getInstance ( ) -> prepare ( "SELECT `id` , `title` , `banner_stat_protected` , `banner_stat_groups` FROM tl_banner_category WHERE 1 ORDER BY title " ) -> execute ( ) ; while ( $ objBannerCat -> next ( ) ) { if ( true === $ this -> isUserInBannerStatGroups ( $ objBannerCat -> banner_stat_groups , ( bool ) $ objBannerCat -> banner_stat_protected ) ) { $ arrBannerCats [ ] = array ( 'id' => $ objBannerCat -> id , 'title' => $ objBannerCat -> title ) ; } } if ( 0 == count ( $ arrBannerCats ) ) { $ arrBannerCats [ ] = array ( 'id' => '0' , 'title' => '---------' ) ; } return $ arrBannerCats ; }
Get banner categories by usergroups
3,906
protected function getMaxViewsClicksStatus ( & $ Banner ) { $ intMaxViews = false ; $ intMaxClicks = false ; if ( $ Banner [ 'banner_until' ] == 1 && $ Banner [ 'banner_views_until' ] != '' && $ Banner [ 'banner_views' ] >= $ Banner [ 'banner_views_until' ] ) { $ intMaxViews = true ; } if ( $ Banner [ 'banner_until' ] == 1 && $ Banner [ 'banner_clicks_until' ] != '' && $ Banner [ 'banner_clicks' ] >= $ Banner [ 'banner_clicks_until' ] ) { $ intMaxClicks = true ; } return array ( $ intMaxViews , $ intMaxClicks ) ; }
Get status of maxviews and maxclicks
3,907
protected function isUserInBannerStatGroups ( $ banner_stat_groups , $ banner_stat_protected ) { if ( true === $ this -> User -> isAdmin ) { return true ; } if ( false === $ banner_stat_protected ) { return true ; } if ( 0 == strlen ( $ banner_stat_groups ) ) { return false ; } foreach ( deserialize ( $ banner_stat_groups ) as $ id => $ groupid ) { if ( true === $ this -> User -> isMemberOf ( $ groupid ) ) { return true ; } } return false ; }
Check if User member of group in banner statistik groups
3,908
public function runMigration ( $ plugin ) { $ command = new Migrate ( ) ; $ output = new NullOutput ( ) ; $ input = new ArrayInput ( [ '--plugin' => $ plugin ] ) ; $ resultCode = $ command -> run ( $ input , $ output ) ; }
Runs the migrations for a given plugin
3,909
public function tableExists ( $ tableName , $ connectionName = 'default' ) { try { $ db = ConnectionManager :: get ( $ connectionName ) ; $ collection = $ db -> schemaCollection ( ) ; $ tables = $ collection -> listTables ( ) ; if ( in_array ( $ tableName , $ tables ) ) { return true ; } } catch ( PDOException $ connectionError ) { return false ; } return false ; }
Check whether table is exists in database or not .
3,910
public function databaseConnection ( $ dataSource = 'default' ) { try { $ connection = ConnectionManager :: get ( $ dataSource ) ; $ connected = $ connection -> connect ( ) ; } catch ( MissingConnectionException $ connectionError ) { $ connected = false ; } return $ connected ; }
Test database connection .
3,911
public function roles ( User $ user ) { if ( $ this -> session -> hasValue ( Roles :: SESSION_KEY ) ) { return $ this -> session -> value ( Roles :: SESSION_KEY ) ; } $ roles = $ this -> authorizationProvider -> roles ( $ user ) ; $ this -> session -> putValue ( Roles :: SESSION_KEY , $ roles ) ; return $ roles ; }
returns the roles available for this request and user
3,912
protected function _getAppBase ( ) { $ baseUrl = Configure :: read ( 'App.base' ) ; if ( ! $ baseUrl ) { $ request = Router :: getRequest ( true ) ; if ( ! $ request ) { $ baseUrl = '' ; } else { $ baseUrl = $ request -> base ; } } return $ baseUrl . '/' ; }
Return the content of CakePHP App . base . If the App . base value is false it returns the generated URL automatically by mimicking how CakePHP add the base to its URL .
3,913
public function module ( $ name ) { list ( $ plugin , $ path ) = $ this -> _View -> pluginSplit ( $ name , false ) ; if ( ! empty ( $ plugin ) ) { $ name = $ this -> Url -> assetUrl ( $ name , [ 'pathPrefix' => Configure :: read ( 'App.jsBaseUrl' ) , 'ext' => '.js' , ] ) ; } if ( ! $ this -> _requireLoaded ) { return $ this -> _preLoadModule ( $ name ) ; } return $ this -> _loadModule ( $ name ) ; }
Add a javascript module to be loaded on the page .
3,914
public function evaluate ( array $ item , array $ clause ) { if ( false === isset ( $ clause [ 'key' ] ) || false === isset ( $ clause [ 'value' ] ) || false === isset ( $ clause [ 'operator' ] ) ) { throw new \ InvalidArgumentException ( 'Clause must contain "key", "value" and operator.' ) ; } $ value = isset ( $ item [ $ clause [ 'key' ] ] ) ? $ item [ $ clause [ 'key' ] ] : null ; $ value = $ this -> evaluateFilters ( $ value , $ clause ) ; if ( false === isset ( $ this -> operators [ $ clause [ 'operator' ] ] ) ) { throw new UnkownOperatorException ( sprintf ( 'The operator "%s" does not exist.' , $ clause [ 'operator' ] ) ) ; } if ( false === $ this -> operators [ $ clause [ 'operator' ] ] -> evaluate ( $ value , $ clause [ 'value' ] ) ) { return false ; } return true ; }
Evaluates the given item with the given clause .
3,915
protected function evaluateFilters ( $ value , array $ clause ) { if ( true === isset ( $ clause [ 'filters' ] ) ) { if ( false === is_array ( $ clause [ 'filters' ] ) ) { $ clause [ 'filters' ] = [ $ clause [ 'filters' ] ] ; } foreach ( $ clause [ 'filters' ] as $ filter ) { $ value = $ this -> evaluateFilter ( $ value , $ filter ) ; } } return $ value ; }
Evaluates the given value with the given clause .
3,916
public function listAction ( ) { $ products = $ this -> container -> get ( 'vespolina.product_manager' ) -> findBy ( array ( ) ) ; return $ this -> container -> get ( 'templating' ) -> renderResponse ( 'VespolinaCommerceBundle:Product:list.html.' . $ this -> getEngine ( ) , array ( 'products' => $ products ) ) ; }
Show all products
3,917
public function detailAction ( $ id ) { $ product = $ this -> container -> get ( 'vespolina.product_manager' ) -> findProductById ( $ id ) ; if ( ! $ product ) { throw new NotFoundHttpException ( 'The product does not exist!' ) ; } return $ this -> container -> get ( 'templating' ) -> renderResponse ( 'VespolinaCommerceBundle:Product:show.html.' . $ this -> getEngine ( ) , array ( 'product' => $ product ) ) ; }
Show one product by object id
3,918
public function editAction ( $ id ) { $ product = $ this -> container -> get ( 'vespolina.product_manager' ) -> findProductById ( $ id ) ; if ( ! $ product ) { throw new NotFoundHttpException ( 'The product does not exist!' ) ; } $ formHandler = $ this -> container -> get ( 'vespolina.product.form.handler' ) ; $ process = $ formHandler -> process ( $ product ) ; if ( $ process ) { $ this -> setFlash ( 'vespolina_product_updated' , 'success' ) ; $ url = $ this -> container -> get ( 'router' ) -> generate ( 'vespolina_product_list' ) ; return new RedirectResponse ( $ url ) ; } $ form = $ this -> container -> get ( 'vespolina.product.form' ) ; $ form -> setData ( $ product ) ; return $ this -> container -> get ( 'templating' ) -> renderResponse ( 'VespolinaCommerceBundle:Product:edit.html.' . $ this -> getEngine ( ) , array ( 'form' => $ form -> createView ( ) , 'id' => $ id , 'configuredOptionGroups' => $ this -> getConfiguredOptionsGroups ( ) , ) ) ; }
Edit one product show the edit form
3,919
public function deleteAction ( $ id ) { $ product = $ this -> container -> get ( 'vespolina.product_manager' ) -> findProductById ( $ id ) ; if ( ! $ product ) { throw new NotFoundHttpException ( 'The product does not exist!' ) ; } $ dm = $ this -> container -> get ( 'doctrine.odm.mongodb.document_manager' ) ; $ dm -> remove ( $ product ) ; $ dm -> flush ( ) ; $ this -> setFlash ( 'vespolina_product_deleted' , 'success' ) ; $ url = $ this -> container -> get ( 'router' ) -> generate ( 'vespolina_product_list' ) ; return new RedirectResponse ( $ url ) ; }
Delete one product then show list
3,920
private function buildModelMap ( ) { $ this -> modelMap = ArrayHelper :: merge ( $ this -> defaultModelMap , $ this -> modelMap ) ; foreach ( $ this -> modelMap as $ modelName => $ configuration ) { Yii :: $ container -> set ( $ configuration [ 'class' ] , $ configuration ) ; } }
Builds model map setups di container
3,921
private function createVisitor ( ) { $ this -> visitor = Yii :: $ container -> get ( $ this -> modelMap [ 'Visitor' ] [ 'class' ] ) ; $ this -> visitor -> save ( ) ; return $ this -> visitor ; }
Create Visitor record
3,922
private function saveVisitor ( ) { Yii :: $ app -> session -> set ( $ this -> visitorCookieName , $ this -> visitor -> getPrimaryKey ( ) ) ; if ( ! Yii :: $ app -> request -> cookies -> has ( $ this -> visitorCookieName ) ) { $ this -> setVisitorCookie ( ) ; return ; } $ cookie = Yii :: $ app -> request -> cookies -> get ( $ this -> visitorCookieName ) ; if ( $ cookie -> expire - time ( ) <= $ this -> visitorCookieExpireTime ) { $ this -> setVisitorCookie ( ) ; } }
Store visitor_id in session and if require in cookie
3,923
private function setVisitorCookie ( ) { Yii :: $ app -> response -> cookies -> add ( new Cookie ( [ 'name' => $ this -> visitorCookieName , 'value' => $ this -> visitor -> getPrimaryKey ( ) , 'expire' => time ( ) + $ this -> visitorCookieTime , ] ) ) ; }
Add visitor cookie
3,924
public function hasVisitor ( $ visitor_id ) { if ( $ this -> visitor !== null ) { return true ; } $ model = Yii :: $ container -> get ( $ this -> modelMap [ 'Visitor' ] [ 'class' ] ) ; $ this -> visitor = $ model -> find ( ) -> where ( [ 'id' => $ visitor_id ] ) -> one ( ) ; return $ this -> visitor !== null ; }
Check if visitor exists
3,925
public function getVisitor ( ) { if ( $ this -> visitor !== null ) { return $ this -> visitor ; } if ( Yii :: $ app -> session -> has ( $ this -> visitorCookieName ) ) { $ visitor_id = Yii :: $ app -> session -> get ( $ this -> visitorCookieName ) ; } elseif ( Yii :: $ app -> request -> cookies -> has ( $ this -> visitorCookieName ) ) { $ visitor_id = Yii :: $ app -> request -> cookies -> getValue ( $ this -> visitorCookieName ) ; } if ( isset ( $ visitor_id ) && $ this -> hasVisitor ( $ visitor_id ) ) { return $ this -> visitor ; } return $ this -> createVisitor ( ) ; }
Return current Visitor
3,926
public function getQualifiedOrderByColumns ( ) { $ columns = $ this -> cmsOrderBy ; $ qualified = [ ] ; if ( empty ( $ columns ) ) return [ ] ; foreach ( $ columns as $ column => $ direction ) { $ qualified [ $ this -> getTable ( ) . '.' . $ column ] = $ direction ; } return $ qualified ; }
Get the fully qualified column name for applying the scope
3,927
public function store ( ApiStoreRequest $ request , $ crudeName ) { $ this -> crude = CrudeInstance :: get ( $ request -> crudeName ) ; $ model = $ this -> crude -> store ( $ request -> all ( ) ) ; return $ this -> successResponse ( [ 'model' => $ model , 'message' => $ this -> crude -> getCrudeSetup ( ) -> trans ( 'item_has_been_saved' ) ] ) ; }
Add new model
3,928
public function getOptionOrDefault ( $ name ) { return isset ( $ this -> options [ $ name ] ) ? $ this -> options [ $ name ] : $ this -> getDefault ( $ name ) ; }
Get an option value by name or a default option with the same name .
3,929
private function traverse ( array $ segments , & $ result = array ( ) , $ node = null ) { $ path = array ( ) ; if ( null !== $ node ) { $ path = explode ( '/' , substr ( $ node -> getPath ( ) , 1 ) ) ; } do { list ( $ element , $ bitmask ) = array_shift ( $ segments ) ; if ( $ bitmask & SelectorParser :: T_STATIC ) { $ path [ ] = $ element ; if ( $ bitmask & SelectorParser :: T_LAST ) { if ( $ node = $ this -> getNode ( $ path ) ) { $ result [ ] = $ node ; break ; } } } if ( $ bitmask & SelectorParser :: T_PATTERN ) { if ( null === $ parentNode = $ this -> getNode ( $ path ) ) { return ; } $ children = $ this -> getChildren ( $ parentNode , $ element ) ; foreach ( $ children as $ child ) { if ( $ bitmask & SelectorParser :: T_LAST ) { $ result [ ] = $ child ; } else { $ this -> traverse ( $ segments , $ result , $ child ) ; } } return ; } } while ( $ segments ) ; }
Traverse the node
3,930
protected function addEntry ( $ id , $ number , $ type , DateTime $ date , $ route , $ pdfUrl , $ translationKey = '' ) { $ this -> entries [ ] = array ( 'id' => $ id , 'number' => $ number , 'type' => $ type , 'date' => $ date , 'route' => $ route , 'pdfUrl' => $ pdfUrl , 'translationKey' => $ translationKey ) ; }
Creates and adds an entry to the exisiting entries
3,931
public function statusCodes ( ) : array { return array_map ( function ( $ status ) { return new Status ( $ status -> getCode ( ) , $ status -> getDescription ( ) ) ; } , $ this -> annotations -> named ( 'Status' ) ) ; }
returns list of possible status codes on this route
3,932
public function headers ( ) : array { return array_map ( function ( $ header ) { return new Header ( $ header -> getName ( ) , $ header -> getDescription ( ) ) ; } , $ this -> annotations -> named ( 'Header' ) ) ; }
returns list of headers on this route
3,933
public function parameters ( ) : array { return array_map ( function ( $ parameter ) { $ param = new Parameter ( $ parameter -> getName ( ) , $ parameter -> getDescription ( ) , $ parameter -> getIn ( ) ) ; if ( $ parameter -> hasValueByName ( 'required' ) && $ parameter -> isRequired ( ) ) { $ param -> markRequired ( ) ; } return $ param ; } , $ this -> annotations -> named ( 'Parameter' ) ) ; }
returns list of parameters
3,934
public function hasRole ( Role $ role ) { $ role = ! is_string ( $ role ) ? : Role :: where ( [ 'name' => $ role ] ) -> firstOrFail ( ) ; if ( $ role ) { foreach ( $ this -> roles as $ r ) { if ( $ r -> id == $ role -> id ) { return true ; } } } return false ; }
Returns true if the user has the role .
3,935
final public function compare ( $ item1 , $ item2 ) { if ( ! $ this -> isReady ( ) ) { throw new \ RuntimeException ( "The comparer is not ready, no valid callback has been set." ) ; } return call_user_func_array ( $ this -> callback , [ $ item1 , $ item2 , $ this -> options ] ) ; }
Compares two items .
3,936
public function reorder ( array $ newOrder ) { $ param = $ this -> crudeSetup -> getOrderParameters ( ) ; $ idAttr = $ param [ 'idAttr' ] ; $ orderAttr = $ param [ 'orderAttr' ] ; $ table = $ this -> model -> getTable ( ) ; $ data = collect ( $ newOrder ) -> map ( function ( $ item ) { return "({$item['id']},{$item['order']})" ; } ) -> toArray ( ) ; $ data = implode ( ',' , $ data ) ; \ DB :: statement ( "INSERT INTO {$table} (`{$idAttr}`,`{$orderAttr}`) VALUES {$data} ON DUPLICATE KEY UPDATE `{$orderAttr}`=VALUES(`{$orderAttr}`);" ) ; }
Set new order for selected items
3,937
public function setPort ( $ port ) { if ( ! ctype_digit ( $ port ) ) { trigger_error ( 'Port must be a positive integer: ' . var_export ( $ port , true ) , E_USER_ERROR ) ; } $ this -> port = $ port ; }
Sets the port on which to operate the daemon .
3,938
public function setDownloadPath ( $ downloadPath ) { if ( ! is_dir ( $ downloadPath ) || ! is_writable ( $ downloadPath ) ) { trigger_error ( 'Cannot write to directory: ' . $ downloadPath , E_USER_ERROR ) ; } $ this -> downloadPath = $ downloadPath ; }
Sets the path at which to store downloaded files .
3,939
protected function execute ( $ command ) { $ process = proc_open ( $ command , array ( 1 => array ( 'pipe' , 'w' ) , 2 => array ( 'pipe' , 'w' ) ) , $ pipes ) ; fclose ( $ pipes [ 2 ] ) ; $ this -> output = stream_get_contents ( $ pipes [ 1 ] ) ; fclose ( $ pipes [ 1 ] ) ; $ status = proc_get_status ( $ process ) ; $ this -> status = $ status [ 'exitcode' ] ; proc_close ( $ process ) ; }
Execute a shell command .
3,940
public function start ( ) { if ( $ this -> started ) { return ; } $ auth = $ this -> getAuthFlag ( ) ; $ command = 'transmission-remote -C ' . $ auth . ' -' . ( $ this -> encryption ? 'er' : 'ep' ) . ' -p ' . $ this -> port . ' -' . ( $ this -> upnp ? 'm' : 'M' ) . ( $ this -> downloadPath ? ' -w ' . $ this -> downloadPath : '' ) ; $ this -> execute ( $ command ) ; $ this -> execute ( 'transmission-remote ' . $ auth . ' -l' ) ; if ( $ this -> getStatus ( ) == 1 ) { $ this -> execute ( 'transmission-daemon' ) ; } $ this -> started = true ; }
Starts the daemon .
3,941
public function addTorrents ( $ paths ) { if ( is_array ( $ paths ) ) { $ paths = implode ( ' ' , $ paths ) ; } $ this -> execute ( 'transmission-remote ' . $ this -> getAuthFlag ( ) . ' -a ' . $ paths ) ; }
Adds a torrent to download .
3,942
protected function splitUrl ( $ url ) { $ path = parse_url ( trim ( $ url , '/' ) , PHP_URL_PATH ) ; return $ path ? explode ( '/' , $ path ) : array ( ) ; }
Get parts of a URL path
3,943
public function initPermissionsRelatedById ( $ overrideExisting = true ) { if ( null !== $ this -> collPermissionsRelatedById && ! $ overrideExisting ) { return ; } $ this -> collPermissionsRelatedById = new ObjectCollection ( ) ; $ this -> collPermissionsRelatedById -> setModel ( '\Alchemy\Component\Cerberus\Model\Permission' ) ; }
Initializes the collPermissionsRelatedById collection .
3,944
public function getPermissionsRelatedById ( Criteria $ criteria = null , ConnectionInterface $ con = null ) { $ partial = $ this -> collPermissionsRelatedByIdPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collPermissionsRelatedById || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collPermissionsRelatedById ) { $ this -> initPermissionsRelatedById ( ) ; } else { $ collPermissionsRelatedById = ChildPermissionQuery :: create ( null , $ criteria ) -> filterByPermissionRelatedByParentId ( $ this ) -> find ( $ con ) ; if ( null !== $ criteria ) { if ( false !== $ this -> collPermissionsRelatedByIdPartial && count ( $ collPermissionsRelatedById ) ) { $ this -> initPermissionsRelatedById ( false ) ; foreach ( $ collPermissionsRelatedById as $ obj ) { if ( false == $ this -> collPermissionsRelatedById -> contains ( $ obj ) ) { $ this -> collPermissionsRelatedById -> append ( $ obj ) ; } } $ this -> collPermissionsRelatedByIdPartial = true ; } return $ collPermissionsRelatedById ; } if ( $ partial && $ this -> collPermissionsRelatedById ) { foreach ( $ this -> collPermissionsRelatedById as $ obj ) { if ( $ obj -> isNew ( ) ) { $ collPermissionsRelatedById [ ] = $ obj ; } } } $ this -> collPermissionsRelatedById = $ collPermissionsRelatedById ; $ this -> collPermissionsRelatedByIdPartial = false ; } } return $ this -> collPermissionsRelatedById ; }
Gets an array of ChildPermission objects which contain a foreign key that references this object .
3,945
public function countPermissionsRelatedById ( Criteria $ criteria = null , $ distinct = false , ConnectionInterface $ con = null ) { $ partial = $ this -> collPermissionsRelatedByIdPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collPermissionsRelatedById || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collPermissionsRelatedById ) { return 0 ; } if ( $ partial && ! $ criteria ) { return count ( $ this -> getPermissionsRelatedById ( ) ) ; } $ query = ChildPermissionQuery :: create ( null , $ criteria ) ; if ( $ distinct ) { $ query -> distinct ( ) ; } return $ query -> filterByPermissionRelatedByParentId ( $ this ) -> count ( $ con ) ; } return count ( $ this -> collPermissionsRelatedById ) ; }
Returns the number of related Permission objects .
3,946
public function addPermissionRelatedById ( ChildPermission $ l ) { if ( $ this -> collPermissionsRelatedById === null ) { $ this -> initPermissionsRelatedById ( ) ; $ this -> collPermissionsRelatedByIdPartial = true ; } if ( ! $ this -> collPermissionsRelatedById -> contains ( $ l ) ) { $ this -> doAddPermissionRelatedById ( $ l ) ; } return $ this ; }
Method called to associate a ChildPermission object to this object through the ChildPermission foreign key attribute .
3,947
public function getRolePermissions ( Criteria $ criteria = null , ConnectionInterface $ con = null ) { $ partial = $ this -> collRolePermissionsPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collRolePermissions || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collRolePermissions ) { $ this -> initRolePermissions ( ) ; } else { $ collRolePermissions = ChildRolePermissionQuery :: create ( null , $ criteria ) -> filterByPermission ( $ this ) -> find ( $ con ) ; if ( null !== $ criteria ) { if ( false !== $ this -> collRolePermissionsPartial && count ( $ collRolePermissions ) ) { $ this -> initRolePermissions ( false ) ; foreach ( $ collRolePermissions as $ obj ) { if ( false == $ this -> collRolePermissions -> contains ( $ obj ) ) { $ this -> collRolePermissions -> append ( $ obj ) ; } } $ this -> collRolePermissionsPartial = true ; } return $ collRolePermissions ; } if ( $ partial && $ this -> collRolePermissions ) { foreach ( $ this -> collRolePermissions as $ obj ) { if ( $ obj -> isNew ( ) ) { $ collRolePermissions [ ] = $ obj ; } } } $ this -> collRolePermissions = $ collRolePermissions ; $ this -> collRolePermissionsPartial = false ; } } return $ this -> collRolePermissions ; }
Gets an array of ChildRolePermission objects which contain a foreign key that references this object .
3,948
public function countRolePermissions ( Criteria $ criteria = null , $ distinct = false , ConnectionInterface $ con = null ) { $ partial = $ this -> collRolePermissionsPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collRolePermissions || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collRolePermissions ) { return 0 ; } if ( $ partial && ! $ criteria ) { return count ( $ this -> getRolePermissions ( ) ) ; } $ query = ChildRolePermissionQuery :: create ( null , $ criteria ) ; if ( $ distinct ) { $ query -> distinct ( ) ; } return $ query -> filterByPermission ( $ this ) -> count ( $ con ) ; } return count ( $ this -> collRolePermissions ) ; }
Returns the number of related RolePermission objects .
3,949
public function getRolePermissionsJoinRole ( Criteria $ criteria = null , ConnectionInterface $ con = null , $ joinBehavior = Criteria :: LEFT_JOIN ) { $ query = ChildRolePermissionQuery :: create ( null , $ criteria ) ; $ query -> joinWith ( 'Role' , $ joinBehavior ) ; return $ this -> getRolePermissions ( $ query , $ con ) ; }
If this collection has already been initialized with an identical criteria it returns the collection . Otherwise if this Permission is new it will return an empty collection ; or if this Permission has previously been saved it will retrieve related RolePermissions from storage .
3,950
public function getRoles ( Criteria $ criteria = null , ConnectionInterface $ con = null ) { $ partial = $ this -> collRolesPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collRoles || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) ) { if ( null === $ this -> collRoles ) { $ this -> initRoles ( ) ; } } else { $ query = ChildRoleQuery :: create ( null , $ criteria ) -> filterByPermission ( $ this ) ; $ collRoles = $ query -> find ( $ con ) ; if ( null !== $ criteria ) { return $ collRoles ; } if ( $ partial && $ this -> collRoles ) { foreach ( $ this -> collRoles as $ obj ) { if ( ! $ collRoles -> contains ( $ obj ) ) { $ collRoles [ ] = $ obj ; } } } $ this -> collRoles = $ collRoles ; $ this -> collRolesPartial = false ; } } return $ this -> collRoles ; }
Gets a collection of ChildRole objects related by a many - to - many relationship to the current object by way of the role_permission cross - reference table .
3,951
public function countRoles ( Criteria $ criteria = null , $ distinct = false , ConnectionInterface $ con = null ) { $ partial = $ this -> collRolesPartial && ! $ this -> isNew ( ) ; if ( null === $ this -> collRoles || null !== $ criteria || $ partial ) { if ( $ this -> isNew ( ) && null === $ this -> collRoles ) { return 0 ; } else { if ( $ partial && ! $ criteria ) { return count ( $ this -> getRoles ( ) ) ; } $ query = ChildRoleQuery :: create ( null , $ criteria ) ; if ( $ distinct ) { $ query -> distinct ( ) ; } return $ query -> filterByPermission ( $ this ) -> count ( $ con ) ; } } else { return count ( $ this -> collRoles ) ; } }
Gets the number of Role objects related by a many - to - many relationship to the current object by way of the role_permission cross - reference table .
3,952
public function removeRole ( ChildRole $ role ) { if ( $ this -> getRoles ( ) -> contains ( $ role ) ) { $ rolePermission = new ChildRolePermission ( ) ; $ rolePermission -> setRole ( $ role ) ; if ( $ role -> isPermissionsLoaded ( ) ) { $ role -> getPermissions ( ) -> removeObject ( $ this ) ; } $ rolePermission -> setPermission ( $ this ) ; $ this -> removeRolePermission ( clone $ rolePermission ) ; $ rolePermission -> clear ( ) ; $ this -> collRoles -> remove ( $ this -> collRoles -> search ( $ role ) ) ; if ( null === $ this -> rolesScheduledForDeletion ) { $ this -> rolesScheduledForDeletion = clone $ this -> collRoles ; $ this -> rolesScheduledForDeletion -> clear ( ) ; } $ this -> rolesScheduledForDeletion -> push ( $ role ) ; } return $ this ; }
Remove role of this object through the role_permission cross reference table .
3,953
public static function findBySlug ( $ slug , $ locale = null ) { $ model = ( new static ) ; $ translationModel = $ model -> getTranslationModelName ( ) ; $ parentKey = $ model -> getRelationKey ( ) ; $ translationInstance = $ translationModel :: findBySlug ( $ slug , $ locale ) ; if ( empty ( $ translationInstance ) ) return null ; return static :: find ( $ translationInstance -> { $ parentKey } ) ; }
Find by slug on translated attribute
3,954
public function scopeWhereSlug ( $ query , $ slug , $ locale = null ) { return $ query -> whereHas ( 'translations' , function ( $ query ) use ( $ slug , $ locale ) { return $ query -> whereSlug ( $ slug , $ locale , true ) ; } ) ; }
Scopes query for slug on translated attribute
3,955
public function createQuery ( $ context = 'list' ) { $ query = parent :: createQuery ( $ context ) ; $ query -> leftJoin ( $ query -> getRootAlias ( ) . '.template' , 'template' ) -> addSelect ( 'template' ) -> leftJoin ( 'template.areas' , 'area' ) -> addSelect ( 'area' ) -> leftJoin ( $ query -> getRootAlias ( ) . '.metas' , 'articleMeta' ) -> addSelect ( 'articleMeta' ) -> leftJoin ( 'articleMeta.meta' , 'meta' ) -> addSelect ( 'meta' ) ; return $ query ; }
Need to override createQuery method because or list order & joins
3,956
protected function checkIntTypes ( NumericTypeInterface $ a , NumericTypeInterface $ b ) { $ a1 = ( $ a instanceof IntType ? $ a : $ a -> asIntType ( ) ) ; $ b1 = ( $ a instanceof IntType ? $ b : $ b -> asIntType ( ) ) ; return [ $ a1 , $ b1 ] ; }
Check for integer type converting if necessary
3,957
public function getConfigFactory ( ) { if ( empty ( $ this -> configFactory ) ) { $ this -> configFactory = \ Drupal :: service ( 'config.factory' ) ; } return $ this -> configFactory ; }
Gets the config factory .
3,958
public function setFile ( $ file ) { if ( empty ( $ file ) || false === stream_resolve_include_path ( $ file ) ) { throw new Exception \ InvalidArgumentException ( 'Invalid options to validator provided' ) ; } $ this -> options [ 'file' ] = $ file ; return $ this ; }
Sets the path to the file
3,959
public function setType ( $ type ) { $ this -> type = ( string ) $ type ; $ this -> getDocBlock ( ) -> getTagCollection ( ) -> removeByName ( Tag :: TAG_VAR ) ; $ tag = Tag :: createFromProperty ( $ this ) ; $ this -> getDocBlock ( ) -> addTag ( $ tag ) ; return $ this ; }
Sets the property s type .
3,960
public function toUrlQuery ( ) { $ queryData = array ( ) ; foreach ( self :: $ properties as $ p => $ setter ) { if ( $ this -> $ p !== null ) { $ queryData [ $ p ] = $ this -> $ p ; } } return http_build_query ( $ queryData ) ; }
Returns the resulting url - encoded query string .
3,961
public function set ( $ criteria ) { if ( $ criteria instanceof Criteria ) { $ this -> limit = $ criteria -> limit ; $ this -> offset = $ criteria -> offset ; $ this -> sort = $ criteria -> sort ; $ this -> filter = $ criteria -> filter ; $ this -> after = $ criteria -> after ; $ this -> loadonly = $ criteria -> loadonly ; } elseif ( is_string ( $ criteria ) ) { $ criteria = $ this -> parseHttpQuery ( $ criteria ) ; } if ( is_array ( $ criteria ) ) { foreach ( self :: $ properties as $ p => $ setter ) { if ( isset ( $ criteria [ $ p ] ) ) { $ this -> $ setter ( $ criteria [ $ p ] ) ; } } } }
Sets multiple parameters at once .
3,962
private function parseHttpQuery ( $ query ) { if ( empty ( $ query ) ) { return array ( ) ; } $ result = array ( ) ; $ parts = explode ( '&' , $ query ) ; foreach ( $ parts as $ p ) { $ keyval = explode ( '=' , $ p ) ; $ result [ urldecode ( $ keyval [ 0 ] ) ] = urldecode ( $ keyval [ 1 ] ) ; } return $ result ; }
Parses a http query into a key - value array similar to PHP s parse_str function .
3,963
public static function fromCookie ( $ key , $ default = null , $ filter = null , $ args = array ( ) ) { if ( ! $ key ) { return self :: filterArray ( $ _COOKIE , $ filter , $ args ) ; } return self :: getPassedValue ( $ key , $ default , 'C' , $ filter , $ args ) ; }
Wrapper for COOKIE input
3,964
public static function fromDelete ( $ key , $ default = null , $ filter = null , $ args = array ( ) ) { if ( ! $ key ) { $ values = array ( ) ; parse_str ( file_get_contents ( "php://input" ) , $ values ) ; return self :: filterArray ( $ values , $ filter , $ args ) ; } return self :: getPassedValue ( $ key , $ default , 'D' , $ filter , $ args ) ; }
Wrapper for DELETE input
3,965
public static function fromFiles ( $ key , $ default = null , $ filter = null , $ args = array ( ) ) { if ( ! $ key ) { return self :: filterArray ( $ _FILES , $ filter , $ args ) ; } return self :: getPassedValue ( $ key , $ default , 'F' , $ filter , $ args ) ; }
Wrapper for FILES input
3,966
public static function fromGet ( $ key , $ default = null , $ filter = null , $ args = array ( ) ) { if ( ! $ key ) { return self :: filterArray ( $ _GET , $ filter , $ args ) ; } return self :: getPassedValue ( $ key , $ default , 'G' , $ filter , $ args ) ; }
Wrapper for GET input
3,967
public static function fromPost ( $ key , $ default = null , $ filter = null , $ args = array ( ) ) { if ( ! $ key ) { return self :: filterArray ( $ _POST , $ filter , $ args ) ; } return self :: getPassedValue ( $ key , $ default , 'P' , $ filter , $ args ) ; }
Wrapper for POST input
3,968
public static function fromRequest ( $ key , $ default = null , $ filter = null , $ args = array ( ) ) { if ( ! $ key ) { return self :: filterArray ( $ _REQUEST , $ filter , $ args ) ; } return self :: getPassedValue ( $ key , $ default , 'R' , $ filter , $ args ) ; }
Wrapper for REQUEST input
3,969
protected static function filterArray ( array $ values , $ filter = null , $ args = array ( ) , $ doTrim = true ) { if ( ! $ values ) { return $ values ; } if ( ! $ filter ) { $ filter = self :: $ defaultFilter ; } if ( ! $ args ) { $ args = array ( 'flags' => self :: $ defaultFlags ) ; } foreach ( $ values as $ k => $ v ) { if ( is_array ( $ v ) ) { $ values [ $ k ] = self :: filterArray ( $ v , $ filter , $ args , $ doTrim ) ; } else { $ values [ $ k ] = filter_var ( self :: trim ( $ v , $ doTrim ) , $ filter , $ args ) ; } } return $ values ; }
Filter an array item by item . This function is recursive array safe .
3,970
private function sumField ( $ devices = null , $ partitions = null , $ field ) { $ result = 0 ; if ( $ devices ) { $ devices = ( array ) $ devices ; } if ( is_array ( $ devices ) ) { $ devices = array_flip ( $ devices ) ; } if ( $ partitions ) { $ partitions = ( array ) $ partitions ; } if ( is_array ( $ partitions ) ) { $ partitions = array_flip ( $ partitions ) ; } foreach ( $ this -> devices as $ device => $ partition ) { if ( $ devices && ! isset ( $ devices [ $ device ] ) ) { continue ; } foreach ( $ partition as $ p => $ info ) { if ( $ partitions && ! isset ( $ partitions [ $ p ] ) ) { continue ; } $ result += $ info [ $ field ] ; } } return $ result ; }
Calcuate a sum
3,971
protected function loginUser ( $ user ) { $ this -> session -> put ( config ( 'pagekit.session_key' , 'pagekit_session' ) , [ 'github_id' => $ user -> id , 'github_name' => $ user -> name , 'github_email' => $ user -> email ] ) ; $ this -> session -> save ( ) ; }
Checks if the user credentials matches the credentials stored in the config
3,972
public function getTags ( $ useDefault = null ) { if ( is_null ( $ useDefault ) ) { $ useDefault = $ this -> useDefault ; } $ tags = array ( ) ; foreach ( $ this -> tags as $ tag ) { if ( ! array_key_exists ( $ tag -> getProperty ( ) , $ tags ) ) { $ tags [ $ tag -> getProperty ( ) ] = $ tag -> getValue ( ) ; } } if ( $ useDefault ) { foreach ( $ this -> defaultTags as $ tag ) { if ( ! array_key_exists ( $ tag -> getProperty ( ) , $ tags ) ) { $ tags [ $ tag -> getProperty ( ) ] = $ tag -> getValue ( ) ; } } } return $ tags ; }
return the tags merged with the defaults
3,973
public function getConnection ( ) { if ( ! $ this -> _connection ) { $ this -> _connection = new \ Guzzle \ Http \ Client ( $ this -> getHost ( ) ) ; } return $ this -> _connection ; }
Get Guzzle RESTful client
3,974
protected function _should_load_template ( ) { return ( \ is_tax ( ) || \ is_category ( ) || \ is_tag ( ) ) && ! empty ( $ this -> term ) && in_array ( $ this -> taxonomy , $ this -> taxonomies ) ; }
Determines whether a custom template for a taxonomy term should be loaded .
3,975
private function buildFields ( array $ fields , $ indent , array & $ result ) { $ stringified_field_names = [ ] ; $ fields_with_default_value = [ ] ; foreach ( $ fields as $ field ) { if ( $ field instanceof ScalarField && $ field -> getShouldBeAddedToModel ( ) ) { $ stringified_field_names [ ] = var_export ( $ field -> getName ( ) , true ) ; if ( $ field -> getName ( ) != 'id' && $ field -> getDefaultValue ( ) !== null ) { $ fields_with_default_value [ $ field -> getName ( ) ] = $ field -> getDefaultValue ( ) ; } } } $ result [ ] = '' ; $ result [ ] = $ indent . '/**' ; $ result [ ] = $ indent . ' * Table fields that are managed by this entity.' ; $ result [ ] = $ indent . ' *' ; $ result [ ] = $ indent . ' * @var array' ; $ result [ ] = $ indent . ' */' ; $ result [ ] = $ indent . 'protected $fields = [' . implode ( ', ' , $ stringified_field_names ) . '];' ; if ( count ( $ fields_with_default_value ) ) { $ result [ ] = '' ; $ result [ ] = $ indent . '/**' ; $ result [ ] = $ indent . ' * List of default field values.' ; $ result [ ] = $ indent . ' *' ; $ result [ ] = $ indent . ' * @var array' ; $ result [ ] = $ indent . ' */' ; $ result [ ] = $ indent . 'protected $default_field_values = [' ; foreach ( $ fields_with_default_value as $ field_name => $ default_value ) { $ result [ ] = $ indent . ' ' . var_export ( $ field_name , true ) . ' => ' . var_export ( $ default_value , true ) . ',' ; } $ result [ ] = $ indent . '];' ; } }
Build field definitions .
3,976
public function buildGeneratedFields ( array $ generated_field_names , $ indent , array & $ result ) { $ result [ ] = '' ; $ result [ ] = $ indent . '/**' ; $ result [ ] = $ indent . ' * Generated fields that are loaded, but not managed by the entity..' ; $ result [ ] = $ indent . ' *' ; $ result [ ] = $ indent . ' * @var array' ; $ result [ ] = $ indent . ' */' ; $ result [ ] = $ indent . 'protected $generated_fields = [' . implode ( ', ' , array_map ( function ( $ field_name ) { return var_export ( $ field_name , true ) ; } , $ generated_field_names ) ) . '];' ; }
Build a list of generated fields .
3,977
private function buildGeneratedFieldGetter ( $ field_name , $ caster , $ indent , array & $ result ) { $ short_getter = null ; switch ( $ caster ) { case ValueCasterInterface :: CAST_INT : $ return_type = 'int' ; break ; case ValueCasterInterface :: CAST_FLOAT : $ return_type = 'float' ; break ; case ValueCasterInterface :: CAST_BOOL : $ return_type = 'bool' ; break ; case ValueCasterInterface :: CAST_DATE : $ return_type = '\\' . DateValueInterface :: class ; break ; case ValueCasterInterface :: CAST_DATETIME : $ return_type = '\\' . DateTimeValueInterface :: class ; break ; case ValueCasterInterface :: CAST_JSON : $ return_type = 'mixed' ; break ; default : $ return_type = 'string' ; } if ( $ this -> useShortGetterName ( $ field_name ) ) { $ short_getter = $ this -> getShortGetterName ( $ field_name ) ; $ lines [ ] = '' ; $ lines [ ] = '/**' ; $ lines [ ] = ' * Return value of ' . $ field_name . ' field.' ; $ lines [ ] = ' *' ; $ lines [ ] = ' * @return ' . $ return_type ; $ lines [ ] = ' */' ; $ lines [ ] = 'public function ' . $ short_getter . '()' ; $ lines [ ] = '{' ; $ lines [ ] = ' return $this->getFieldValue(' . var_export ( $ field_name , true ) . ');' ; $ lines [ ] = '}' ; } $ lines [ ] = '' ; $ lines [ ] = '/**' ; $ lines [ ] = ' * Return value of ' . $ field_name . ' field.' ; $ lines [ ] = ' *' ; $ lines [ ] = ' * @return ' . $ return_type ; if ( $ short_getter && $ this -> getStructure ( ) -> getConfig ( 'deprecate_long_bool_field_getter' ) ) { $ lines [ ] = " * @deprecated use $short_getter()" ; } $ lines [ ] = ' */' ; $ lines [ ] = 'public function ' . $ this -> getGetterName ( $ field_name ) . '()' ; $ lines [ ] = '{' ; $ lines [ ] = ' return $this->getFieldValue(' . var_export ( $ field_name , true ) . ');' ; $ lines [ ] = '}' ; $ lines [ ] = '' ; foreach ( $ lines as $ line ) { $ result [ ] = $ line ? $ indent . $ line : '' ; } }
Build getter for generated field .
3,978
private function useShortGetterName ( $ field_name ) { return substr ( $ field_name , 0 , 3 ) === 'is_' || in_array ( substr ( $ field_name , 0 , 4 ) , [ 'has_' , 'had_' , 'was_' ] ) || in_array ( substr ( $ field_name , 0 , 5 ) , [ 'were_' , 'have_' ] ) ; }
Return true if we should use a short getter name .
3,979
private function buildJsonSerialize ( array $ serialize , $ indent , array & $ result ) { if ( count ( $ serialize ) ) { $ result [ ] = '' ; $ result [ ] = $ indent . '/**' ; $ result [ ] = $ indent . ' * Prepare object properties so they can be serialized to JSON.' ; $ result [ ] = $ indent . ' *' ; $ result [ ] = $ indent . ' * @return array' ; $ result [ ] = $ indent . ' */' ; $ result [ ] = $ indent . 'public function jsonSerialize()' ; $ result [ ] = $ indent . '{' ; $ result [ ] = $ indent . ' return array_merge(parent::jsonSerialize(), [' ; foreach ( $ serialize as $ field ) { $ result [ ] = $ indent . ' ' . var_export ( $ field , true ) . ' => $this->' . $ this -> getGetterName ( $ field ) . '(),' ; } $ result [ ] = $ indent . ' ]);' ; $ result [ ] = $ indent . '}' ; } }
Build JSON serialize method if we need to serialize extra fields .
3,980
private function buildValidatePresenceLinesForScalarField ( ScalarField $ field , $ line_indent , array & $ validator_lines ) { if ( $ field instanceof RequiredInterface && $ field instanceof UniqueInterface ) { if ( $ field -> isRequired ( ) && $ field -> isUnique ( ) ) { $ validator_lines [ ] = $ line_indent . $ this -> buildValidatePresenceAndUniquenessLine ( $ field -> getName ( ) , $ field -> getUniquenessContext ( ) ) ; } elseif ( $ field -> isRequired ( ) ) { $ validator_lines [ ] = $ line_indent . $ this -> buildValidatePresenceLine ( $ field -> getName ( ) ) ; } elseif ( $ field -> isUnique ( ) ) { $ validator_lines [ ] = $ line_indent . $ this -> buildValidateUniquenessLine ( $ field -> getName ( ) , $ field -> getUniquenessContext ( ) ) ; } } elseif ( $ field instanceof RequiredInterface && $ field -> isRequired ( ) ) { $ validator_lines [ ] = $ line_indent . $ this -> buildValidatePresenceLine ( $ field -> getName ( ) ) ; } elseif ( $ field instanceof UniqueInterface && $ field -> isUnique ( ) ) { $ validator_lines [ ] = $ line_indent . $ this -> buildValidateUniquenessLine ( $ field -> getName ( ) , $ field -> getUniquenessContext ( ) ) ; } }
Build validate lines for scalar fields .
3,981
private function buildValidateUniquenessLine ( $ field_name , array $ context ) { $ field_names = [ var_export ( $ field_name , true ) ] ; foreach ( $ context as $ v ) { $ field_names [ ] = var_export ( $ v , true ) ; } return '$validator->unique(' . implode ( ', ' , $ field_names ) . ');' ; }
Build validator uniqueness line .
3,982
protected function registerDrupalPaths ( $ composer_config ) { if ( empty ( $ composer_config [ 'class-location' ] ) ) { return ; } $ this -> loader -> setClassMap ( ( array ) $ composer_config [ 'class-location' ] ) ; $ this -> load ( ) ; }
Register the path based autoloader .
3,983
protected function registerPsr ( array $ composer_config ) { $ psr0 = $ psr4 = array ( ) ; if ( ! empty ( $ composer_config [ 'psr-0' ] ) ) { $ psr0 = ( array ) $ composer_config [ 'psr-0' ] ; } if ( ! empty ( $ composer_config [ 'psr-4' ] ) ) { $ psr4 = ( array ) $ composer_config [ 'psr-4' ] ; } if ( empty ( $ psr4 ) && empty ( $ psr0 ) ) { return ; } $ this -> loader -> setPsrClassMap ( array ( 'psr-0' => $ psr0 , 'psr-4' => $ psr4 , ) ) ; $ this -> loader -> registerPsr ( $ this -> classLoader ) ; }
Use Composer s autoloader to register the PRS - 0 and PSR - 4 paths .
3,984
public function index ( ) { $ action = $ this -> Crud -> action ( ) ; $ action -> config ( 'scaffold.fields_blacklist' , [ 'created' , 'modified' ] ) ; $ this -> Crud -> execute ( ) ; }
Index method Don t show created and modified fields
3,985
public function view ( ) { $ action = $ this -> Crud -> action ( ) ; $ action -> config ( 'scaffold.relations' , false ) ; $ this -> Crud -> execute ( ) ; }
View method Related models are blacklisted because the role is already present in the main user panel
3,986
private function getNextOrderCollection ( int $ renderedArticleCount ) { $ count = $ this -> count ( ) ; $ logger = $ this -> getLogger ( ) ; $ orderCollection = null ; $ withPagination = $ this -> withPagination ( ) ; $ logger -> debug ( 'Tries to load the next order collection' , [ 'count' => $ count , 'withPagination' => $ withPagination ] ) ; if ( ( ! $ withPagination ) || ( $ renderedArticleCount < $ count ) ) { if ( $ withPagination ) { $ this -> getOrderQuery ( ) -> offset ( $ renderedArticleCount ) ; } $ this -> loadOrderCollection ( ) ; $ orderCollection = $ this -> getOrderCollection ( ) ; } return $ orderCollection ; }
Returns the next order collection or void .
3,987
private function getTotalCount ( ) : int { if ( $ this -> totalCount === - 1 ) { $ this -> setTotalCount ( $ this -> getLastResponse ( ) -> getTotal ( ) ) ; } return $ this -> totalCount ; }
Returns the total count of found orders .
3,988
private function loadOrderCollection ( ) : OrderVisitor { $ logger = $ this -> getLogger ( ) ; $ response = $ this -> getClient ( ) -> execute ( $ this -> getOrderQuery ( ) ) ; if ( $ response instanceof ErrorResponse ) { $ logger -> error ( 'Got error response loading the orders.' , [ 'response' => $ response ] ) ; throw new RuntimeException ( $ response -> getMessage ( ) ) ; } else { $ logger -> debug ( 'Found some orders.' , [ 'response' => $ response ] ) ; } $ this -> setLastResponse ( $ response ) ; $ this -> setOrderCollection ( $ this -> getLastResponse ( ) -> toObject ( ) ) ; return $ this ; }
Loads the order collection .
3,989
private function loadOrderQuery ( ) : OrderVisitor { $ logger = $ this -> getLogger ( ) ; $ query = new OrderQueryRequest ( ) ; if ( $ wheres = $ this -> getDefaultWhere ( ) ) { $ logger -> debug ( 'Added where-clause to fech orders.' , [ 'predicates' => $ wheres ] ) ; array_walk ( $ wheres , function ( string $ where ) use ( $ logger , $ query ) { $ query -> where ( $ where ) ; } ) ; } else { $ logger -> debug ( 'No where-clause to fetch orders.' ) ; } $ this -> setOrderQuery ( $ query ) ; return $ this ; }
Returns the order query request .
3,990
private function withPagination ( bool $ newStatus = true ) : bool { $ oldStatus = $ this -> withPagination ; if ( func_num_args ( ) ) { $ this -> withPagination = $ newStatus ; } return $ oldStatus ; }
Sets the pagination status for this list .
3,991
public function yieldOrders ( ) { $ usedIndex = 0 ; $ orderCollection = $ this -> getOrderCollection ( ) ; while ( $ orderCollection && count ( $ orderCollection ) ) { foreach ( $ orderCollection as $ order ) { set_time_limit ( 0 ) ; yield $ usedIndex ++ => $ order ; } $ orderCollection = $ this -> getNextOrderCollection ( $ usedIndex ) ; } }
Yields all found orders .
3,992
public function addPanel ( Panel $ panel ) { $ id = $ panel -> getId ( ) ; if ( ! empty ( $ this -> _panels [ $ id ] ) ) { throw new BugException ( '[FireBug] No panels exist with ID "' . $ id . '".' ) ; } $ this -> _panels [ $ id ] = $ panel ; }
Adds a Fire \ Bug \ Panel object to the the array of panels .
3,993
public function render ( ) { if ( $ this -> _enabled ) { if ( php_sapi_name ( ) === 'cli' ) { echo 'FireBug: ' . $ this -> getLoadTime ( ) . ' milliseconds' . "\n" ; } else { ob_start ( ) ; include $ this -> _template ; $ debugPanel = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ debugPanel ; } } }
Method used to render FireBug .
3,994
public function add ( string $ key , $ object ) { $ key = self :: ProcessKey ( __METHOD__ , $ key ) ; $ objectType = gettype ( $ object ) ; switch ( $ objectType ) { case "object" : $ this -> repository -> push ( $ object , $ key ) ; return true ; case "string" : return $ this -> service ( $ key ) -> class ( $ object ) ; default : throw new DependencyInjectionException ( sprintf ( 'Cannot store "%s" in Dependency Injection container' , $ objectType ) ) ; } }
Store an instance or add new server
3,995
public function request ( $ method , $ url , array $ params = [ ] , $ outFile = '' , $ returnBool = \ false , $ arrayKey = '' , $ verifyPeer = \ true ) { list ( $ url , $ contextOptions ) = $ this -> configureRequestOptions ( $ url , $ method , $ params , $ verifyPeer ) ; $ fp = @ fopen ( $ url , 'rb' , \ false , stream_context_create ( $ contextOptions ) ) ; $ headers = stream_get_meta_data ( $ fp ) [ 'wrapper_data' ] ; return $ this -> handleRequest ( $ fp , $ headers , $ outFile , $ returnBool , $ arrayKey ) ; }
Makes an HTTP request to put . io s API and returns the response . Relies on native PHP functions .
3,996
public function match ( $ httpMethod , $ path ) { $ path = $ this -> parsePath ( $ path ) ; if ( ( $ route = $ this -> collector -> findStaticRoute ( $ httpMethod , $ path ) ) || ( $ route = $ this -> matchDynamicRoute ( $ httpMethod , $ path ) ) ) { $ route -> setMatcher ( $ this ) ; return $ route ; } $ this -> matchSimilarRoute ( $ httpMethod , $ path ) ; }
Find a route that matches the given arguments .
3,997
protected function matchDynamicRoute ( $ httpMethod , $ path ) { if ( $ routes = $ this -> collector -> findDynamicRoutes ( $ httpMethod , $ path ) ) { $ this -> parser = $ this -> collector -> getParser ( ) ; foreach ( array_chunk ( $ routes , round ( 1 + 3.3 * log ( count ( $ routes ) ) ) , true ) as $ chunk ) { array_map ( [ $ this , "buildRoute" ] , $ chunk ) ; list ( $ pattern , $ map ) = $ this -> buildGroup ( $ chunk ) ; if ( ! preg_match ( $ pattern , $ path , $ matches ) ) { continue ; } $ route = $ map [ count ( $ matches ) ] ; unset ( $ matches [ 0 ] ) ; $ route -> setParams ( array_combine ( $ route -> getParams ( ) , array_filter ( $ matches ) ) ) ; return $ route ; } } return false ; }
Find and return the request dynamic route based on the compiled data and Path .
3,998
protected function buildRoute ( Route $ route ) { if ( $ route -> getBlock ( ) ) { return $ route ; } list ( $ pattern , $ params ) = $ this -> parsePlaceholders ( $ route -> getPattern ( ) ) ; return $ route -> setPatternWithoutReset ( $ pattern ) -> setParams ( $ params ) -> setBlock ( true ) ; }
Parse the dynamic segments of the pattern and replace then for corresponding regex .
3,999
protected function buildGroup ( array $ routes ) { $ groupCount = ( int ) $ map = $ regex = [ ] ; foreach ( $ routes as $ route ) { $ params = $ route -> getParams ( ) ; $ paramsCount = count ( $ params ) ; $ groupCount = max ( $ groupCount , $ paramsCount ) + 1 ; $ regex [ ] = $ route -> getPattern ( ) . str_repeat ( "()" , $ groupCount - $ paramsCount - 1 ) ; $ map [ $ groupCount ] = $ route ; } return [ "~^(?|" . implode ( "|" , $ regex ) . ")$~" , $ map ] ; }
Group several dynamic routes patterns into one big regex and maps the routes to the pattern positions in the big regex .