idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
24,400 | public function setFetchMode ( $ mode , $ complement_info = null , array $ ctor_args = array ( ) ) { $ this -> fetchMode = new FetchMode ( $ mode , $ complement_info , $ ctor_args ) ; } | Sets fetch mode for this result set |
24,401 | public function setCursorMode ( $ mode ) { switch ( $ mode ) { case DB :: CURSOR_FIRST : case DB :: CURSOR_PREV : case DB :: CURSOR_NEXT : case DB :: CURSOR_LAST : $ this -> cursorMode = $ mode ; break ; default : throw new \ InvalidArgumentException ( 'Invalid cursor mode' ) ; } } | Sets cursor fetching mode for next fetch |
24,402 | final private function prefetch ( ) { static $ prefetched = false ; if ( ! $ prefetched ) { $ prefetched = true ; while ( $ row = $ this -> doFetch ( ) ) $ this -> prefetched [ ] = $ row ; } } | Prefetch method allows to load in memory all the rows quickly and allows for a faster acces with scrollable possibilities . |
24,403 | final private function parseFetched ( array $ row , FetchMode $ fetchmode ) { foreach ( $ row as $ tag => $ value ) { if ( isset ( $ this -> parameters [ $ tag ] ) ) { $ param = & $ this -> parameters [ $ tag ] [ 'param' ] ; $ type = $ this -> parameters [ $ tag ] [ 'type' ] ; $ param = $ this -> connection -> quote ( $ value , $ type ) ; } } if ( $ fetchmode -> hasMode ( DB :: FETCH_BOTH ) ) return array_merge ( $ row , array_values ( $ row ) ) ; if ( $ fetchmode -> hasMode ( DB :: FETCH_ASSOC ) ) return $ row ; if ( $ fetchmode -> hasMode ( DB :: FETCH_NUM ) ) return array_values ( $ row ) ; if ( $ fetchmode -> hasMode ( DB :: FETCH_COLUMN ) ) { $ values = array_values ( $ row ) ; return isset ( $ values [ $ fetchmode -> col ] ) ? $ values [ $ fetchmode -> col ] : null ; } if ( $ fetchmode -> hasMode ( DB :: FETCH_OBJ ) ) return ( object ) $ row ; if ( $ fetchmode -> hasMode ( DB :: FETCH_CLASS ) ) { $ classname = $ fetchmode -> hasMode ( DB :: FETCH_CLASSTYPE ) ? array_shift ( $ row ) : $ fetchmode -> classname ; $ refl = new \ ReflectionClass ( $ classname ) ; $ obj = $ fetchmode -> hasMode ( DB :: FETCH_PROPS_EARLY ) ? $ refl -> newInstanceWithoutConstructor ( ) : $ refl -> newInstanceArgs ( $ fetchmode -> ctor_args ) ; $ refl = new \ ReflectionObject ( $ obj ) ; foreach ( $ row as $ tag => $ value ) { if ( $ refl -> hasProperty ( $ tag ) ) $ refl -> getProperty ( $ tag ) -> setValue ( $ obj , $ value ) ; else $ obj -> $ tag = $ value ; } if ( $ fetchmode -> hasMode ( DB :: FETCH_PROPS_EARLY ) ) $ refl -> getConstructor ( ) -> invokeArgs ( $ obj , $ fetchmode -> ctor_args ) ; return $ obj ; } if ( $ fetchmode -> hasMode ( DB :: FETCH_INTO ) ) { $ refl = new \ ReflectionObject ( $ fetchmode -> obj ) ; foreach ( $ row as $ tag => $ value ) { if ( $ refl -> hasProperty ( $ tag ) ) $ refl -> getProperty ( $ tag ) -> setValue ( $ obj , $ value ) ; else $ obj -> $ tag = $ value ; } } } | Parse a fetched row using fetch mode . This method also populates bound columns . |
24,404 | public function fetch ( $ mode = null , $ complement_info = null , array $ ctor_args = array ( ) ) { $ fetchmode = is_null ( $ mode ) ? $ this -> fetchMode : new FetchMode ( $ mode , $ complement_info , $ ctor_args ) ; switch ( $ this -> cursorMode ) { case DB :: CURSOR_FIRST : $ this -> rewind ( ) ; break ; case DB :: CURSOR_PREV : $ this -> prev ( ) ; break ; case DB :: CURSOR_NEXT : $ this -> next ( ) ; break ; case DB :: CURSOR_LAST : $ this -> end ( ) ; break ; } $ this -> setCursorMode ( DB :: CURSOR_NEXT ) ; return $ this -> valid ( ) ? $ this -> parseFetched ( $ this -> current ( ) , $ fetchmode ) : false ; } | Fetches next row |
24,405 | public function fetchAll ( $ mode = null , $ complement_info = null , array $ ctor_args = array ( ) ) { $ fetchmode = is_null ( $ mode ) ? $ this -> fetchMode : new FetchMode ( $ mode , $ complement_info , $ ctor_args ) ; $ rows = array ( ) ; foreach ( $ this -> prefetched as $ row ) { if ( $ fetchmode -> hasMode ( DB :: FETCHALL_KEY_PAIR ) ) { $ rows [ array_shift ( $ row ) ] = array_shift ( $ row ) ; } elseif ( $ fetchmode -> hasMode ( DB :: FETCHALL_UNIQUE ) ) { $ rows [ array_shift ( $ row ) ] = $ this -> parseFetched ( $ rows , $ fetchmode ) ; } else { $ rows [ ] = $ this -> parseFetched ( $ rows , $ fetchmode ) ; } } return $ rows ; } | Fetches all found rows as an array |
24,406 | private function loadDirectoryFromAutoloader ( ) { $ spl = spl_autoload_functions ( ) ; $ dirs = array ( ) ; foreach ( $ spl as $ item ) { $ object = $ item [ 0 ] ; if ( ! $ object instanceof ClassLoader ) { continue ; } $ temp = array_merge ( $ object -> getPrefixes ( ) , $ object -> getPrefixesPsr4 ( ) ) ; foreach ( $ temp as $ name => $ dir ) { if ( false === strpos ( $ name , 'Dotfiles' ) ) { continue ; } foreach ( $ dir as $ num => $ path ) { $ path = realpath ( $ path ) ; if ( $ path && is_dir ( $ path ) && ! in_array ( $ path , $ dirs ) ) { $ dirs [ ] = $ path ; } } } } return $ dirs ; } | Load available plugins directory . |
24,407 | private function loadPlugins ( ) : void { $ finder = Finder :: create ( ) ; $ finder -> name ( '*Plugin.php' ) ; if ( is_dir ( $ dir = __DIR__ . '/../Plugins' ) ) { $ finder -> in ( __DIR__ . '/../Plugins' ) ; } $ dirs = $ this -> loadDirectoryFromAutoloader ( ) ; $ finder -> in ( $ dirs ) ; foreach ( $ finder -> files ( ) as $ file ) { $ namespace = 'Dotfiles\\Plugins\\' . str_replace ( 'Plugin.php' , '' , $ file -> getFileName ( ) ) ; $ className = $ namespace . '\\' . str_replace ( '.php' , '' , $ file -> getFileName ( ) ) ; if ( class_exists ( $ className ) ) { $ plugin = new $ className ( ) ; $ this -> registerPlugin ( $ plugin ) ; } } } | Load available plugins . |
24,408 | private function registerPlugin ( Plugin $ plugin ) : void { if ( $ this -> hasPlugin ( $ plugin -> getName ( ) ) ) { return ; } $ this -> plugins [ $ plugin -> getName ( ) ] = $ plugin ; } | Register plugin . |
24,409 | public function filterByIsTutorial ( $ isTutorial = null , $ comparison = null ) { if ( is_string ( $ isTutorial ) ) { $ isTutorial = in_array ( strtolower ( $ isTutorial ) , array ( 'false' , 'off' , '-' , 'no' , 'n' , '0' , '' ) ) ? false : true ; } return $ this -> addUsingAlias ( VideoTableMap :: COL_IS_TUTORIAL , $ isTutorial , $ comparison ) ; } | Filter the query on the is_tutorial column |
24,410 | public function filterByAthleteId ( $ athleteId = null , $ comparison = null ) { if ( is_array ( $ athleteId ) ) { $ useMinMax = false ; if ( isset ( $ athleteId [ 'min' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_ATHLETE_ID , $ athleteId [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ athleteId [ 'max' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_ATHLETE_ID , $ athleteId [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( VideoTableMap :: COL_ATHLETE_ID , $ athleteId , $ comparison ) ; } | Filter the query on the athlete_id column |
24,411 | public function filterByUploaderId ( $ uploaderId = null , $ comparison = null ) { if ( is_array ( $ uploaderId ) ) { $ useMinMax = false ; if ( isset ( $ uploaderId [ 'min' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_UPLOADER_ID , $ uploaderId [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ uploaderId [ 'max' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_UPLOADER_ID , $ uploaderId [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( VideoTableMap :: COL_UPLOADER_ID , $ uploaderId , $ comparison ) ; } | Filter the query on the uploader_id column |
24,412 | public function filterByReferenceId ( $ referenceId = null , $ comparison = null ) { if ( is_array ( $ referenceId ) ) { $ useMinMax = false ; if ( isset ( $ referenceId [ 'min' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_REFERENCE_ID , $ referenceId [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ referenceId [ 'max' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_REFERENCE_ID , $ referenceId [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( VideoTableMap :: COL_REFERENCE_ID , $ referenceId , $ comparison ) ; } | Filter the query on the reference_id column |
24,413 | public function filterByPosterUrl ( $ posterUrl = null , $ comparison = null ) { if ( null === $ comparison ) { if ( is_array ( $ posterUrl ) ) { $ comparison = Criteria :: IN ; } elseif ( preg_match ( '/[\%\*]/' , $ posterUrl ) ) { $ posterUrl = str_replace ( '*' , '%' , $ posterUrl ) ; $ comparison = Criteria :: LIKE ; } } return $ this -> addUsingAlias ( VideoTableMap :: COL_POSTER_URL , $ posterUrl , $ comparison ) ; } | Filter the query on the poster_url column |
24,414 | public function filterByProvider ( $ provider = null , $ comparison = null ) { if ( null === $ comparison ) { if ( is_array ( $ provider ) ) { $ comparison = Criteria :: IN ; } elseif ( preg_match ( '/[\%\*]/' , $ provider ) ) { $ provider = str_replace ( '*' , '%' , $ provider ) ; $ comparison = Criteria :: LIKE ; } } return $ this -> addUsingAlias ( VideoTableMap :: COL_PROVIDER , $ provider , $ comparison ) ; } | Filter the query on the provider column |
24,415 | public function filterByProviderId ( $ providerId = null , $ comparison = null ) { if ( null === $ comparison ) { if ( is_array ( $ providerId ) ) { $ comparison = Criteria :: IN ; } elseif ( preg_match ( '/[\%\*]/' , $ providerId ) ) { $ providerId = str_replace ( '*' , '%' , $ providerId ) ; $ comparison = Criteria :: LIKE ; } } return $ this -> addUsingAlias ( VideoTableMap :: COL_PROVIDER_ID , $ providerId , $ comparison ) ; } | Filter the query on the provider_id column |
24,416 | public function filterByPlayerUrl ( $ playerUrl = null , $ comparison = null ) { if ( null === $ comparison ) { if ( is_array ( $ playerUrl ) ) { $ comparison = Criteria :: IN ; } elseif ( preg_match ( '/[\%\*]/' , $ playerUrl ) ) { $ playerUrl = str_replace ( '*' , '%' , $ playerUrl ) ; $ comparison = Criteria :: LIKE ; } } return $ this -> addUsingAlias ( VideoTableMap :: COL_PLAYER_URL , $ playerUrl , $ comparison ) ; } | Filter the query on the player_url column |
24,417 | public function filterByWidth ( $ width = null , $ comparison = null ) { if ( is_array ( $ width ) ) { $ useMinMax = false ; if ( isset ( $ width [ 'min' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_WIDTH , $ width [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ width [ 'max' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_WIDTH , $ width [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( VideoTableMap :: COL_WIDTH , $ width , $ comparison ) ; } | Filter the query on the width column |
24,418 | public function filterByHeight ( $ height = null , $ comparison = null ) { if ( is_array ( $ height ) ) { $ useMinMax = false ; if ( isset ( $ height [ 'min' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_HEIGHT , $ height [ 'min' ] , Criteria :: GREATER_EQUAL ) ; $ useMinMax = true ; } if ( isset ( $ height [ 'max' ] ) ) { $ this -> addUsingAlias ( VideoTableMap :: COL_HEIGHT , $ height [ 'max' ] , Criteria :: LESS_EQUAL ) ; $ useMinMax = true ; } if ( $ useMinMax ) { return $ this ; } if ( null === $ comparison ) { $ comparison = Criteria :: IN ; } } return $ this -> addUsingAlias ( VideoTableMap :: COL_HEIGHT , $ height , $ comparison ) ; } | Filter the query on the height column |
24,419 | public function useFeaturedSkillQuery ( $ relationAlias = null , $ joinType = Criteria :: LEFT_JOIN ) { return $ this -> joinFeaturedSkill ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'FeaturedSkill' , '\gossi\trixionary\model\SkillQuery' ) ; } | Use the FeaturedSkill relation Skill object |
24,420 | public function useFeaturedTutorialSkillQuery ( $ relationAlias = null , $ joinType = Criteria :: LEFT_JOIN ) { return $ this -> joinFeaturedTutorialSkill ( $ relationAlias , $ joinType ) -> useQuery ( $ relationAlias ? $ relationAlias : 'FeaturedTutorialSkill' , '\gossi\trixionary\model\SkillQuery' ) ; } | Use the FeaturedTutorialSkill relation Skill object |
24,421 | protected function getPages ( $ totalPages , $ currentPage ) { $ range = range ( 1 , $ totalPages ) ; $ pages = [ ] ; foreach ( $ range as $ page ) { $ pages [ ] = [ 'number' => $ page , 'active' => ( int ) $ page === ( int ) $ currentPage ] ; } return $ pages ; } | Returns an array containing all page numbers |
24,422 | protected function getNextPage ( $ totalPages , $ offset , $ limit ) { $ nextPage = ( $ offset / $ limit ) + 2 ; if ( $ nextPage > $ totalPages ) { return null ; } return $ nextPage ; } | Returns the next page or false if last page |
24,423 | public function set ( $ key , $ value , $ expiration = 0 ) { $ this -> cache -> save ( $ key , $ value , $ expiration ) ; } | Puts data into cache . |
24,424 | public function increment ( $ key , $ value = 1 , $ expiration = 0 ) { $ new = intval ( $ this -> get ( $ key ) ) ; $ new += $ value ; $ this -> set ( $ key , $ new , $ expiration ) ; } | Increment a key . |
24,425 | public function decrement ( $ key , $ value = 1 , $ expiration = 0 ) { $ new = intval ( $ this -> get ( $ key ) ) ; $ new -= $ value ; $ this -> set ( $ key , $ new , $ expiration ) ; } | Decrement a key . |
24,426 | protected function recv ( ) { if ( ( $ line = fgets ( $ this -> handle ) ) && ( $ line = trim ( $ line ) ) ) { if ( $ this -> logger ) { $ this -> logger -> onReceive ( $ line ) ; } return $ line ; } throw new \ RuntimeException ( "failed to receive data from {$this->server}" ) ; } | Recv response from server |
24,427 | public static function register ( ) { self :: $ list = [ ] ; self :: $ list [ 'post' ] = ! isset ( $ _POST ) ? : $ _POST ; self :: $ list [ 'get' ] = ! isset ( $ _GET ) ? : $ _GET ; self :: $ list [ 'session' ] = ! isset ( $ _SESSION ) ? : $ _SESSION ; self :: $ list [ 'cookie' ] = ! isset ( $ _COOKIE ) ? : $ _COOKIE ; self :: $ list [ 'files' ] = ! isset ( $ _FILES ) ? : $ _FILES ; self :: $ list [ 'server' ] = ! isset ( $ _SERVER ) ? : $ _SERVER ; self :: $ list [ 'env' ] = ! isset ( $ _ENV ) ? : $ _ENV ; self :: $ list [ 'request' ] = ! isset ( $ _REQUEST ) ? : $ _REQUEST ; return self :: $ list ; } | regsiter all http input vars . |
24,428 | public function createEntity ( $ className , array $ fields = [ ] ) { $ metadata = $ this -> getEntityMetadata ( $ className ) ; if ( is_null ( $ metadata ) ) { return null ; } $ reflection = $ metadata -> getReflectionClass ( ) ; try { $ entity = $ reflection -> newInstance ( ) ; } catch ( \ Exception $ e ) { $ entity = $ reflection -> newInstanceWithoutConstructor ( ) ; } foreach ( $ fields as $ fieldName => $ fieldValue ) { if ( self :: IDENTITY === $ fieldName ) { $ property = $ reflection -> getProperty ( $ this -> getEntityIdName ( $ className ) ) ; } else { $ property = $ reflection -> getProperty ( $ fieldName ) ; } try { $ property -> setValue ( $ entity , $ fieldValue ) ; } catch ( \ Exception $ e ) { $ property -> setAccessible ( true ) ; $ property -> setValue ( $ entity , $ fieldValue ) ; $ property -> setAccessible ( false ) ; } } return $ entity ; } | Create instance of the class which managed by Doctrine by received class name |
24,429 | public function getEntityClassFull ( $ entity ) { $ entity = $ this -> toString ( $ entity ) ; if ( isset ( $ this -> cache [ $ entity ] ) ) { return $ entity ; } if ( $ this -> managed || $ this -> isManagedByDoctrine ( $ entity ) ) { $ classMetaData = $ this -> entityManager -> getClassMetadata ( $ entity ) ; $ entity = $ classMetaData -> getName ( ) ; $ this -> cache [ $ entity ] = [ 'metadata' => $ classMetaData ] ; $ this -> managed = false ; } else { $ this -> cache [ $ entity ] = [ ] ; } return $ entity ; } | Returns full name of the received entity or class name . |
24,430 | public function getEntityClassShort ( $ entity ) { $ cacheKey = 'short' ; $ entity = $ this -> getEntityClassFull ( $ entity ) ; $ short = $ this -> getFromCache ( $ entity , $ cacheKey ) ; if ( false !== $ short ) { return $ short ; } foreach ( $ this -> entityManager -> getConfiguration ( ) -> getEntityNamespaces ( ) as $ short => $ full ) { if ( false === strpos ( $ entity , $ full ) ) { continue ; } $ short .= ':' . ltrim ( str_replace ( $ full , '' , $ entity ) , '\\' ) ; $ this -> cache [ $ full ] [ $ cacheKey ] = $ short ; return $ short ; } return $ entity ; } | Returns short name of the received entity or class name . |
24,431 | public function getEntityMetadata ( $ entity ) { if ( ! $ this -> isManagedByDoctrine ( $ entity ) ) { return null ; } $ cacheKey = 'metadata' ; $ entity = $ this -> getEntityClassFull ( $ entity ) ; $ metadata = $ this -> getFromCache ( $ entity , $ cacheKey ) ; if ( false !== $ metadata ) { return $ metadata ; } $ metadata = $ this -> entityManager -> getClassMetadata ( $ entity ) ; $ this -> cache [ $ metadata -> getName ( ) ] [ $ cacheKey ] = $ metadata ; return $ metadata ; } | Returns ClassMetadata object for received entity |
24,432 | public function isManagedByDoctrine ( $ entity ) { $ cacheKey = 'managed' ; $ entity = $ this -> toString ( $ entity ) ; $ isManaged = $ this -> getFromCache ( $ entity , $ cacheKey , null ) ; if ( null !== $ isManaged ) { return $ isManaged ; } try { $ this -> managed = $ isManaged = ( bool ) $ this -> entityManager -> getReference ( $ entity , 0 ) ; $ entity = $ this -> getEntityClassFull ( $ entity ) ; } catch ( \ Exception $ e ) { $ isManaged = false ; } $ this -> cache [ $ entity ] [ $ cacheKey ] = $ isManaged ; return $ isManaged ; } | Returns is received entity managed by doctrine or not |
24,433 | private function getFromCache ( $ className , $ property , $ default = false ) { return empty ( $ this -> cache [ $ className ] [ $ property ] ) ? $ default : $ this -> cache [ $ className ] [ $ property ] ; } | Returns appropriated property value form the local cache if exists . Otherwise return default value . |
24,434 | public function setOptions ( array $ options = array ( ) ) { $ options [ 'inited' ] = true ; $ resolver = new OptionsResolver ( ) ; $ this -> configureOptions ( $ resolver ) ; $ options = $ resolver -> resolve ( $ options ) ; $ this -> options = array_merge ( $ this -> options , $ options ) ; if ( empty ( $ this -> options [ 'blocks' ] [ 'header' ] ) ) { $ this -> options [ 'header' ] = false ; } if ( ! $ this -> options [ 'header' ] ) { $ this -> options [ 'css' ] = trim ( $ this -> options [ 'css' ] . ' no page header' ) ; } if ( isset ( $ options [ 'keywords' ] ) ) { $ this -> options [ 'metas' ] [ 'keywords' ] = $ options [ 'keywords' ] ; } if ( isset ( $ options [ 'description' ] ) ) { $ this -> options [ 'metas' ] [ 'description' ] = $ options [ 'description' ] ; } if ( $ seo = $ this -> seoPage ) { $ seo -> setTitle ( $ this -> options [ 'title' ] ) ; $ seo -> addHtmlAttributes ( 'lang' , $ this -> options [ 'locale' ] ) ; if ( $ this -> options [ 'canonical' ] ) { $ seo -> setLinkCanonical ( $ this -> options [ 'canonical' ] ) ; } foreach ( $ this -> options [ 'metas' ] as $ key => $ value ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ k => $ v ) { $ seo -> addMeta ( 'property' , $ k , $ v ) ; } } else { $ seo -> addMeta ( 'name' , $ key , $ value ) ; } } } } | Set page options . |
24,435 | private function parse ( ) { $ this -> rawDocblock = $ this -> reflection -> getDocComment ( ) ; $ raw = str_replace ( "\r\n" , "\n" , $ this -> rawDocblock ) ; $ lines = explode ( "\n" , $ raw ) ; $ matches = null ; switch ( count ( $ lines ) ) { case 1 : if ( ! preg_match ( '#\\/\\*\\*([^*]*)\\*\\/#' , $ lines [ 0 ] , $ matches ) ) { return ; } $ lines [ 0 ] = substr ( $ lines [ 0 ] , 3 , - 2 ) ; break ; case 2 : break ; default : array_shift ( $ lines ) ; array_pop ( $ lines ) ; break ; } $ this -> parseLines ( $ lines ) ; } | Parse the docblock . |
24,436 | private function parseLines ( $ lines ) { foreach ( $ lines as $ line ) { $ line = preg_replace ( '#^[ \t\*]*#' , '' , $ line ) ; if ( strlen ( $ line ) < 2 ) { continue ; } if ( preg_match ( '#@([^ ]+)(.*)#' , $ line , $ matches ) ) { $ tag_name = $ matches [ 1 ] ; $ tag_value = trim ( $ matches [ 2 ] ) ; if ( isset ( $ this -> tags [ $ tag_name ] ) ) { if ( ! is_array ( $ this -> tags [ $ tag_name ] ) ) { $ this -> tags [ $ tag_name ] = [ $ this -> tags [ $ tag_name ] ] ; } $ this -> tags [ $ tag_name ] [ ] = $ tag_value ; } else { $ this -> tags [ $ tag_name ] = $ tag_value ; } continue ; } $ this -> comment .= "$line\n" ; } $ this -> comment = trim ( $ this -> comment ) ; } | Parse the lines from the docblock . |
24,437 | public function getTag ( string $ name , $ default = null ) { return isset ( $ this -> tags [ $ name ] ) ? $ this -> tags [ $ name ] : $ default ; } | Get a tag by name . |
24,438 | protected function getResolveMethod ( ) { if ( is_array ( $ this -> resolveMethod ) ) { $ method = $ this -> resolveMethod ; } else { if ( strpos ( $ this -> resolveMethod , 'model:' ) >= 0 ) { $ method = substr ( $ this -> resolveMethod , strpos ( $ this -> resolveMethod , ':' ) + 1 ) ; return $ method ; } else { if ( strpos ( $ this -> resolveMethod , 'self:' ) >= 0 ) { $ method = [ $ this , substr ( $ this -> resolveMethod , strpos ( $ this -> resolveMethod , ':' ) + 1 ) ] ; } else { throw new LogicException ( "Unable to determine entity resolve method." ) ; } } } if ( ! method_exists ( $ method [ 0 ] , $ method [ 1 ] ) ) { throw new LogicException ( "Resolve method does not exist" ) ; } return $ method ; } | Get the resolve method for the query . |
24,439 | private function createErrorHtml ( bool $ dismissable = false ) { $ html = ' <div class="alert alert-danger' . ( $ dismissable == true ? ' alert-dismissible' : '' ) . '" role="alert" id="core-error-' . $ this -> throwable -> getCode ( ) . '">' ; if ( $ dismissable ) { $ html .= '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>' ; } switch ( true ) { case $ this -> public : $ html .= $ this -> getHeadline ( ) ; $ html .= $ this -> getMessage ( ) ; $ html .= $ this -> getFileinfo ( ) ; $ html .= $ this -> getTrace ( ) ; break ; default : $ html .= ' <h3 class="no-top-margin">Error</h3> <p>Sorry for that! Webmaster has been informed. Please try again later.</p>' ; } $ html .= ' </div>' ; return $ html ; } | Creates html error message |
24,440 | public static function generateTemplateWidget ( $ model ) { $ templateWidget = Html :: beginTag ( 'div' , [ 'data-id' => ( string ) $ model -> _id , 'data-category' => $ model -> category , 'class' => 'let_widget_origin' ] ) ; $ templateWidget .= $ model -> title ; $ templateWidget .= Html :: endTag ( 'div' ) ; return $ templateWidget ; } | Ham hien thi widget khi duoc tao qua namespace |
24,441 | private static function getInputByType ( $ type = 'text' , $ templateSetting = null , $ keySetting = null , $ value = null , $ items = [ ] ) { switch ( $ type ) { case 'textarea' : $ templateSetting = Html :: textarea ( $ keySetting , $ value , [ 'class' => 'form-control' , 'title' => $ keySetting ] ) ; break ; case 'date' : $ templateSetting = DateControl :: widget ( [ 'name' => $ keySetting , 'value' => $ value , 'type' => DateControl :: FORMAT_DATE , 'ajaxConversion' => false , 'options' => [ 'pluginOptions' => [ 'autoclose' => true ] , 'options' => [ 'title' => $ keySetting ] , ] , 'displayFormat' => 'dd-MM-yyyy' , 'saveFormat' => 'yyyy-MM-dd' , ] ) ; break ; case 'datetime' : $ templateSetting = DateControl :: widget ( [ 'name' => $ keySetting , 'value' => $ value , 'type' => DateControl :: FORMAT_DATETIME , 'ajaxConversion' => false , 'options' => [ 'pluginOptions' => [ 'autoclose' => true ] , 'options' => [ 'title' => $ keySetting ] , ] , 'saveFormat' => 'yyyy-MM-dd' , ] ) ; break ; case 'daterange' : $ templateSetting = DateRangePicker :: widget ( [ 'name' => $ keySetting , 'value' => $ value , 'presetDropdown' => true , 'hideInput' => true , 'options' => [ 'title' => $ keySetting ] , ] ) ; break ; case 'dropdown' : $ templateSetting = Html :: dropDownList ( $ keySetting , $ value , $ items , [ 'class' => 'form-control' , 'title' => $ keySetting ] ) ; break ; case 'checkbox' : $ templateSetting = Html :: checkboxList ( $ keySetting , $ value , $ items , [ 'class' => 'form-control' , 'title' => $ keySetting ] ) ; break ; case 'radio' : $ templateSetting = Html :: radioList ( $ keySetting , $ value , $ items , [ 'class' => 'form-control' , 'title' => $ keySetting ] ) ; break ; default : $ templateSetting = Html :: textInput ( $ keySetting , $ value , [ 'class' => 'form-control' , 'title' => $ keySetting ] ) ; break ; } return $ templateSetting ; } | Ham get html cho input theo type |
24,442 | public static function getDaysInMonth ( $ month = '' , $ year = '' ) { $ firstOfSpecifiedMonth = self :: getFirstOfMonth ( $ month , $ year ) ; $ numDays = date ( "t" , $ firstOfSpecifiedMonth ) ; return $ numDays ; } | Fetches the number of days in a given month . |
24,443 | public static function roundTimestampToDay ( $ timestamp ) { $ day = date ( 'd' , $ timestamp ) ; $ month = date ( 'm' , $ timestamp ) ; $ year = date ( 'Y' , $ timestamp ) ; $ roundedTimestamp = mktime ( 0 , 0 , 0 , $ month , $ day , $ year ) ; return $ roundedTimestamp ; } | Rounds a timestamp down to midnight of the day it was taken . |
24,444 | public static function roundTimestampToWeek ( $ timestamp ) { $ roundedToDay = self :: roundTimestampToDay ( $ timestamp ) ; $ weekDay = date ( 'w' , $ roundedToDay ) ; $ daysToSubtract = $ weekDay - 1 ; $ roundedToWeek = strtotime ( "-" . $ daysToSubtract . " day" , $ roundedToDay ) ; return $ roundedToWeek ; } | Rounds a timestamp down to midnight on Monday of time it was taken |
24,445 | public static function roundTimestampDownToMonth ( $ timestamp ) { $ month = date ( 'n' , $ timestamp ) ; $ year = date ( 'Y' , $ timestamp ) ; $ roundedTimestamp = mktime ( 0 , 0 , 0 , $ month , $ day = "01" , $ year ) ; return $ roundedTimestamp ; } | Rounds a timestamp down to midnight on the first of the month it was taken |
24,446 | public static function roundTimestampToYear ( $ timestamp ) { $ year = date ( 'Y' , $ timestamp ) ; $ roundedTimestamp = mktime ( 0 , 0 , 0 , $ month = 1 , $ day = 1 , $ year ) ; return $ roundedTimestamp ; } | Rounds a timestamp down to midnight on the 1st of January of the year it was taken |
24,447 | public static function get_human_readble_time_difference ( \ DateTime $ timestamp ) { $ resultString = "" ; $ now = new \ DateTime ( ) ; $ diffInSeconds = $ now -> getTimestamp ( ) - $ timestamp -> getTimestamp ( ) ; if ( $ diffInSeconds < 60 ) { $ resultString = "$diffInSeconds seconds" ; } elseif ( $ diffInSeconds < 3600 ) { $ diffInMinutes = ( int ) ( $ diffInSeconds / 60 ) ; $ remainder = ( int ) ( $ diffInSeconds % 60 ) ; $ resultString = "$diffInMinutes mins $remainder secs" ; } elseif ( $ diffInSeconds < 86400 ) { $ diffInHours = ( int ) ( $ diffInSeconds / 3600 ) ; $ remainder = ( int ) ( $ diffInSeconds % 3600 ) ; $ minutes = ( int ) ( $ remainder / 60 ) ; $ resultString = "$diffInHours hours $minutes mins" ; } else { $ diffInDays = ( int ) ( $ diffInSeconds / 86400 ) ; $ remainder = ( int ) ( $ diffInSeconds % 86400 ) ; $ hours = ( int ) ( $ remainder / 3600 ) ; $ resultString = "$diffInDays days $hours hours" ; } return $ resultString ; } | Given a timestamp get how long ago it was in human readable form . E . g . 10 seconds 4 minutes 1 hour 456 days |
24,448 | protected function filter ( $ packageNames , $ filters ) { if ( empty ( $ filters ) ) { return $ packageNames ; } $ packages = [ ] ; foreach ( $ packageNames as $ packageName ) { if ( count ( $ package = $ this -> repository -> findPackages ( $ packageName ) ) > 0 ) { foreach ( $ filters as $ filter ) { $ package = array_filter ( $ package , $ filter ) ; } if ( $ package = current ( $ package ) ) { $ packages [ $ packageName ] = $ package ; } } } return array_map ( function ( $ package ) { return $ package -> getName ( ) ; } , $ packages ) ; } | Filter the passed list of package names . |
24,449 | protected function decorate ( $ packageName ) { $ results = $ this -> repository -> findPackages ( $ packageName ) ; if ( ! count ( $ results ) ) { throw new \ InvalidArgumentException ( 'Could not find package with specified name ' . $ packageName ) ; } $ latest = array_slice ( $ results , 0 , 1 ) [ 0 ] ; $ versions = array_slice ( $ results , 1 ) ; $ package = new VersionedPackage ( $ latest , $ versions ) ; return $ this -> decorateWithPackagistStats ( $ package ) ; } | Decorate a package . |
24,450 | protected function decorateWithPackagistStats ( VersionedPackage $ package ) { if ( null === $ this -> decorateBaseUrl ) { return $ package ; } $ rfs = new RemoteFilesystem ( new BufferIO ( ) ) ; $ requestUrl = sprintf ( $ this -> decorateBaseUrl , $ package -> getName ( ) ) ; if ( ! ( $ jsonData = $ rfs -> getContents ( $ requestUrl , $ requestUrl ) ) ) { $ this -> decorateBaseUrl = null ; return $ package ; } try { $ data = new JsonArray ( $ jsonData ) ; } catch ( \ RuntimeException $ exception ) { $ this -> decorateBaseUrl = null ; return $ package ; } $ metaPaths = [ 'downloads' => 'package/downloads/total' , 'favers' => 'package/favers' ] ; foreach ( $ metaPaths as $ metaKey => $ metaPath ) { $ package -> addMetaData ( $ metaKey , $ data -> get ( $ metaPath ) ) ; } return $ package ; } | Decorate the package with stats from packagist . |
24,451 | public function disableSearchType ( $ searchType ) { if ( ( $ key = array_search ( $ searchType , $ this -> enabledSearchTypes ) ) !== false ) { unset ( $ this -> enabledSearchTypes [ $ key ] ) ; } return $ this ; } | Disable a search type . |
24,452 | public function indexAction ( ) { $ body = '' ; $ body .= '<a href="' . $ this -> generateUrl ( 'phlexible_status_user_context' ) . '">Context</a><br />' ; $ body .= '<a href="' . $ this -> generateUrl ( 'phlexible_status_user_session' ) . '">Session</a>' ; return new Response ( $ body ) ; } | Show security status . |
24,453 | public function contextAction ( ) { $ tokenStorage = $ this -> get ( 'security.token_storage' ) ; $ token = $ tokenStorage -> getToken ( ) ; $ user = $ token -> getUser ( ) ; $ output = '<pre>' ; $ output .= 'Token class: ' . get_class ( $ token ) . PHP_EOL ; $ output .= 'User class: ' . ( is_object ( $ user ) ? get_class ( $ user ) : $ user ) . PHP_EOL ; $ output .= PHP_EOL ; $ output .= 'Token username: ' ; $ output .= print_r ( $ token -> getUsername ( ) , 1 ) . PHP_EOL ; $ output .= 'Token attributes: ' ; $ output .= print_r ( $ token -> getAttributes ( ) , 1 ) . PHP_EOL ; $ output .= 'Token credentials: ' ; $ output .= print_r ( $ token -> getCredentials ( ) , 1 ) . PHP_EOL ; $ output .= 'Token roles: ' ; $ output .= print_r ( $ token -> getRoles ( ) , 1 ) . PHP_EOL ; return new Response ( $ output ) ; } | Show security context . |
24,454 | public function sessionAction ( Request $ request ) { $ output = '<pre>' ; $ output .= 'Security session namespace:' . PHP_EOL ; $ output .= '<ul>' ; foreach ( $ request -> getSession ( ) -> all ( ) as $ key => $ value ) { if ( is_object ( $ value ) ) { $ o = get_class ( $ value ) ; } elseif ( is_array ( $ value ) ) { $ o = 'array ' . count ( $ value ) ; } else { $ o = $ value ; if ( @ unserialize ( $ o ) ) { $ o = unserialize ( $ o ) ; } } $ output .= '<li>' . $ key . ': ' . $ o . '</li>' ; } $ output .= '</ul>' ; return new Response ( $ output ) ; } | Show session . |
24,455 | public static function Ld ( $ bm , array $ p , array $ q , array $ e , $ em , $ dlim , array & $ p1 ) { $ i ; $ qpe = [ ] ; $ qdqpe ; $ w ; $ eq = [ ] ; $ peq = [ ] ; for ( $ i = 0 ; $ i < 3 ; $ i ++ ) { $ qpe [ $ i ] = $ q [ $ i ] + $ e [ $ i ] ; } $ qdqpe = IAU :: Pdp ( $ q , $ qpe ) ; $ w = $ bm * SRS / $ em / max ( $ qdqpe , $ dlim ) ; IAU :: Pxp ( $ e , $ q , $ eq ) ; IAU :: Pxp ( $ p , $ eq , $ peq ) ; for ( $ i = 0 ; $ i < 3 ; $ i ++ ) { $ p1 [ $ i ] = $ p [ $ i ] + $ w * $ peq [ $ i ] ; } } | - - - - - - i a u L d - - - - - - |
24,456 | public function execute ( $ command = '' , $ cwd = null , array $ env = null ) { $ fd = proc_open ( $ command , $ this -> descriptors , $ pipes , $ cwd , $ env ) ; fclose ( $ pipes [ 0 ] ) ; $ output = $ this -> parseOutput ( stream_get_contents ( $ pipes [ 1 ] ) ) ; fclose ( $ pipes [ 1 ] ) ; $ returnCode = ( int ) trim ( proc_close ( $ fd ) ) ; return new CliCommandResponse ( [ 'output' => $ output , 'return_code' => $ returnCode , ] ) ; } | Executes a cli command using proc_open |
24,457 | protected function parseOutput ( $ output ) { $ lines = explode ( "\n" , $ output ) ; $ escapeStr = "\x1b\x5b\x4b" ; $ actualLines = array ( ) ; foreach ( $ lines as $ line ) { if ( stripos ( $ line , $ escapeStr ) !== false ) { $ parts = explode ( "\r" , $ line ) ; $ actualLine = array_pop ( $ parts ) ; $ actualLines [ ] = str_replace ( $ escapeStr , '' , $ actualLine ) ; } else { $ actualLines [ ] = $ line ; } } return trim ( implode ( "\n" , $ actualLines ) ) ; } | Parses output from shell into usable string |
24,458 | public function getLoggedUser ( ) { $ session = BUsersSession :: getInstanceAndStart ( ) ; if ( empty ( $ session ) ) { return NULL ; } return $ this -> itemGet ( $ session -> userid ) ; } | Get logged user class |
24,459 | public function login ( $ email , $ password , $ longsession = false ) { $ user = $ this -> getUserByEmail ( $ email ) ; if ( $ user == false ) { BLog :: addToLog ( '[Users]: login() wrong email!' , LL_ERROR ) ; return USERS_ERROR_NOSUCHEMAIL ; } if ( $ user -> active == USER_STATUS_NOTACTIVATED ) { BLog :: addToLog ( '[Users]: Not Activated' , LL_ERROR ) ; return USERS_ERROR_NOACTIVATED ; } if ( $ user -> active == USER_STATUS_BANNED ) { BLog :: addToLog ( '[Users]: Banned user' , LL_ERROR ) ; return USERS_ERROR_BANNED ; } $ hash = $ this -> makepass ( $ email , $ password ) ; if ( $ user -> password != $ hash ) { BLog :: addToLog ( '[Users]: password hashes not equal! user hash=' . $ user -> password . '; post hash=' . $ hash , LL_ERROR ) ; return USERS_ERROR_PASS ; } $ options = array ( 'interval' => $ longsession ? 2592000 : 10800 , 'updatestep' => 60 , ) ; $ sess = BUsersSession :: getInstance ( ) ; $ sess -> newSession ( $ user -> id , $ options ) ; return USERS_ERROR_OK ; } | Login . Returns user object |
24,460 | public function itemsFilterSql ( $ params , & $ wh , & $ jn ) { parent :: itemsFilterSql ( $ params , $ wh , $ jn ) ; $ db = BFactory :: getDBO ( ) ; if ( isset ( $ params [ 'email' ] ) ) { $ wh [ ] = '(`email`=' . $ db -> escapeString ( $ params [ 'email' ] ) . ')' ; } return true ; } | Items Filter SQL |
24,461 | public function itemsFilterHash ( $ params ) { $ itemsHash = parent :: itemsFilterHash ( $ params ) ; if ( isset ( $ params [ 'email' ] ) ) { $ itemsHash .= ':email=' . $ params [ 'email' ] ; } return $ itemsHash ; } | Return items hash |
24,462 | public function getUserByEmail ( $ email ) { $ list = $ this -> itemsFilter ( [ 'email' => $ email , 'limit' => 1 ] ) ; if ( empty ( $ list ) ) { return NULL ; } $ user = reset ( $ list ) ; return $ user ; } | Get user By email |
24,463 | public function filePutContents ( $ filePath , $ data ) { $ bytesWritten = @ file_put_contents ( $ filePath , $ data ) ; if ( $ bytesWritten === false ) { throw new FileSystemException ( 'File ' . $ filePath . ' could not be written' ) ; } return true ; } | write to a file |
24,464 | protected function validateTable ( $ table ) { $ this -> checkTableArgument ( $ table ) ; if ( ! $ this -> hasTable ( $ table ) ) { throw new Exception \ TableNotFoundException ( __METHOD__ . ": Table '$table' does not exists in database '{$this->schema}'" ) ; } return $ this ; } | Check whether a table parameter is valid and exists . |
24,465 | protected function validateSchema ( $ schema ) { if ( ! is_string ( $ schema ) || trim ( $ schema ) == '' ) { throw new Exception \ InvalidArgumentException ( __METHOD__ . ': Schema name must be a valid string or an empty string detected' ) ; } return $ this ; } | Check whether a schema parameter is valid . |
24,466 | protected function setSchemaSignature ( ) { $ host = $ this -> adapter -> getConnection ( ) -> getHost ( ) ; $ schema = $ this -> schema ; $ this -> schemaSignature = "$host:$schema" ; } | Return current schema signature for caching . |
24,467 | public function authenticateWithAuthCode ( $ authCode ) { $ accessToken = $ this -> fetchAccessTokenWithAuthCode ( $ authCode ) ; $ this -> getLogger ( ) -> debug ( 'Access token with auth code: ' . json_encode ( $ accessToken ) ) ; return ! array_key_exists ( 'error' , $ accessToken ) ; } | Authentication passed if access token can be fetch using authorization code |
24,468 | public function getAccessToken ( ) { $ this -> getLogger ( ) -> debug ( 'Get access token. If expired try to update' ) ; if ( $ this -> isAccessTokenExpired ( ) && $ this -> getRefreshToken ( ) ) { $ this -> fetchAccessTokenWithRefreshToken ( $ this -> getRefreshToken ( ) ) ; } return parent :: getAccessToken ( ) ; } | Proxy for parent method Get new access token if it expired using refresh token |
24,469 | public static function FilterPersonalInfo ( $ Role ) { if ( is_string ( $ Role ) ) { $ Role = array_shift ( self :: GetByName ( $ Role ) ) ; } return ( GetValue ( 'PersonalInfo' , $ Role ) ) ? FALSE : TRUE ; } | Use with array_filter to remove PersonalInfo roles . |
24,470 | public function GetArray ( ) { $ RoleData = $ this -> Get ( ) ; $ RoleIDs = ConsolidateArrayValuesByKey ( $ RoleData -> ResultArray ( ) , 'RoleID' ) ; $ RoleNames = ConsolidateArrayValuesByKey ( $ RoleData -> ResultArray ( ) , 'Name' ) ; return ArrayCombine ( $ RoleIDs , $ RoleNames ) ; } | Returns an array of RoleID = > RoleName pairs . |
24,471 | public function GetByUserID ( $ UserID ) { return $ this -> SQL -> Select ( ) -> From ( 'Role' ) -> Join ( 'UserRole' , 'Role.RoleID = UserRole.RoleID' ) -> Where ( 'UserRole.UserID' , $ UserID ) -> Get ( ) ; } | Returns a resultset of role data related to the specified UserID . |
24,472 | public function setParent ( Logger $ parent ) { $ this -> handlers = $ parent -> handlers ; $ this -> processors = $ parent -> processors ; $ this -> level = $ parent -> level ; } | Set this logger s parent logger . |
24,473 | public static function create ( int $ year , int $ month , int $ day ) : Date { return new static ( $ year , $ month , $ day ) ; } | Creates instance from date values |
24,474 | public static function now ( ? string $ timezone = null ) : Date { $ timezone = $ timezone ? : date_default_timezone_get ( ) ; assert ( Validate :: isTimezone ( $ timezone ) , sprintf ( 'Invalid timezone: %s' , $ timezone ) ) ; $ dateTime = new DateTimeImmutable ( 'now' , new DateTimeZone ( $ timezone ) ) ; $ year = ( int ) $ dateTime -> format ( 'Y' ) ; $ month = ( int ) $ dateTime -> format ( 'n' ) ; $ day = ( int ) $ dateTime -> format ( 'j' ) ; return new static ( $ year , $ month , $ day ) ; } | Creates instance for the current date |
24,475 | protected function guardDate ( int $ year , int $ month , int $ day ) : void { if ( ! checkdate ( $ month , $ day , $ year ) ) { $ message = sprintf ( 'Invalid date: %04d-%02d-%02d' , $ year , $ month , $ day ) ; throw new DomainException ( $ message ) ; } } | Validates the date |
24,476 | public function addFactory ( ProcessorFactoryInterface $ factory , $ priority = 0 ) { $ this -> factories [ $ priority ] [ ] = $ factory ; \ krsort ( $ this -> factories ) ; $ this -> sortedFactories = \ array_merge ( ... $ this -> factories ) ; } | Registers a factory in the chain |
24,477 | public function equals ( UrlPathInterface $ urlPath ) : bool { return $ this -> isAbsolute ( ) === $ urlPath -> isAbsolute ( ) && $ this -> getDirectoryParts ( ) === $ urlPath -> getDirectoryParts ( ) && $ this -> getFilename ( ) === $ urlPath -> getFilename ( ) ; } | Returns true if the url path equals other url path false otherwise . |
24,478 | public function getDirectory ( ) : UrlPathInterface { return new self ( $ this -> myIsAbsolute , $ this -> myAboveBaseLevel , $ this -> myDirectoryParts , null ) ; } | Returns the directory of the url path . |
24,479 | public function getParentDirectory ( ) : ? UrlPathInterface { if ( $ this -> myParentDirectory ( $ aboveBaseLevel , $ directoryParts ) ) { return new self ( $ this -> myIsAbsolute , $ aboveBaseLevel , $ directoryParts , null ) ; } return null ; } | Returns the parent directory of the url path or null if url path does not have a parent directory . |
24,480 | public function toAbsolute ( ) : UrlPathInterface { if ( $ this -> myAboveBaseLevel > 0 ) { throw new UrlPathLogicException ( 'Url path "' . $ this -> __toString ( ) . '" can not be made absolute: Relative path is above base level.' ) ; } return new self ( true , $ this -> myAboveBaseLevel , $ this -> myDirectoryParts , $ this -> myFilename ) ; } | Returns The url path as an absolute path . |
24,481 | public function toRelative ( ) : UrlPathInterface { return new self ( false , $ this -> myAboveBaseLevel , $ this -> myDirectoryParts , $ this -> myFilename ) ; } | Returns the url path as a relative path . |
24,482 | public function withUrlPath ( UrlPathInterface $ urlPath ) : UrlPathInterface { if ( ! $ this -> myCombine ( $ urlPath , $ isAbsolute , $ aboveBaseLevel , $ directoryParts , $ filename , $ error ) ) { throw new UrlPathLogicException ( 'Url path "' . $ this -> __toString ( ) . '" can not be combined with url path "' . $ urlPath -> __toString ( ) . '": ' . $ error ) ; } return new self ( $ isAbsolute , $ aboveBaseLevel , $ directoryParts , $ filename ) ; } | Returns a copy of the url path combined with another url path . |
24,483 | public static function isValid ( string $ urlPath ) : bool { return self :: myParse ( '/' , $ urlPath , function ( $ p , $ d , & $ e ) { return self :: myPartValidator ( $ p , $ d , $ e ) ; } ) ; } | Checks if a url path is valid . |
24,484 | private function validateFormatUri ( string $ subject ) : bool { return \ filter_var ( $ subject , \ FILTER_VALIDATE_URL , \ FILTER_FLAG_SCHEME_REQUIRED | \ FILTER_FLAG_HOST_REQUIRED ) !== false ; } | uri format validation |
24,485 | public function serve ( ) { $ request = Request :: createFromGlobals ( ) ; $ response = $ this -> handleRequest ( $ request ) ; if ( $ this -> liveReload ) $ this -> injectLiveReload ( $ response ) ; $ response -> send ( ) ; } | Serves a response based on the request received from the client . |
24,486 | private function injectLiveReload ( Response $ response ) { $ content = $ response -> getContent ( ) ; $ content = str_replace ( '</body>' , ' <script> document.write(\'<script src="http://\' + (location.host || \'localhost\').split(\':\')[0] + \':35729/livereload.js?snipver=1"></\' + \'script>\') </script></body>' , $ content ) ; $ response -> setContent ( $ content ) ; } | Injects script tag that loads livereload . js to the response . |
24,487 | public function beforeSave ( Event $ event , Entity $ entity , ArrayObject $ options ) { if ( empty ( $ entity -> expiry ) ) { $ entity -> expiry = Configure :: read ( 'Tokens.expiryDefaultValue' ) ; } if ( ! empty ( $ entity -> extra ) ) { $ entity -> extra = serialize ( $ entity -> extra ) ; } $ this -> deleteExpired ( $ entity ) ; return true ; } | Called before each entity is saved . Stopping this event will abort the save operation . |
24,488 | public function deleteExpired ( Token $ entity = null ) { $ conditions [ ] = [ 'expiry <' => new Time ] ; if ( ! empty ( $ entity -> token ) ) { $ conditions [ ] = [ 'token' => $ entity -> token ] ; } if ( ! empty ( $ entity -> user_id ) ) { $ conditions [ ] = [ 'user_id' => $ entity -> user_id ] ; } return $ this -> deleteAll ( [ 'OR' => $ conditions ] ) ; } | Deletes all expired tokens . |
24,489 | public function buildRules ( RulesChecker $ rules ) { $ rules -> add ( function ( Token $ entity ) { $ errors = $ this -> getValidator ( 'default' ) -> errors ( $ entity -> extract ( $ this -> getSchema ( ) -> columns ( ) , true ) , $ entity -> isNew ( ) ) ; $ entity -> setErrors ( $ errors ) ; return empty ( $ errors ) ; } ) ; $ rules -> add ( $ rules -> existsIn ( [ 'user_id' ] , 'Users' ) ) ; return $ rules ; } | Build rules . |
24,490 | public static function activeIcon ( $ active , array $ options = [ ] , $ withTooltip = true ) { $ classes = Arr :: get ( $ options , 'classes' , [ 'enabled' => 'label label-success' , 'disabled' => 'label label-default' , ] ) ; $ translations = Arr :: get ( $ options , 'trans' , [ 'enabled' => 'core::statuses.enabled' , 'disabled' => 'core::statuses.disabled' , ] ) ; $ icons = Arr :: get ( $ options , 'icons' , [ 'enabled' => 'fa fa-fw fa-check' , 'disabled' => 'fa fa-fw fa-ban' , ] ) ; $ key = $ active ? 'enabled' : 'disabled' ; $ attributes = [ 'class' => $ classes [ $ key ] ] ; $ value = static :: generateIcon ( $ icons [ $ key ] ) ; return $ withTooltip ? static :: generateWithTooltip ( $ value , ucfirst ( trans ( $ translations [ $ key ] ) ) , $ attributes ) : static :: generate ( $ value , $ attributes ) ; } | Generate active icon label . |
24,491 | public static function activeStatus ( $ active , array $ options = [ ] , $ withIcon = true ) { $ classes = Arr :: get ( $ options , 'classes' , [ 'enabled' => 'label label-success' , 'disabled' => 'label label-default' , ] ) ; $ translations = Arr :: get ( $ options , 'trans' , [ 'enabled' => 'core::statuses.enabled' , 'disabled' => 'core::statuses.disabled' , ] ) ; $ icons = Arr :: get ( $ options , 'icons' , [ 'enabled' => 'fa fa-fw fa-check' , 'disabled' => 'fa fa-fw fa-ban' , ] ) ; $ key = $ active ? 'enabled' : 'disabled' ; $ attributes = [ 'class' => $ classes [ $ key ] ] ; return $ withIcon ? static :: generateWithIcon ( ucfirst ( trans ( $ translations [ $ key ] ) ) , $ icons [ $ key ] , $ attributes ) : static :: generate ( ucfirst ( trans ( $ translations [ $ key ] ) ) , $ attributes ) ; } | Generate active status label . |
24,492 | public static function checkStatus ( $ checked , array $ options = [ ] , $ withIcon = true ) { $ classes = Arr :: get ( $ options , 'classes' , [ 'checked' => 'label label-success' , 'unchecked' => 'label label-default' , ] ) ; $ translations = Arr :: get ( $ options , 'trans' , [ 'checked' => 'core::statuses.checked' , 'unchecked' => 'core::statuses.unchecked' , ] ) ; $ icons = Arr :: get ( $ options , 'icons' , [ 'checked' => 'fa fa-fw fa-check' , 'unchecked' => 'fa fa-fw fa-ban' , ] ) ; $ key = $ checked ? 'checked' : 'unchecked' ; $ attributes = [ 'class' => $ classes [ $ key ] ] ; return $ withIcon ? static :: generateWithIcon ( ucfirst ( trans ( $ translations [ $ key ] ) ) , $ icons [ $ key ] , $ attributes ) : static :: generate ( ucfirst ( trans ( $ translations [ $ key ] ) ) , $ attributes ) ; } | Generate check status label . |
24,493 | public static function count ( $ count , array $ options = [ ] ) { $ classes = Arr :: get ( $ options , 'classes' , [ 'positive' => 'label label-info' , 'zero' => 'label label-default' , 'negative' => 'label label-danger' , ] ) ; return static :: generate ( $ count , [ 'class' => $ count > 0 ? $ classes [ 'positive' ] : ( $ count < 0 ? $ classes [ 'negative' ] : $ classes [ 'zero' ] ) ] ) ; } | Generate count label . |
24,494 | public static function lockedStatus ( $ locked , array $ options = [ ] , $ withIcon = true ) { $ classes = Arr :: get ( $ options , 'classes' , [ 'locked' => 'label label-danger' , 'unlocked' => 'label label-success' , ] ) ; $ translations = Arr :: get ( $ options , 'trans' , [ 'locked' => 'core::statuses.locked' , 'unlocked' => 'core::statuses.unlocked' , ] ) ; $ icons = Arr :: get ( $ options , 'icons' , [ 'locked' => 'fa fa-fw fa-lock' , 'unlocked' => 'fa fa-fw fa-unlock' , ] ) ; $ key = $ locked ? 'locked' : 'unlocked' ; $ value = ucfirst ( trans ( $ translations [ $ key ] ) ) ; $ attributes = [ 'class' => $ classes [ $ key ] ] ; return $ withIcon ? static :: generateWithIcon ( $ value , $ icons [ $ key ] , $ attributes ) : static :: generate ( $ value , $ attributes ) ; } | Generate locked status label . |
24,495 | public static function trashedStatus ( array $ options = [ ] , $ withIcon = true ) { $ trans = Arr :: get ( $ options , 'trans' , 'core::statuses.trashed' ) ; $ icon = Arr :: get ( $ options , 'icon' , 'fa fa-fw fa-trash-o' ) ; $ attributes = [ 'class' => Arr :: get ( $ options , 'class' , 'label label-danger' ) ] ; return $ withIcon ? static :: generateWithIcon ( ucfirst ( trans ( $ trans ) ) , $ icon , $ attributes ) : static :: generate ( ucfirst ( trans ( $ trans ) ) , $ attributes ) ; } | Generate trashed icon label . |
24,496 | protected static function generateWithTooltip ( $ value , $ title , array $ attributes = [ ] ) { $ attributes [ 'data-toggle' ] = 'tooltip' ; $ attributes [ 'data-original-title' ] = $ title ; return static :: generate ( $ value , $ attributes ) ; } | Generate the label with tooltip . |
24,497 | public function validateHeaders ( WebRequest $ request ) { $ settings = CsrfSettings :: singleton ( ) ; $ headersValid = false ; $ referrerDomain = $ this -> getHost ( $ request -> header ( "Referer" , "" ) ) ; if ( $ referrerDomain != "" ) { if ( $ referrerDomain == $ settings -> domain ) { $ headersValid = true ; } } else { if ( $ this -> getHost ( $ request -> header ( "Origin" ) ) == $ settings -> domain ) { $ headersValid = true ; } } if ( ! $ headersValid ) { throw new CsrfViolationException ( ) ; } } | Validates that a request headers meets CSRF requirements . |
24,498 | public function validateCookie ( WebRequest $ request ) { if ( $ request -> cookie ( self :: TOKEN_COOKIE_NAME ) != $ request -> post ( self :: TOKEN_COOKIE_NAME ) ) { throw new CsrfViolationException ( ) ; } } | Validates if the csrf_tk cookie matches the posted value . |
24,499 | public function getCookie ( ) { $ request = Request :: current ( ) ; $ settings = CsrfSettings :: singleton ( ) ; if ( $ request instanceof WebRequest ) { $ existingCookie = $ request -> cookie ( self :: TOKEN_COOKIE_NAME , false ) ; if ( $ existingCookie ) { $ this -> currentCookie = $ existingCookie ; } } if ( ! $ this -> currentCookie ) { $ chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345689.;,!$%^&*()-=+" ; $ cookie = "" ; for ( $ x = 0 ; $ x < self :: TOKEN_COOKIE_LENGTH ; $ x ++ ) { $ rand = rand ( 0 , strlen ( $ chars ) - 1 ) ; $ char = $ chars [ $ rand ] ; if ( rand ( 0 , 1 ) == 1 ) { $ char = strtolower ( $ char ) ; } $ cookie .= $ char ; } $ this -> currentCookie = $ cookie ; HttpResponse :: setCookie ( self :: TOKEN_COOKIE_NAME , $ cookie , 0 , '/' , parse_url ( $ settings -> domain , PHP_URL_HOST ) , false , true ) ; } return $ this -> currentCookie ; } | Returns the current cookie being used for CSRF or generates one if one doesn t exist . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.